Package com.google.appengine.api.urlfetch

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


   }

   @Test
   void testConvertRequestGetsTargetAndUri() throws IOException {
      HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(endPoint).build();
      HTTPRequest gaeRequest = req.apply(request);
      assertEquals(gaeRequest.getURL().getPath(), "/foo");
   }
View Full Code Here


   }

   @Test
   void testConvertRequestSetsFetchOptions() throws IOException {
      HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(endPoint).build();
      HTTPRequest gaeRequest = req.apply(request);
      assert gaeRequest.getFetchOptions() != null;
   }
View Full Code Here

   void testConvertRequestSetsHeaders() throws IOException {
      HttpRequest request = HttpRequest.builder()
                                       .method(HttpMethod.GET)
                                       .endpoint(endPoint)
                                       .addHeader("foo", "bar").build();
      HTTPRequest gaeRequest = req.apply(request);
      assertEquals(gaeRequest.getHeaders().get(0).getName(), "foo");
      assertEquals(gaeRequest.getHeaders().get(0).getValue(), "bar");
   }
View Full Code Here

   }

   @Test
   void testConvertRequestNoContent() throws IOException {
      HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(endPoint).build();
      HTTPRequest gaeRequest = req.apply(request);
      assert gaeRequest.getPayload() == null;
      assertEquals(gaeRequest.getHeaders().size(), 1);// user agent
      assertEquals(gaeRequest.getHeaders().get(0).getName(), HttpHeaders.USER_AGENT);
      assertEquals(gaeRequest.getHeaders().get(0).getValue(), "jclouds/1.0 urlfetch/1.4.3");
   }
View Full Code Here

   }

   private void testHoot(HttpRequest request) throws IOException {
      request.getPayload().getContentMetadata().setContentType("text/plain");
      request.getPayload().getContentMetadata().setContentMD5(new byte[] { 1, 2, 3, 4 });
      HTTPRequest gaeRequest = req.apply(request);

      StringBuilder builder = new StringBuilder();
      for (HTTPHeader header : gaeRequest.getHeaders()) {
         builder.append(header.getName()).append(": ").append(header.getValue()).append("\n");
      }
      assertEquals(builder.toString(),
      // note content-length is prohibited in gae
            "User-Agent: jclouds/1.0 urlfetch/1.4.3\nExpect: 100-continue\nContent-Type: text/plain\nContent-MD5: AQIDBA==\n");
      assertEquals(new String(gaeRequest.getPayload()), "hoot!");
   }
View Full Code Here

        break;
    }

    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);
View Full Code Here

    String currentUrl = url;

    for (int i = 0; i <= requestOptions.getMaxRedirects(); i++) {

      HTTPRequest httpRequest = new HTTPRequest(new URL(currentUrl),
          method, options);

      addHeaders(httpRequest, requestOptions);

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

      HTTPResponse httpResponse;
      try {
        httpResponse = fetchService.fetch(httpRequest);
View Full Code Here

      Log.warn(SimpleUrlRetrieverModule.class, ".run: not tried because time left is too short. URL", url);
      callback.onFailure(new IOException(
        "BasicUrlRetrieverModule.loadUrl: timeout is less than 200ms. Not worth trying..."));
      return;
    }
    HTTPRequest httpRequest = null;
    String urlString = url.toString();
    if (urlString.length() > Constants.MAX_URL_LENGTH) {
      if (urlString.indexOf('?') < 0) {
        Log.severe(
          this,
          "loadUrl: URL is longer than 2000 characters but there are no parameters that could be sent via POST (there is no \"?\" in the URL)! Thus, this URL can not be loaded. URL",
          urlString);
        //        callback.onSuccess(new byte[0]);
        // There is no data that can be loaded in a retry using this URL, thus success aka we did all we could.
        callback.onSuccess(null);
      }
      Log.warn(this, "loadUrl: URL longer than 2000 characters. Trying POST mode...");
      String[] urlSplit = urlString.split("\\?");
      assert urlSplit.length == 2 : urlSplit;
      try {
        httpRequest = new HTTPRequest(new URL(urlSplit[0]), HTTPMethod.POST);
        httpRequest.setPayload(urlSplit[1].getBytes(Constants.UTF8));
      } catch (Throwable t) {
        Log.warn(this, "loadUrl: URL longer than 2000 characters. Failed to convert to POST request! error", t);
      }
    }
    if (httpRequest == null) {
      httpRequest = new HTTPRequest(url);
    }
    httpRequest.getFetchOptions().disallowTruncate().doNotValidateCertificate().followRedirects();
    if (timeout > 0) {
      httpRequest.getFetchOptions().setDeadline(timeout / 1000d);
    }
    if (Util.notEmpty(requiredContentType)) {
      httpRequest.setHeader(new HTTPHeader("Accept", requiredContentType));
    }
    urlRetriever.addRequest(httpRequest, callback);
  }
View Full Code Here

     *             {@link GHttpEndpoint#isThrowExceptionOnFailure()} 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

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

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.