Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.HTTPRequest.addHeader()


    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


    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

  @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());
View Full Code Here

  @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

  }

  static HTTPRequest copyRequest(HTTPRequest in) {
    HTTPRequest out = new HTTPRequest(in.getURL(), in.getMethod(), in.getFetchOptions());
    for (HTTPHeader h : in.getHeaders()) {
      out.addHeader(h);
    }
    out.setPayload(in.getPayload());
    return out;
  }
}
View Full Code Here

        FetchOptions.Builder.disallowTruncate()
            .doNotFollowRedirects()
            .validateCertificate()
            .setDeadline(timeoutMillis / 1000.0));
    for (HTTPHeader header : headers) {
      request.addHeader(header);
    }
    request.addHeader(USER_AGENT);
    return request;
  }
View Full Code Here

            .validateCertificate()
            .setDeadline(timeoutMillis / 1000.0));
    for (HTTPHeader header : headers) {
      request.addHeader(header);
    }
    request.addHeader(USER_AGENT);
    return request;
  }

  @Override
  public int getMaxWriteSizeByte() {
View Full Code Here

  @Override
  public Response get(String path) throws IOException {
    HTTPRequest req = new HTTPRequest(new URL(makeUrl(path)), HTTPMethod.GET);
    req.getFetchOptions().doNotFollowRedirects();
    for (String[] headerPair : getHeadersForGet()) {
      req.addHeader(new HTTPHeader(headerPair[0], headerPair[1]));
    }
    addCookies(req);
    HTTPResponse resp = urlFetch.fetch(req);
    return createResponse(resp);
  }
View Full Code Here

  @Override
  public Response post(String path, String mimeType, byte[] body) throws IOException {
    HTTPRequest req = new HTTPRequest(new URL(makeUrl(path)), HTTPMethod.POST);
    req.getFetchOptions().doNotFollowRedirects();
    for (String[] headerPair : getHeadersForPost(mimeType)) {
      req.addHeader(new HTTPHeader(headerPair[0], headerPair[1]));
    }
    addCookies(req);
    req.setPayload(body);
    HTTPResponse resp = urlFetch.fetch(req);
    return createResponse(resp);
View Full Code Here

     
      if (WithTokenHeader) {
        if (token == null) {
          throw new IllegalStateException("Oauth2 token is not set!");
        }
        request.addHeader(new HTTPHeader("Authorization", "OAuth2 "
            + token));
        request.addHeader(new HTTPHeader("API-RemoteIP", ipaddr
            .getHostAddress()));
      }
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.