Package com.google.appengine.api.urlfetch

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


   
    @Test(expected = GHttpException.class)
    public void testFailureException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
    }
View Full Code Here


   
    @Test
    public void testFailureNoException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test?throwExceptionOnFailure=false");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
        assertEquals(500, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
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

    @Test(expected = GHttpException.class)
    public void testFailureException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
    }
View Full Code Here

    @Test
    public void testFailureNoException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test?throwExceptionOnFailure=false");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl());
        request.addHeader(new HTTPHeader("code", "500"));
        HTTPResponse response = service.fetch(request);
        binding.readResponse(endpoint, exchange, response);
        assertEquals(500, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

  public HttpRequestBuilder addHeader(String name, String value) {
    if (headers == null) {
      headers = new ArrayList<HTTPHeader>();
    }
    headers.add(new HTTPHeader(name, value));
    return this;
  }
View Full Code Here

    HTTPRequest req =
        new HTTPRequest(url, method == null ? HTTPMethod.POST : method, getFetchOptions());

    if (HTTPMethod.POST.equals(method)) {
      // TODO(ohler): use multipart/form-data for efficiency
      req.setHeader(new HTTPHeader("Content-Type", "application/x-www-form-urlencoded"));
      if (headers != null) {
        for (HTTPHeader header : headers) {
          req.addHeader(header);
        }
      }
View Full Code Here

    this.oAuthProvider = oAuthProvider;
  }

  @Override
  public void authorize(HTTPRequest req) {
    req.setHeader(new HTTPHeader("Authorization", "Bearer " + getCredentials().getAccessToken()));
  }
View Full Code Here

        try {
            setHeaders(req, request);
            if (req.getMethod() == POST) {
                if (HttpParameter.containsFile(req.getParameters())) {
                    String boundary = "----Twitter4J-upload" + System.currentTimeMillis();
                    request.setHeader(new HTTPHeader("Content-Type", "multipart/form-data; boundary=" + boundary));
                    boundary = "--" + boundary;
                    os = new ByteArrayOutputStream();
                    DataOutputStream out = new DataOutputStream(os);
                    for (HttpParameter param : req.getParameters()) {
                        if (param.isFile()) {
                            write(out, boundary + "\r\n");
                            write(out, "Content-Disposition: form-data; name=\"" + param.getName() + "\"; filename=\"" + param.getFile().getName() + "\"\r\n");
                            write(out, "Content-Type: " + param.getContentType() + "\r\n\r\n");
                            BufferedInputStream in = new BufferedInputStream(
                                    param.hasFileBody() ? param.getFileBody() : new FileInputStream(param.getFile())
                            );
                            int buff = 0;
                            while ((buff = in.read()) != -1) {
                                out.write(buff);
                            }
                            write(out, "\r\n");
                            in.close();
                        } else {
                            write(out, boundary + "\r\n");
                            write(out, "Content-Disposition: form-data; name=\"" + param.getName() + "\"\r\n");
                            write(out, "Content-Type: text/plain; charset=UTF-8\r\n\r\n");
                            logger.debug(param.getValue());
                            out.write(param.getValue().getBytes("UTF-8"));
                            write(out, "\r\n");
                        }
                    }
                    write(out, boundary + "--\r\n");
                    write(out, "\r\n");
                } else {
                    request.setHeader(new HTTPHeader(
                            "Content-Type",
                            "application/x-www-form-urlencoded"
                    ));
                    String postParam = HttpParameter.encodeParameters(req.getParameters());
                    logger.debug("Post Params: ", postParam);
                    byte[] bytes = postParam.getBytes("UTF-8");
                    request.setHeader(new HTTPHeader("Content-Length",
                            Integer.toString(bytes.length)));
                    os = new ByteArrayOutputStream();
                    os.write(bytes);
                }
                request.setPayload(os.toByteArray());
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.