Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.HTTPRequest


    String currentUrl = url;

    for (int i = 0; i <= requestOptions.getMaxRedirects(); i++) {

      HTTPRequest httpRequest = new HTTPRequest(new URL(currentUrl),
          method, options);

      addHeaders(httpRequest, requestOptions);

      if (method == HTTPMethod.POST && content != null) {
        httpRequest.setPayload(content.getBytes());
      }

      HTTPResponse httpResponse;
      try {
        httpResponse = fetchService.fetch(httpRequest);
View Full Code Here


    }
  }

  public String getMethod(URL url) throws IOException {
    log.finer("Calling GET on " + url);
    HTTPRequest req = new HTTPRequest(url);
    if(cookie!=null)
      req.setHeader(cookie);
    HTTPResponse resp = getURLFetchService().fetch(req);
    updateCookies(resp);
    int responseCode = -1;
    if (resp != null) {
      responseCode = resp.getResponseCode();
View Full Code Here

    throw new IOException("Problem calling GET on: " + url.toString() + " response: " + responseCode);
  }

  public String postMethod(URL url, String params) throws IOException {
    log.finer("Calling POST on " + url + " with params: " + params);
    HTTPRequest req = new HTTPRequest(url, POST, followRedirects()); //.withDeadline(10.0));
    //req.setHeader(new HTTPHeader("x-header-one", "some header"));
    if(cookie!=null)
      req.setHeader(cookie);
    if(sessionParam!=null)
      params = sessionParam + "&" + params;
    req.setPayload(params.getBytes(RESPONSE_CONTENT_ENCODING));
 
    HTTPResponse resp = getURLFetchService().fetch(req);
    updateCookies(resp);
    int responseCode = -1;
    if (resp != null) {
View Full Code Here

    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());

    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      throw new IOException( //
View Full Code Here

    getwork.append("params", work.data);
    getwork.put("id", 0);

    URL url = new URL(config.getJsonRpcServer());
    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(getwork.toString().getBytes());
    req.addHeader(new HTTPHeader("Authorization", config.getAuth()));

    HTTPResponse resp = ufs.fetch(req);
    String content = new String(resp.getContent());
    if (resp.getResponseCode() != 200) {
      log.severe( //
View Full Code Here

   
   
    //URL url = new URL(urlStr);
    URLFetchService urlFetchService =
    URLFetchServiceFactory.getURLFetchService();
    HTTPRequest httpRequest = new HTTPRequest(url);
    HTTPResponse response = urlFetchService.fetch(httpRequest);
   
   
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setReadTimeout(60000);
View Full Code Here

      FetchOptions.Builder.doNotFollowRedirects().disallowTruncate().validateCertificate();
  private HttpContent content;
  private final HTTPRequest request;

  UrlFetchRequest(HTTPMethod method, String url) throws IOException {
    request = new HTTPRequest(new URL(url), method, OPTIONS);
  }
View Full Code Here

    assertTrue(expected + "\nis not a prefix of:\n" + result, result.startsWith(expected));
  }

  @Test
  public void testDescribeRequestAndResponseF() throws Exception {
    HTTPRequest request = new HTTPRequest(new URL("http://ping/pong"));
    request.setPayload("hello".getBytes());
    request.addHeader(new HTTPHeader("k1", "v1"));
    request.addHeader(new HTTPHeader("k2", "v2"));
    HTTPResponse response = mock(HTTPResponse.class);
    when(response.getHeadersUncombined()).thenReturn(ImmutableList.of(new HTTPHeader("k3", "v3")));
    when(response.getResponseCode()).thenReturn(500);
    when(response.getContent()).thenReturn("bla".getBytes());
    String expected = "Request: GET http://ping/pong\nk1: v1\nk2: v2\n\n"
View Full Code Here

    }
  }

  @Test
  public void testCopyRequest() throws Exception {
    HTTPRequest request = new HTTPRequest(new URL("http://h1/v1"), HTTPMethod.HEAD);
    request.setHeader(new HTTPHeader("k3", "v3"));
    HTTPRequest copy = URLFetchUtils.copyRequest(request);
    assertEquals("http://h1/v1", copy.getURL().toString());
    assertEquals(HTTPMethod.HEAD, copy.getMethod());
    assertEquals(1, copy.getHeaders().size());
    assertEquals("k3", copy.getHeaders().get(0).getName());
    assertEquals("v3", copy.getHeaders().get(0).getValue());
  }
View Full Code Here

      @Override
      public String call() {
        return getToken();
      }
    }, RETRY_PARAMS, EXCEPTION_HANDLER);
    HTTPRequest request = URLFetchUtils.copyRequest(req);
    request.setHeader(new HTTPHeader("Authorization", "Bearer " + token));
    return request;
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.urlfetch.HTTPRequest

Copyright © 2018 www.massapicom. 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.