Package com.ning.http.client

Examples of com.ning.http.client.RequestBuilder


    * @throws Exception
    */
   @Test
   public void testSearch() throws Exception
   {
      RequestBuilder builder = new RequestBuilder("GET");
      String uri = UriTemplate.fromTemplate(SEARCH_BASE)
                              .append(SEARCH_PARAMS)
                              .set("format", "json")
                              .set("q", "URI Templates")
                              .set("rpp", "5")
                              .set("include_entities", true)
                              .set("result_type", "mixed")
                              .expand();
      Request request = builder.setUrl(uri).build();
      Assert.assertEquals("http://search.twitter.com/search.json?q=URI%20Templates&result_type=mixed&rpp=5&include_entities=true&result_type=mixed", uri);
      executeRequest(createClient(), request);
   }
View Full Code Here


   @Test
   public void testUserRepos() throws Exception
   {
     
     
      RequestBuilder builder = new RequestBuilder("GET");
      Request request = builder.setUrl(
             UriTemplate.fromTemplate(BASE)
                        .append("/users/{user}/repos")
                        .append(PAGINATION)
                        .set("user", "damnhandy")
                        .set("repo", "repos")
View Full Code Here

   @Test
   public void testCommitsApi() throws Exception
   {
     
     
      RequestBuilder builder = new RequestBuilder("GET");
      Request request = builder.setUrl(
             UriTemplate.fromTemplate(BASE)
                        .append(PATH_EXPRESSION)
                        .set("user", "damnhandy")
                        .set("repo", "Handy-URI-Templates")
                        .set("function","commits")
View Full Code Here

   @Test
   public void testCommitsApiWithSpecificCommit() throws Exception
   {
     
     
      RequestBuilder builder = new RequestBuilder("GET");
      Request request = builder.setUrl(
            UriTemplate.fromTemplate(BASE)
                       .append(PATH_EXPRESSION)
                       .set("user", "damnhandy")
                       .set("repo", "Handy-URI-Templates")
                       .set("function","commits")
View Full Code Here

         for (HttpRequestFilter filter : request.getFilters()) {
            request = filter.filter(request);
         }

         RequestBuilder builder = new RequestBuilder(request.getMethod());
         builder.setUrl(request.getEndpoint().toASCIIString());
         Payload payload = request.getPayload();
         if (payload != null) {
            boolean chunked = "chunked".equals(request.getFirstHeaderOrNull("Transfer-Encoding"));

            if (request.getPayload().getContentMetadata().getContentMD5() != null)
               builder.addHeader("Content-MD5", CryptoStreams.base64(request.getPayload().getContentMetadata()
                        .getContentMD5()));
            if (request.getPayload().getContentMetadata().getContentType() != null)
               builder.addHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentMetadata().getContentType());
            if (request.getPayload().getContentMetadata().getContentLanguage() != null)
               builder.addHeader(HttpHeaders.CONTENT_LANGUAGE, request.getPayload().getContentMetadata()
                        .getContentLanguage());
            if (request.getPayload().getContentMetadata().getContentEncoding() != null)
               builder.addHeader(HttpHeaders.CONTENT_ENCODING, request.getPayload().getContentMetadata()
                        .getContentEncoding());
            if (request.getPayload().getContentMetadata().getContentDisposition() != null)
               builder.addHeader("Content-Disposition", request.getPayload().getContentMetadata()
                        .getContentDisposition());
            if (!chunked) {
               Long length = checkNotNull(request.getPayload().getContentMetadata().getContentLength(),
                        "payload.getContentLength");
               builder.addHeader(HttpHeaders.CONTENT_LENGTH, length.toString());
            }
            setPayload(builder, payload);
         } else {
            builder.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
         }

         builder.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
         for (Map<String, String> entry : request.getHeaders().entries()) {
            builder.addHeader(entry.getKey(), entry.getValue());
         }

         return builder.build();
      }
View Full Code Here

    Request getRequest(final ClientRequest cr) {
        final String strMethod = cr.getMethod();
        final URI uri = cr.getURI();

        RequestBuilder builder = new RequestBuilder(strMethod).setUrl(uri.toString());

        final Request.EntityWriter entity = getHttpEntity(cr);

        if(entity != null) {
            builder = builder.setBody(entity);
        }

        ProxyServer proxyServer = createProxyServer(cr);
        if(proxyServer != null)
            builder.setProxyServer(proxyServer);

        if(this.clientConfig != null) {
            if(!this.clientConfig.getPropertyAsFeature(NonBlockingClientConfig.PROPERTY_DISABLE_COOKIES)) {
                for(Cookie cookie : cookieStore.get())
                    builder = builder.addCookie(cookie);
                cookieStore.remove();
            }

            if(this.clientConfig.getPropertyAsFeature(ClientConfig.PROPERTY_FOLLOW_REDIRECTS))
                builder = builder.setFollowRedirects(true);
            else
                builder = builder.setFollowRedirects(false);
        }

        Request request = builder.build();

//        /* extremely ugly, unnecessary and inefficient. Unfortunately it is needed
//           because client side providers which modifies header values when entity is
//           being written. Ning Client writes is too late, so header is ClientRequest is
//           not yet changed and not propagated into Nings Request.
View Full Code Here

    // make HTTP call to workflow service.
    InetSocketAddress endpoint = discoverable.getSocketAddress();
    // Construct request
    String url = String.format("http://%s:%d/status", endpoint.getHostName(), endpoint.getPort());
    Request workflowRequest = new RequestBuilder("GET").setUrl(url).build();

    httpClient.executeRequest(workflowRequest, new AsyncCompletionHandler<Void>() {
                                @Override
                                public Void onCompleted(Response response) throws Exception {
                                  callback.handle(new Status(Status.Code.OK,
View Full Code Here

            throw new ZenDeskException(e.getMessage(), e);
        }
    }

    private Request req(String method, Uri template) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.setUrl(template.toString());
        return builder.build();
    }
View Full Code Here

        builder.setUrl(template.toString());
        return builder.build();
    }

    private Request req(String method, Uri template, String contentType, byte[] body) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.setUrl(template.toString());
        builder.addHeader("Content-type", contentType);
        builder.setBody(body);
        return builder.build();
    }
View Full Code Here

        builder.setBody(body);
        return builder.build();
    }

    private Request req(String method, Uri template, int page) {
        RequestBuilder builder = new RequestBuilder(method);
        if (realm != null) {
            builder.setRealm(realm);
        }
        builder.addQueryParameter("page", Integer.toString(page));
        builder.setUrl(template.toString().replace("%2B", "+")); //replace out %2B with + due to API restriction
        return builder.build();
    }
View Full Code Here

TOP

Related Classes of com.ning.http.client.RequestBuilder

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.