Package com.google.appengine.api.urlfetch

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


    StringBuilder payload = new StringBuilder();
    for (String[] param : postParams) {
      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>();
View Full Code Here

            URL url = new URL("http://ae-book.appspot.com/blog/atom.xml");

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

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

            byte[] content = response.getContent();
View Full Code Here

            URL url = new URL("http://ae-book.appspot.com/blog/atom.xml/");

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

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

            byte[] content = response.getContent();
View Full Code Here

     *
     */
    @Test
    public void urlFetch() throws Exception {
        URLFetchService service = URLFetchServiceFactory.getURLFetchService();
        HTTPRequest httpRequest = new HTTPRequest(new URL("http://hoge"));
        String queryString = "aaa=111";
        httpRequest.setPayload(queryString.getBytes("utf-8"));
        tester.setUrlFetchHandler(new URLFetchHandler() {

            public int getStatusCode(URLFetchRequest request)
                    throws IOException {
                return 200;
View Full Code Here

     *
     */
    @Test
    public void urlFetchAsync() throws Exception {
        URLFetchService service = URLFetchServiceFactory.getURLFetchService();
        HTTPRequest httpRequest = new HTTPRequest(new URL("http://hoge"));
        String queryString = "aaa=111";
        httpRequest.setPayload(queryString.getBytes("utf-8"));
        tester.setUrlFetchHandler(new URLFetchHandler() {

            public int getStatusCode(URLFetchRequest request)
                    throws IOException {
                return 200;
View Full Code Here

      }
     
      log("method:"+m+" URI:"+method.getURI()
          .toString());
     
      HTTPRequest request = new HTTPRequest(new URL(method.getURI().toString()),m);
      ipaddr = InetAddress.getLocalHost();
     
      log("WithTokenHeader:"+ WithTokenHeader);
      log("token:" + token);
     
      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));
        request.setPayload(EncodingUtil.getAsciiBytes(content));
      }
     
      List<HTTPHeader> reqHeaders=request.getHeaders();
      log("reqHeaders:"+ reqHeaders);
      if (reqHeaders != null){
        for (HTTPHeader httpHeader : reqHeaders) {
          log("RequestHeader name:"+httpHeader.getName()+" value:"+ httpHeader.getValue());
        }
      }
     
      log("final URL:"+request.getURL().toString());
     
      HTTPResponse responseFromServer = service.fetch(request);

      responseCode = responseFromServer.getResponseCode();
      log("Response:");
View Full Code Here

      options.doNotFollowRedirects();
      if (utils.relaxHostname() || utils.trustAllCerts())
         options.doNotFollowRedirects();
      options.setDeadline(10.0);

      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

      }
      checkRequestHasContentLengthOrChunkedEncoding(request,
            "After filtering, the request has neither chunked encoding nor content length: " + request);
      logger.debug("Sending request %s: %s", request.hashCode(), request.getRequestLine());
      wirePayloadIfEnabled(wire, request);
      HTTPRequest nativeRequest = convertToGaeRequest.apply(request);
      utils.logRequest(headerLog, request, ">>");
      return nativeRequest;
   }
View Full Code Here

      return nativeRequest;
   }

   @Override
   public ListenableFuture<HttpResponse> submit(final HttpCommand command) {
      HTTPRequest nativeRequest = filterLogAndConvertRe(command.getCurrentRequest());
      ListenableFuture<HttpResponse> response = transform(
            listenInPoolThread(urlFetchService.fetchAsync(nativeRequest)), convertToJcloudsResponse);

      return transform(response, new Function<HttpResponse, HttpResponse>() {
         public HttpResponse apply(HttpResponse response) {
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.