Java Reference
In-Depth Information
With that short example, you can start to conceptualize the potential scenarios for
leveraging the URLFetch service. Using the URL Fetch service is how you address
the creation of HTTP and HTTPS connections from App Engine. App Engine does
not allow your application to make socket connections directly. You must use URL
Fetch to achieve the same result. For example, take the scenario of a REST-based
web service that your application would like to query. In any other JSP or Java
environment, you could set up an HTTP connection to the web service's URI and
parse the response directly. With App Engine, you must use URL Fetch to make
the request, and then when your response is received, it's business as usual from
there. For the full code used in the servlet that resulted in Figure 8-5, take a look at
Listing 8-5.
Listing 8-5. URL Fetch
package com.kyleroche.gaeservices;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UrlFetchServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
try {
URL url = new URL("");
BufferedReader reader = new BufferedReader(new
String line;
while ((line = reader.readLine()) != null) {
Search WWH ::

Custom Search