Package com.google.appengine.api.urlfetch

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


    }

    try {

      HTTPRequest httpRequest = new HTTPRequest(request.getUri().toURL(), method);
      HTTPResponse httpResponse = fetchService.fetch(httpRequest);
      return new AppEngineFetchResponse(httpResponse);

    } catch (MalformedURLException e) {
      throw new FetchException(e);
    } catch (IOException e) {
View Full Code Here


      if (method == HTTPMethod.POST && content != null) {
        httpRequest.setPayload(content.getBytes());
      }

      HTTPResponse httpResponse;
      try {
        httpResponse = fetchService.fetch(httpRequest);
      } catch (ResponseTooLargeException e) {
        return new TooLargeResponse(currentUrl);
      }

      if (!isRedirect(httpResponse.getResponseCode())) {
        boolean isResponseTooLarge =
          (getContentLength(httpResponse) > requestOptions.getMaxBodySize());
        return new AppEngineFetchResponse(httpResponse,
            isResponseTooLarge, currentUrl);
      } else {
View Full Code Here

    req.getFetchOptions().doNotFollowRedirects();
    for (String[] headerPair : getHeadersForGet()) {
      req.addHeader(new HTTPHeader(headerPair[0], headerPair[1]));
    }
    addCookies(req);
    HTTPResponse resp = urlFetch.fetch(req);
    return createResponse(resp);
  }
View Full Code Here

    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

      payload.append(String.format("%s=%s&", param[0], param[1]));
    }
    payload.setLength(payload.length() - 1);
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
    req.setPayload(payload.toString().getBytes());
    HTTPResponse resp = fetchService.fetch(req);
    HostedAppEngineClient.Response response =
        HostedAppEngineClient.createResponse(resp);
    return new PostResponse(resp.getResponseCode(), response.getBodyAsString());
  }
View Full Code Here

  @Override
  List<Cookie> getAppEngineLoginCookies(String urlStr) throws IOException {
    FetchOptions fetchOptions = FetchOptions.Builder.doNotFollowRedirects();
    URL url = new URL(urlStr);
    HTTPRequest req = new HTTPRequest(url, HTTPMethod.GET, fetchOptions);
    HTTPResponse resp = fetchService.fetch(req);
    if (resp.getResponseCode() != 302) {
      throw new LoginException("unexpected response from app engine: " + resp.getResponseCode());
    }
    List<Cookie> cookies = new ArrayList<Cookie>();
    for (HTTPHeader header : resp.getHeaders()) {
      if (header.getName().toLowerCase().equals("set-cookie")) {
        CookieSpecBase spec = new CookieSpecBase();
        Collections.addAll(cookies, spec.parse(url.getHost(),
            url.getPort() == -1 ? 0 : url.getPort(), url.getPath(),
            url.getProtocol().equals("https"), header.getValue()));
View Full Code Here

                .doNotFollowRedirects()
                .disallowTruncate();
            HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, options);

            URLFetchService service = URLFetchServiceFactory.getURLFetchService();
            HTTPResponse response = service.fetch(request);

            byte[] content = response.getContent();
            out.println("<p>Read PGAE blog feed (" + content.length + " characters).</p>");

        } catch (ResponseTooLargeException e) {
            out.println("<p>ResponseTooLargeException: " + e + "</p>");
View Full Code Here

                .doNotFollowRedirects()
                .disallowTruncate();
            HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, options);

            URLFetchService service = URLFetchServiceFactory.getURLFetchService();
            HTTPResponse response = service.fetch(request);

            byte[] content = response.getContent();
            out.println("<p>Read PGAE blog feed (" + content.length + " characters).</p>");

        } catch (ResponseTooLargeException e) {
            out.println("<p>ResponseTooLargeException: " + e + "</p>");
View Full Code Here

            public byte[] getContent(URLFetchRequest request)
                    throws IOException {
                return "hello".getBytes();
            }
        });
        HTTPResponse httpResponse = service.fetch(httpRequest);
        assertThat(httpResponse.getResponseCode(), is(200));
        assertThat(new String(httpResponse.getContent()), is("hello"));
    }
View Full Code Here

                    throws IOException {
                return "hello".getBytes();
            }
        });
        Future<HTTPResponse> future = service.fetchAsync(httpRequest);
        HTTPResponse httpResponse = future.get();
        assertThat(httpResponse.getResponseCode(), is(200));
        assertThat(new String(httpResponse.getContent()), is("hello"));
    }
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.