public UrlFetchClient() { this(URLFetchServiceFactory.getURLFetchService()); }
public GoogleAppEngineRequestor(FetchOptions options) { this(options, URLFetchServiceFactory.getURLFetchService()); }
public GaeHttpTransport() { this.connection = URLFetchServiceFactory.getURLFetchService(); }
public GaeHttpTransport() { this.connection = URLFetchServiceFactory.getURLFetchService(); }
public GoogleFetcher() { fetchService = URLFetchServiceFactory.getURLFetchService(); }
@Provides protected URLFetchService provideURLFetchService() { return URLFetchServiceFactory.getURLFetchService(); } }
public GHttpEndpoint(String endpointUri, ServletComponent component, URI httpUri) throws URISyntaxException { // set the endpoint uri with httpUri as we need to create http producer here super(httpUri.toString(), component, httpUri); urlFetchService = URLFetchServiceFactory.getURLFetchService(); }
@Provides protected final URLFetchService provideURLFetchService() { return URLFetchServiceFactory.getURLFetchService(); } }
@Override public LowLevelHttpResponse execute() throws IOException { // write content if (content != null) { String contentType = content.getType(); if (contentType != null) { addHeader("Content-Type", contentType); } String contentEncoding = content.getEncoding(); if (contentEncoding != null) { addHeader("Content-Encoding", contentEncoding); } ByteArrayOutputStream out = new ByteArrayOutputStream(); content.writeTo(out); byte[] payload = out.toByteArray(); if (payload.length != 0) { request.setPayload(payload); } } // connect URLFetchService service = URLFetchServiceFactory.getURLFetchService(); try { HTTPResponse response = service.fetch(request); return new UrlFetchResponse(response); } catch (ResponseTooLargeException e) { IOException ioException = new IOException(); ioException.initCause(e); throw ioException; } }
@Override public Response fetchData(String url, Method method) { try { URL aUrl = new URL(url); HTTPMethod httpMethod = HTTPMethod.GET; switch (method) { case POST: httpMethod = HTTPMethod.POST; break; } HTTPRequest httpRequest = new HTTPRequest(aUrl, httpMethod, doNotValidateCertificate().setDeadline(10d)); URLFetchService service = URLFetchServiceFactory .getURLFetchService(); HTTPResponse response = service.fetch(httpRequest); return new Response(new String(response.getContent(), "UTF-8"), response.getResponseCode(), ""); } catch (MalformedURLException e) { return new Response("", 400, "Malformed URL: " + url); } catch (IOException e) { return new Response("", 500, e.getMessage()); } }
@Test public void testFollowRedirectsExternal() throws Exception { final URL redirectUrl = new URL("http://google.com/"); final String expectedDestinationURLPrefix = "http://www.google."; FetchOptions options = FetchOptions.Builder.followRedirects(); HTTPRequest request = new HTTPRequest(redirectUrl, HTTPMethod.GET, options); URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(request); String destinationUrl = response.getFinalUrl().toString(); assertTrue("Did not get redirected.", destinationUrl.startsWith(expectedDestinationURLPrefix)); }
public static JsonNode fetchUserDataFromFacebook(String access_token) throws LeanException { String url = "https://graph.facebook.com/me?access_token=" + access_token; URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse fetchResponse; try { fetchResponse = fetchService.fetch(new URL(url)); if (fetchResponse.getResponseCode() == 200) { return JsonUtils.getObjectMapper().readTree(new String(fetchResponse.getContent(), "UTF-8")); } else { throw new LeanException(LeanException.Error.FacebookAuthError); } } catch (MalformedURLException ex) { //todo This should not happen - log it } catch (JsonProcessingException ex) { throw new LeanException(LeanException.Error.FacebookAuthParseError, ex); } catch (IOException e) { throw new LeanException(LeanException.Error.FacebookAuthConnectError, e); } return null; }
protected String fetchUrl(String url, int expectedResponse) throws IOException { URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse httpResponse = urlFetchService.fetch(new URL(url)); assertEquals(url, expectedResponse, httpResponse.getResponseCode()); return new String(httpResponse.getContent()); }
URL facebookGraphUrl = new URL(FacebookAuth.getGraphAuthUrl(currentUrl, code)); log.info("facebookGraphUrl="+facebookGraphUrl); URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse fetchResponse = fetchService.fetch(facebookGraphUrl); String responseContent = new String(fetchResponse.getContent(), Charset.forName("UTF-8"));
protected void testOptions(URL url, HTTPMethod method, FetchOptions options, ResponseHandler handler) throws Exception { HTTPRequest request = new HTTPRequest(url, method, options); URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(request); handler.handle(response); }
@Override public LowLevelHttpResponse execute() throws IOException { // write content if (getStreamingContent() != null) { String contentType = getContentType(); if (contentType != null) { addHeader("Content-Type", contentType); } String contentEncoding = getContentEncoding(); if (contentEncoding != null) { addHeader("Content-Encoding", contentEncoding); } ByteArrayOutputStream out = new ByteArrayOutputStream(); getStreamingContent().writeTo(out); byte[] payload = out.toByteArray(); if (payload.length != 0) { request.setPayload(payload); } } // connect URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(request); return new UrlFetchResponse(response); } }
@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)); 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 }
@Test public void testBasicOps() throws Exception { URLFetchService service = URLFetchServiceFactory.getURLFetchService(); URL adminConsole = findAvailableUrl(URLS); HTTPResponse response = service.fetch(adminConsole); printResponse(response); URL jbossOrg = new URL("http://www.jboss.org"); if (available(jbossOrg)) { response = service.fetch(jbossOrg); printResponse(response); } }
@Test public void testPayload() throws Exception { URLFetchService service = URLFetchServiceFactory.getURLFetchService(); URL url = getFetchUrl(); HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST); req.setHeader(new HTTPHeader("Content-Type", "application/octet-stream")); req.setPayload("Tralala".getBytes(UTF_8)); HTTPResponse response = service.fetch(req); String content = new String(response.getContent()); Assert.assertEquals("Hopsasa", content); }
@Test(expected = IOException.class) public void fetchNonExistentLocalAppThrowsException() throws Exception { URL selfURL = new URL("BOGUS-" + appUrlBase + "/"); FetchOptions fetchOptions = FetchOptions.Builder.withDefaults() .doNotFollowRedirects() .setDeadline(10.0); HTTPRequest httpRequest = new HTTPRequest(selfURL, HTTPMethod.GET, fetchOptions); URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse httpResponse = urlFetchService.fetch(httpRequest); fail("expected exception, got " + httpResponse.getResponseCode()); }