Package com.google.appengine.api.urlfetch

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


      HttpRequestOptions requestOptions) {

    String contentType = requestOptions.getContentType();

    if (contentType != null) {
      httpRequest.addHeader(new HTTPHeader("Content-Type", contentType));
    }

    Map<String, String> headers = getRequestHeaders(requestOptions);

    if (headers != null) {
      for (Map.Entry<String, String> header : headers.entrySet()) {
        httpRequest.addHeader(new HTTPHeader(header.getKey(), header.getValue()));
      }
    }
  }
View Full Code Here


        return header.getName().equalsIgnoreCase("Set-Cookie");
      }
    });
    if(!cookies.isEmpty()) {
      logCookies(cookies);
      HTTPHeader setcookie = cookies.iterator().next();
      String[] values = setcookie.getValue().split(";");
      if(values.length>0) {
        String value = values[0];
        if(value.split("=")[0].equalsIgnoreCase("jsessionid")) {
          // only update jsessionid cookies
          cookie = new HTTPHeader("Cookie", value);
        }
      }
    }
  }
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) {
      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

    request = new HTTPRequest(new URL(url), method, OPTIONS);
  }

  @Override
  public void addHeader(String name, String value) {
    request.addHeader(new HTTPHeader(name, value));
  }
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"
        + "5 bytes of content\n\nResponse: 500 with 3 bytes of content\nk3: v3\nbla\n";
    String result =
View Full Code Here

      fail("NoSuchElementException expected");
    } catch (NoSuchElementException expected) {
    }

    List<HTTPHeader> headers =
        ImmutableList.of(new HTTPHeader("k3", "v3"), new HTTPHeader("k1", "v1"));
    when(response.getHeadersUncombined()).thenReturn(headers);
    assertEquals("v1", URLFetchUtils.getSingleHeader(response, "k1"));

    headers = ImmutableList.of(new HTTPHeader("k3", "v3"), new HTTPHeader("k1", "v1"),
        new HTTPHeader("k1", "v2"));
    when(response.getHeadersUncombined()).thenReturn(headers);
    try {
      URLFetchUtils.getSingleHeader(response, "k1");
      fail("NoSuchElementException expected");
    } catch (IllegalArgumentException  expected) {
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());
View Full Code Here

      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

  static RawGcsService createRawGcsService(Map<String, String> headers) {
    ImmutableSet.Builder<HTTPHeader> builder = ImmutableSet.builder();
    if (headers != null) {
      for (Map.Entry<String, String> header : headers.entrySet()) {
        builder.add(new HTTPHeader(header.getKey(), header.getValue()));
      }
    }
    RawGcsService rawGcsService;
    Value location = SystemProperty.environment.value();
    if (location == SystemProperty.Environment.Value.Production) {
View Full Code Here

TOP

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

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.