Package com.google.appengine.api.urlfetch

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


     *
     * @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


            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

    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

  @Override
  public AccountStore.Record getUserInfo() throws IOException {
    URL targetUrl;
    try {
      targetUrl = new URL("https://www.googleapis.com/oauth2/v1/userinfo");
      HTTPResponse resp =
          fetch.get().fetch(
              new HTTPRequest(targetUrl, HTTPMethod.GET, FetchOptions.Builder.withDefaults()
                  .disallowTruncate()));
      String body = OAuthedFetchService.getUtf8ResponseBody(resp, EXPECTED_CONTENT_TYPE);
      JSONObject jsonObject;
View Full Code Here

    b.append("\n" + new String(resp.getContent(), Charsets.UTF_8));
    return "" + b;
  }

  private String fetch(HTTPRequest req) throws IOException {
    HTTPResponse response = fetchService.fetch(req);
    int responseCode = response.getResponseCode();

    if (responseCode >= 300 && responseCode < 400) {
      throw new RuntimeException("Unexpected redirect for url " + req.getURL() + ": "
          + describeResponse(response));
    }

    byte[] rawResponseBody = response.getContent();
    String responseBody;
    if (rawResponseBody == null) {
      responseBody = "";
    } else {
      responseBody = new String(rawResponseBody, Charsets.UTF_8);
View Full Code Here

    }

    @Test
    public void testFindFavIconUrl() throws Exception {
        String html = "html";
        HTTPResponse mockResponse = createMock(HTTPResponse.class);
        expect(mockResponse.getFinalUrl()).andReturn(null);
        expect(mockResponse.getContent()).andStubReturn(html.getBytes());

        String urlAsString = "http://my.domain.com/foo/index.html";
        URL url = new URL(urlAsString);
        expect(mockUrlFetchService.fetch(url)).andReturn(mockResponse);
View Full Code Here

    }

    @Test
    public void testFindFavIconUrlWhenRedirectOccurs() throws Exception {
        String html = "html";
        HTTPResponse mockResponse = createMock(HTTPResponse.class);
        URL finalUrl = new URL("http://www.my.domain.com/foo/index.html");
        expect(mockResponse.getFinalUrl()).andStubReturn(finalUrl);
        expect(mockResponse.getContent()).andStubReturn(html.getBytes());

        String urlAsString = "http://my.domain.com/foo/index.html";
        URL url = new URL(urlAsString);
        expect(mockUrlFetchService.fetch(url)).andReturn(mockResponse);
View Full Code Here

TOP

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

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.