Package com.google.appengine.api.urlfetch

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


    }
   
    @Test
    public void testWriteRequestHeaders() throws Exception {
        GHttpEndpoint endpoint = createEndpoint("ghttp://somewhere.com:9090/path");
        HTTPRequest request = createRequest();
        // Shouldn't be filtered out
        exchange.getIn().setHeader("test", "abc");
        // Should be filtered out
        exchange.getIn().setHeader("org.apache.camel.whatever", "xyz");
        exchange.getIn().setHeader("CamelWhatever", "xyz");
        exchange.getIn().setHeader(Exchange.HTTP_QUERY, "x=y");
        binding.writeRequestHeaders(endpoint, exchange, request);
        assertEquals(1, request.getHeaders().size());
        assertEquals("test", request.getHeaders().get(0).getName());
        assertEquals("abc", request.getHeaders().get(0).getValue());
    }
View Full Code Here


        assertEquals("abc", request.getHeaders().get(0).getValue());
    }

    @Test
    public void testWriteRequestBody() throws Exception {
        HTTPRequest request = createRequest();
        String body = "abc";
        exchange.getIn().setBody(body);
        binding.writeRequestBody(null, exchange, request);
        assertArrayEquals(body.getBytes(), request.getPayload());
    }
View Full Code Here

    }
   
    @Test
    public void testWriteRequest() throws Exception {
        GHttpEndpoint endpoint = createEndpoint("ghttp://somewhere.com:9090/path");
        HTTPRequest request = binding.writeRequest(endpoint, exchange, null);
        assertEquals("http://somewhere.com:9090/path", request.getURL().toString());
        assertEquals(HTTPMethod.GET, request.getMethod());
    }
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
    public void testReadResponseBody() throws Exception {
        GHttpEndpoint endpoint = createEndpoint(getBaseUri("ghttp") + "/test");
        HTTPRequest request = new HTTPRequest(endpoint.getEndpointUrl(), HTTPMethod.POST);
        request.setPayload("abc".getBytes());
        HTTPResponse response = service.fetch(request);
        binding.readResponseBody(null, exchange, response);
        assertEquals("abc", exchange.getOut().getBody(String.class));
    }
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

     * returns <code>true</code>.
     *
     * @see GHttpBinding
     */
    public void process(Exchange exchange) throws Exception {
        HTTPRequest request = getOutboundBinding().writeRequest(getEndpoint(), exchange, null);
        HTTPResponse response = getUrlFetchService().fetch(request);
        getOutboundBinding().readResponse(getEndpoint(), exchange, response);
    }
View Full Code Here

     *
     * @return a newly created {@link HTTPRequest} instance containing data from
     *         <code>exchange</code>.
     */
    public HTTPRequest writeRequest(GHttpEndpoint endpoint, Exchange exchange, HTTPRequest request) throws Exception {
        HTTPRequest answer = new HTTPRequest(
                getRequestUrl(endpoint, exchange),
                getRequestMethod(endpoint, exchange));
        writeRequestHeaders(endpoint, exchange, answer);
        writeRequestBody(endpoint, exchange, answer);
        return answer;
View Full Code Here

    static final String APP_ID = "YOUR_APP_ID";

    public static Set<String> parse(String sentence) throws IOException,
            SAXException, ParserConfigurationException {
        String baseUrl = "http://jlp.yahooapis.jp/MAService/V1/parse";
        HTTPRequest request =
            new HTTPRequest(new URL(baseUrl
                + "?appid="
                + URLEncoder.encode(APP_ID, "utf-8")), HTTPMethod.POST);
        StringBuilder payload =
            new StringBuilder()
                .append("filter=9")
                .append("&sentence=")
                .append(URLEncoder.encode(sentence, "utf-8"));
        request.setPayload(payload.toString().getBytes("utf-8"));
        HTTPResponse response =
            URLFetchServiceFactory.getURLFetchService().fetch(request);
        return extractKeyWords(new StringReader(new String(
            response.getContent(),
            "utf-8")));
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.