Package com.google.appengine.api.urlfetch

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


  @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()));
      }

      if (method instanceof PostMethod){
        String content = EncodingUtil.formUrlEncode(((PostMethod)method).getParameters(), getRequestCharSet((PostMethod)method));
View Full Code Here

      HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options);

      for (Entry<String, String> entry : request.getHeaders().entries()) {
         String header = entry.getKey();
         if (!prohibitedHeaders.contains(header))
            gaeRequest.addHeader(new HTTPHeader(header, entry.getValue()));
      }
      gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT));
      /**
       * byte [] content is replayable and the only content type supportable by GAE. As such, we
       * convert the original request content to a byte array.
       */
      if (request.getPayload() != null) {
         InputStream input = request.getPayload().getInput();
         try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            request.getPayload().writeTo(out);
            byte[] array = out.toByteArray();
            if (!request.getPayload().isRepeatable()) {
               Payload oldPayload = request.getPayload();
               request.setPayload(array);
               HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata());
            }
            gaeRequest.setPayload(array);
            if (array.length > 0) {
               gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue"));
            }
         } catch (IOException e) {
            Throwables.propagate(e);
         } finally {
            Closeables2.closeQuietly(input);
         }

         for (Entry<String, String> header : contentMetadataCodec.toHeaders(
               request.getPayload().getContentMetadata()).entries()) {
            if (!prohibitedHeaders.contains(header.getKey()))
               gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue()));
         }
      }
      return gaeRequest;
   }
View Full Code Here

   @Test
   void testConvertWithHeaders() throws IOException {
      HTTPResponse gaeResponse = createMock(HTTPResponse.class);
      expect(gaeResponse.getResponseCode()).andReturn(200);
      List<HTTPHeader> headers = Lists.newArrayList();
      headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
      expect(gaeResponse.getHeaders()).andReturn(headers);
      expect(gaeResponse.getContent()).andReturn(null).atLeastOnce();
      replay(gaeResponse);
      HttpResponse response = req.apply(gaeResponse);
      assertEquals(response.getStatusCode(), 200);
View Full Code Here

   @Test
   void testConvertWithContent() throws IOException {
      HTTPResponse gaeResponse = createMock(HTTPResponse.class);
      expect(gaeResponse.getResponseCode()).andReturn(200);
      List<HTTPHeader> headers = Lists.newArrayList();
      headers.add(new HTTPHeader(HttpHeaders.CONTENT_TYPE, "text/xml"));
      expect(gaeResponse.getHeaders()).andReturn(headers);
      expect(gaeResponse.getContent()).andReturn("hello".getBytes()).atLeastOnce();
      replay(gaeResponse);
      HttpResponse response = req.apply(gaeResponse);
      assertEquals(response.getStatusCode(), 200);
View Full Code Here

      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 (Entry<String, String> header : headers.entrySet()) {
        httpRequest.addHeader(new HTTPHeader(header.getKey(), header.getValue()));
      }
    }
  }
View Full Code Here

    httpRequest.getFetchOptions().disallowTruncate().doNotValidateCertificate().followRedirects();
    if (timeout > 0) {
      httpRequest.getFetchOptions().setDeadline(timeout / 1000d);
    }
    if (Util.notEmpty(requiredContentType)) {
      httpRequest.setHeader(new HTTPHeader("Accept", requiredContentType));
    }
    urlRetriever.addRequest(httpRequest, callback);
  }
View Full Code Here

    protected void writeRequestHeaders(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) {
        HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
        for (String headerName : exchange.getIn().getHeaders().keySet()) {
            String headerValue = exchange.getIn().getHeader(headerName, String.class);
            if (strategy != null && !strategy.applyFilterToCamelHeaders(headerName, headerValue, exchange)) {
                request.addHeader(new HTTPHeader(headerName, headerValue));
            }
        }
    }
View Full Code Here

    protected void writeRequestHeaders(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) {
        HeaderFilterStrategy strategy = endpoint.getHeaderFilterStrategy();
        for (String headerName : exchange.getIn().getHeaders().keySet()) {
            String headerValue = exchange.getIn().getHeader(headerName, String.class);
            if (strategy != null && !strategy.applyFilterToCamelHeaders(headerName, headerValue, exchange)) {
                request.addHeader(new HTTPHeader(headerName, headerValue));
            }
        }
    }
View Full Code Here

   
    @Test
    public void testReadResponseHeaders() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("test", "abc"));
        request.addHeader(new HTTPHeader("content-type", "text/plain"));
        HTTPResponse response = service.fetch(request);
        binding.readResponseHeaders(endpoint, exchange, response);
        assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
        assertEquals("abc", exchange.getOut().getHeader("test"));
        assertEquals("text/plain", exchange.getOut().getHeader("content-type"));
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.