Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.URLFetchService.fetchAsync()


      out.println("");

      try {
        URL url = new URL(pageName);
        URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
        Future<HTTPResponse> fetchResponse = fetchService.fetchAsync(url);

        String result = new String(fetchResponse.get().getContent());
        result = result.replace("<", "&lt;").replace(">", "&gt;");
        out.println(result);
View Full Code Here


            public byte[] getContent(URLFetchRequest request)
                    throws IOException {
                return "hello".getBytes();
            }
        });
        Future<HTTPResponse> future = service.fetchAsync(httpRequest);
        HTTPResponse httpResponse = future.get();
        assertThat(httpResponse.getResponseCode(), is(200));
        assertThat(new String(httpResponse.getContent()), is("hello"));
    }
}
View Full Code Here

                    os.write(bytes);
                }
                request.setPayload(os.toByteArray());
            }
            URLFetchService service = URLFetchServiceFactory.getURLFetchService();
            return new AppEngineHttpResponseImpl(service.fetchAsync(request));
        } catch (IOException ioe) {
            // connection timeout or read timeout
            throw new TwitterException(ioe.getMessage(), ioe, responseCode);
        }
    }
View Full Code Here

        if (options.containsKey("payload")) {
            request.setPayload((byte[]) options.get("payload"));
        }

        // do an async call, if the async: true option is present
        if (options.containsKey("async") && DefaultGroovyMethods.asBoolean(options.get("async"))) return urlFetch.fetchAsync(request);
        return urlFetch.fetch(request);
    }

    /**
     * Use the URLFetch Service to do a GET on the URL.
View Full Code Here

    @Test
    public void testAsyncOps() throws Exception {
        URLFetchService service = URLFetchServiceFactory.getURLFetchService();

        URL adminConsole = findAvailableUrl(URLS);
        Future<HTTPResponse> response = service.fetchAsync(adminConsole);
        printResponse(response.get(5, TimeUnit.SECONDS));

        response = service.fetchAsync(new HTTPRequest(adminConsole));
        printResponse(response.get(5, TimeUnit.SECONDS));
View Full Code Here

        URL adminConsole = findAvailableUrl(URLS);
        Future<HTTPResponse> response = service.fetchAsync(adminConsole);
        printResponse(response.get(5, TimeUnit.SECONDS));

        response = service.fetchAsync(new HTTPRequest(adminConsole));
        printResponse(response.get(5, TimeUnit.SECONDS));

        URL jbossOrg = new URL("http://www.jboss.org");
        if (available(jbossOrg)) {
            response = service.fetchAsync(jbossOrg);
View Full Code Here

        response = service.fetchAsync(new HTTPRequest(adminConsole));
        printResponse(response.get(5, TimeUnit.SECONDS));

        URL jbossOrg = new URL("http://www.jboss.org");
        if (available(jbossOrg)) {
            response = service.fetchAsync(jbossOrg);
            printResponse(response.get(30, TimeUnit.SECONDS));
        }

        sync(5000L); // wait a bit for async to finish
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.