Package com.google.appengine.api.urlfetch

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


         url = request.getEndpoint().toURL();
      } catch (MalformedURLException e) {
         Throwables.propagate(e);
      }

      FetchOptions options = disallowTruncate();
      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();
View Full Code Here


        return new String(response.getContent(), encoding);
    }

    private static Object fetch(URL url, HTTPMethod method, Map<String, Object> options) throws IOException {
        URLFetchService urlFetch = URLFetchServiceFactory.getURLFetchService();
        FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();

        // specify the fetch options
        for (Entry<String, Object> entry : options.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
           
            switch(key) {
                case "allowTruncate":
                    if (DefaultGroovyMethods.asBoolean(value))
                        fetchOptions.allowTruncate();
                    else
                        fetchOptions.disallowTruncate();
                    break;
                case "followRedirects":
                    if (DefaultGroovyMethods.asBoolean(value))
                        fetchOptions.followRedirects();
                    else
                        fetchOptions.doNotFollowRedirects();
                    break;
                case "deadline":
                    fetchOptions.setDeadline(((Number)value).doubleValue());
                    break;
            // bypass the headers, payload, params and async options
                case "headers":
                case "payload":
                case "params":
View Full Code Here

//  }

    @Test(expected = IOException.class)
    public void fetchNonExistentLocalAppThrowsException() throws Exception {
        URL selfURL = new URL("BOGUS-" + appUrlBase + "/");
        FetchOptions fetchOptions = FetchOptions.Builder.withDefaults()
            .doNotFollowRedirects()
            .setDeadline(10.0);
        HTTPRequest httpRequest = new HTTPRequest(selfURL, HTTPMethod.GET, fetchOptions);
        URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
        HTTPResponse httpResponse = urlFetchService.fetch(httpRequest);
View Full Code Here

    }

    @Test
    public void testFollowRedirects() throws Exception {
        final URL redirect = getUrl("redirect");
        FetchOptions options = buildFetchOptions();
        options.followRedirects();
        testOptions(redirect, options, new ResponseHandler() {
            public void handle(HTTPResponse response) throws Exception {
                URL finalURL = response.getFinalUrl();
                Assert.assertEquals(getUrl(""), finalURL);
            }
View Full Code Here

    }

    @Test
    public void testDoNotFollowRedirects() throws Exception {
        final URL redirect = getUrl("redirect");
        FetchOptions options = buildFetchOptions();
        options.doNotFollowRedirects();
        testOptions(redirect, options, new ResponseHandler() {
            public void handle(HTTPResponse response) throws Exception {
                Assert.assertEquals(302, response.getResponseCode());
            }
        });
View Full Code Here

        });
    }

    @Test
    public void testAllowTruncate() throws Exception {
        FetchOptions options = buildFetchOptions();
        options.allowTruncate();
        testOptions(options);
    }
View Full Code Here

        testOptions(options);
    }

    @Test
    public void testDisallowTruncate() throws Exception {
        FetchOptions options = buildFetchOptions();
        options.disallowTruncate();
        testOptions(options);
    }
View Full Code Here

        testOptions(options);
    }

    @Test
    public void testValidateCertificate() throws Exception {
        FetchOptions options = buildFetchOptions();
        options.validateCertificate();
        testOptions(options);
    }
View Full Code Here

        testOptions(options);
    }

    @Test
    public void testDoNotValidateCertificate() throws Exception {
        FetchOptions options = buildFetchOptions();
        options.doNotValidateCertificate();
        testOptions(options);
    }
View Full Code Here

        testOptions(options);
    }

    @Test
    public void testWithDeadline() throws Exception {
        FetchOptions options = buildFetchOptions();
        options.setDeadline(10 * 1000.0);
        testOptions(options);
    }
View Full Code Here

TOP

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

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.