/** Execute the specified {@code request} using the provided {@code urlFetchService}. */ protected HTTPResponse execute(URLFetchService urlFetchService, HTTPRequest request) throws IOException { return urlFetchService.fetch(request); }
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService(); FetchOptions lFetchOptions = FetchOptions.Builder.validateCertificate(); HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, lFetchOptions); HTTPResponse response = fetcher.fetch(request);
public void flush() throws IOException { if (request != null) { try { // System.err.println("----"); response = urlFS.fetch(request); request = null; }catch (IOException ex) { ex.printStackTrace(); throw ex; } } else { response = null; } }
HTTPRequest request = new HTTPRequest(_url, HTTPMethod.POST, Builder.allowTruncate()); URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(request);
String request = "https://graph.facebook.com/194652357227159?access_token=Aj2h4df..."; URL url = new URL(request); URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse resp = urlFetchService.fetch(new HTTPRequest(url, HTTPMethod.GET, FetchOptions.Builder.doNotValidateCertificate()));
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); } }
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); } }
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); }
@Override public HTTPResponse fetch(HTTPRequest req) throws IOException, RetryHelperException { HTTPRequest authorizedRequest = createAuthorizeRequest(req); return urlFetch.fetch(authorizedRequest); }
//Classes to import import com.google.appengine.api.urlfetch.HTTPMethod; import com.google.appengine.api.urlfetch.HTTPRequest; import com.google.appengine.api.urlfetch.HTTPResponse; import com.google.appengine.api.urlfetch.URLFetchService; import com.google.appengine.api.urlfetch.URLFetchServiceFactory; //Shortening download URL URL url=new URL("http://goo.gl/api/shorten"); HTTPRequest req=new HTTPRequest(url,HTTPMethod.POST); req.setPayload(("url=www.google.com").getBytes()); URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(req); byte[] content = response.getContent(); String urlshort=new String(content); //here is the JSON data from goo.gl
@Override public Response doGet(String url, Iterable<Header> headers) throws IOException { HTTPRequest request = newRequest(url, HTTPMethod.GET, headers); HTTPResponse response = service.fetch(request); return toRequestorResponse(response); }
@Override public Response finish() throws IOException { if (request == null) { throw new IllegalStateException("Uploader already closed."); } request.setPayload(body.toByteArray()); HTTPResponse response = service.fetch(request); Response requestorResponse = toRequestorResponse(response); close(); if (progressListener != null) { progressListener.onProgress(request.getPayload().length); } return requestorResponse; } }
String pivotalUrl = "http://www.pivotaltracker.com/services/v3/projects/"+projectID+"/stories" String body = "<story><story_type>feature</story_type><name>Story name</name><requested_by>James Kirk</requested_by></story>" URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService(); HTTPRequest request = new HTTPRequest(pivotalUrl, HTTPMethod.POST, FetchOptions.Builder.withDeadline(30)); request.addHeader(new HTTPHeader("X-TrackerToken","putTokenHere")); request.addHeader(new HTTPHeader("Content-type","application/xml")); HTTPResponse response = fetchService.fetch(request); if (response.getResponseCode() != 200) { // something went wrong }
@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)); }
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()); }
@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); } }
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); }
/** * Invokes the URL fetch service. * * @param exchange contains the request data in the in-message. The result is written to the out-message. * @throws GHttpException if the response code is >= 400 and {@link GHttpEndpoint#isThrowExceptionOnFailure()} * returns <code>true</code>. * * @see GHttpBinding */ public void process(Exchange exchange) throws Exception { HTTPRequest request = getOutboundBinding().writeRequest(getEndpoint(), exchange, null); HTTPResponse response = getUrlFetchService().fetch(request); getOutboundBinding().readResponse(getEndpoint(), exchange, 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()); }