/** * @param request HTTP request to execute. * @param client The client used to execute the request. * @param responseClass Model class to unmarshal JSON body content. * @param fieldNamingPolicy FieldNamingPolicy for unmarshaling JSON. * @param errorTimeOut Number of milliseconds to re-send erroring requests. * @param maxRetries Number of times allowed to re-send erroring requests. */ public GaePendingResult( HTTPRequest request, URLFetchService client, Class<R> responseClass, FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry) { this.request = request; this.client = client; this.responseClass = responseClass; this.fieldNamingPolicy = fieldNamingPolicy; this.errorTimeOut = errorTimeOut; this.maxRetries = maxRetries; this.exceptionsAllowedToRetry = exceptionsAllowedToRetry; this.call = client.fetchAsync(request); }
/** 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; } }
private T retry() throws IOException, ApiException, InterruptedException { retryCounter++; LOG.info("Retrying request. Retry #{}", retryCounter); this.call = client.fetchAsync(request); return this.await(); }
HTTPRequest request = new HTTPRequest(_url, HTTPMethod.POST, Builder.allowTruncate()); URLFetchService service = URLFetchServiceFactory.getURLFetchService(); HTTPResponse response = service.fetch(request);
/** * @param request HTTP request to execute. * @param client The client used to execute the request. * @param responseClass Model class to unmarshal JSON body content. * @param fieldNamingPolicy FieldNamingPolicy for unmarshaling JSON. * @param errorTimeOut Number of milliseconds to re-send erroring requests. * @param maxRetries Number of times allowed to re-send erroring requests. */ public GaePendingResult( HTTPRequest request, URLFetchService client, Class<R> responseClass, FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry) { this.request = request; this.client = client; this.responseClass = responseClass; this.fieldNamingPolicy = fieldNamingPolicy; this.errorTimeOut = errorTimeOut; this.maxRetries = maxRetries; this.exceptionsAllowedToRetry = exceptionsAllowedToRetry; this.call = client.fetchAsync(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; } }
private T retry() throws IOException, ApiException, InterruptedException { retryCounter++; LOG.info("Retrying request. Retry #{}", retryCounter); this.call = client.fetchAsync(request); return this.await(); }
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 public ListenableFuture<HttpResponse> submit(final HttpCommand command) { HTTPRequest nativeRequest = filterLogAndConvertRe(command.getCurrentRequest()); ListenableFuture<HttpResponse> response = transform( listenInPoolThread(urlFetchService.fetchAsync(nativeRequest)), convertToJcloudsResponse); return transform(response, new Function<HttpResponse, HttpResponse>() { public HttpResponse apply(HttpResponse response) { return receiveResponse(command, response); } }, ioExecutor); }
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); } }
@Override public Future<HTTPResponse> fetchAsync(HTTPRequest req) { HTTPRequest authorizedRequest; try { authorizedRequest = createAuthorizeRequest(req); } catch (RetryHelperException e) { return Futures.immediateFailedCheckedFuture(e); } return urlFetch.fetchAsync(authorizedRequest); } }
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); }
protected HttpResponseImpl fetch(HTTPRequest request, HTTPMethod headGetDelete) { try { Future<HTTPResponse> fetchAsync = fetchService.fetchAsync(request); return new HttpResponseImpl(fetchAsync, this, request.getURL()); } catch (Exception e) { throw new HttpRequestException(e, "Failed to create a %s request: %s", headGetDelete, e.getMessage()); } }
@Override protected HttpResponse invoke(HTTPRequest request) throws IOException { return convert(urlFetchService.fetch(request)); } }
@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 }
@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); }