Package com.ning.http.client.AsyncHttpClient

Examples of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder


        path = _pathFinder.appendStoreEntryPath(path);
        path = _keyConverter.appendToPath(path, contentId);     
        if (params != null) {
            path = params.appendToPath(path, contentId);
        }
        BoundRequestBuilder reqBuilder = path.deleteRequest(_httpClient);

        try {
            Future<Response> futurama = _httpClient.executeRequest(reqBuilder.build());
            // First, see if we can get the answer without time out...
            Response resp;
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
View Full Code Here


            path = _pathFinder.appendStoreEntryPath(path);
            path = _keyConverter.appendToPath(path, contentId);
            if (params != null) {
                path = params.appendToPath(path, contentId);
            }
            BoundRequestBuilder reqBuilder = path.headRequest(_httpClient);

            HeadHandler<K> hh = new HeadHandler<K>(this, _server, startTime);
            ListenableFuture<Object> futurama = _httpClient.executeRequest(reqBuilder.build(), hh);
            // First, see if we can get the answer without time out...
            try {
                futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                return new AHCHeadCallResult(CallFailure.timeout(_server, startTime, System.currentTimeMillis()));
View Full Code Here

            return failed(CallFailure.timeout(_server, startTime, startTime));
        }
        AHCPathBuilder path = _server.rootPath();
        path = _pathFinder.appendStoreEntryInfoPath(path);
        path = _keyConverter.appendToPath(path, contentId);
        BoundRequestBuilder reqBuilder = path
                .listRequest(_httpClient)
                ;
        InputStream in = null;
        try {
            Future<Response> futurama = _httpClient.executeRequest(reqBuilder.build());
            // First, see if we can get the answer without time out...
            Response resp;
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
View Full Code Here

            return failed(CallFailure.timeout(_server, startTime, startTime));
        }
        AHCPathBuilder path = _server.rootPath();
        path = _pathFinder.appendStoreListPath(path);
        path = _keyConverter.appendToPath(path, prefix);
        BoundRequestBuilder reqBuilder = path
                .listRequest(_httpClient)
                .addQueryParameter(ClusterMateConstants.QUERY_PARAM_MAX_ENTRIES, String.valueOf(maxResults))
                .addQueryParameter(ClusterMateConstants.QUERY_PARAM_TYPE, type.toString())
                ;
       
        if (lastSeen != null) {
            reqBuilder = reqBuilder
                    .addQueryParameter(ClusterMateConstants.QUERY_PARAM_LAST_SEEN, toBase64(lastSeen.asBytes()));
        }

        InputStream in = null;
        try {
            Future<Response> futurama = _httpClient.executeRequest(reqBuilder.build());
            // First, see if we can get the answer without time out...
            Response resp;
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
View Full Code Here

        Generator<K> gen = new Generator<K>(content, _keyConverter);
        int checksum = gen.getChecksum();
        path = path.addParameter(ClusterMateConstants.QUERY_PARAM_CHECKSUM,
                (checksum == 0) ? "0" : String.valueOf(checksum));

        BoundRequestBuilder reqBuilder = path.putRequest(_httpClient);
        reqBuilder = reqBuilder.setBody(gen);
        ListenableFuture<Response> futurama = _httpClient.executeRequest(reqBuilder.build());

        // First, see if we can get the answer without time out...
        Response resp;
        try {
            resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
View Full Code Here

        if (range != null) {
            path = path.setHeader(ClusterMateConstants.HTTP_HEADER_RANGE_FOR_REQUEST,
                    range.asRequestHeader());
        }

        BoundRequestBuilder reqBuilder = path.getRequest(_httpClient);

        int statusCode = -1;
        UncompressingAsyncHandler<T> handler = new UncompressingAsyncHandler<T>(processor);
       
        try {
            T resp = null;
            ListenableFuture<T> futurama = _httpClient.executeRequest(reqBuilder.build(), handler);
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                return new AHCReadCallResult<T>(CallFailure.timeout(_server, startTime, System.currentTimeMillis()));
            }
View Full Code Here

        if (range != null) {
            path = path.setHeader(ClusterMateConstants.HTTP_HEADER_RANGE_FOR_REQUEST,
                    range.asRequestHeader());
        }

        BoundRequestBuilder reqBuilder = path.getRequest(_httpClient);

        int statusCode = -1;
        UncompressingAsyncHandler<T> handler = new UncompressingAsyncHandler<T>(processor);
       
        try {
            T resp = null;
            ListenableFuture<T> futurama = _httpClient.executeRequest(reqBuilder.build(), handler);
            try {
                resp = futurama.get(timeout, TimeUnit.MILLISECONDS);
            } catch (TimeoutException e) {
                return new AHCGetCallResult<T>(CallFailure.timeout(_server, startTime, System.currentTimeMillis()));
            }
View Full Code Here

  }
 

  public BoundRequestBuilder createRequest() {
    BoundRequestBuilder builder = null;

    try {

      String completeUrl = requestUrl;

      if (VarUtils.IN_DETAIL_DEBUG) {
        models.utils.LogUtils.printLogError("NING completeUrl " + completeUrl);
      }

      switch (httpMethod) {
      case GET:
        builder = client.prepareGet(completeUrl);
        break;
      case POST:
        builder = client.preparePost(completeUrl);
        break;
      case PUT:
        builder = client.preparePut(completeUrl);
        break;
      case DELETE:
        builder = client.prepareDelete(completeUrl);
        break;
      default:
        break;
      }
      if (builder != null) {


        //new
        MyHttpUtils.addHeaders(builder,
            this.httpHeaderMap);
       
        //OLD Depreciated 20140310
        //MyHttpUtils.addAllHeadersFromHeaderMetadataMap(builder, httpHeaderType);
       
       
        if (!StringUtils.isNullOrEmpty(postData)) {
          builder.setBody(postData);
        }

      } else {
         models.utils.LogUtils.printLogError
             ("Failed to build request; builder is null, unknown method in createRequest()");
View Full Code Here

          if (tryCount == 1) {
            sender = getSender();

            // Construct and submit NING Request
            BoundRequestBuilder request = createRequest();
            // String targetUrl = request.build().getUrl();
            request.execute(new HttpAsyncHandler(this));

            timeoutDuration = Duration
                .create(VarUtils.ACTOR_MAX_OPERATION_TIME_SECONDS_DEFAULT,
                    TimeUnit.SECONDS);
View Full Code Here

        else {
          AsyncHttpClient asyncHttpClient = null;
          try {
            for (SourceFederatedQueryConfigPojo.FederatedQueryEndpointUrl request: endpoint.requests) {
              asyncHttpClient = new AsyncHttpClient();
              BoundRequestBuilder asyncRequest = null;
              String postContent = null;
              if (null != request.httpFields) {
                postContent = request.httpFields.get("Content");
                if (null == postContent)
                  postContent = request.httpFields.get("content");
              }//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "test" }
             
              if (null == postContent) {
                asyncRequest = asyncHttpClient.prepareGet(request.endPointUrl.replace("$1", entityValue));
              }
              else {
                asyncRequest = asyncHttpClient.preparePost(request.endPointUrl.replace("$1", entityValue));             
              }//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "test" }
             
              if (null != request.urlParams) {
                for (Map.Entry<String, String> keyValue: request.urlParams.entrySet()) {
                  asyncRequest = asyncRequest.addQueryParameter(keyValue.getKey(), keyValue.getValue().replace("$1", entityValue));
                }
              }//TESTED (1.5, 1.6, 3.*, 4.*)
              if (null != request.httpFields) {
                for (Map.Entry<String, String> keyValue: request.httpFields.entrySet()) {
                  if (!keyValue.getKey().equalsIgnoreCase("content")) {
                    asyncRequest = asyncRequest.addHeader(keyValue.getKey(), keyValue.getValue().replace("$1", entityValue));
                  }
                }             
              }//TESTED (by hand, "http://httpbin.org/cookies", "httpFields": { "Cookie": "mycookie=test" }
              if (null != postContent) {
                asyncRequest = asyncRequest.setBody(postContent.replace("$1", entityValue));
              }//TESTED (by hand, "http://httpbin.org/post", "httpFields": { "Content": "$1" }
             
              // Common params:
              FederatedRequest requestOverview = new FederatedRequest();
              requestOverview.endpointInfo = endpoint;
              requestOverview.communityIdStrs = communityIdStrs;
              requestOverview.requestParameter = entityValue;
              requestOverview.asyncClient = asyncHttpClient;
              requestOverview.queryIndex = entityIndex;
              requestOverview.mergeKey = endpoint.parentSource.getKey();
              requestOverview.subRequest = request;
   
              // Now check out the cache:
              URI rawUri = asyncRequest.build().getRawURI();
              String url = rawUri.toString();
              if ((null == endpoint.parentSource.getOwnedByAdmin()) || !endpoint.parentSource.getOwnedByAdmin())
              {
                //TODO (INF-2798): Make this consistent with the how security is handled elsewhere
                int port = rawUri.getPort();
                if ((80 != port) && (443 != port) && (-1 != port)) {
                  _logger.error("Only admin can make requests on non-standard ports: " + url + ": " + port);
                  if (_testMode) {
                    asyncHttpClient.close();
                    throw new RuntimeException("Only admin can make requests on non-standard ports: " + url + ": " + port);
                  }                 
                }
              }//TESTED (by hand)
             
              BasicDBObject cachedVal = this.getCache(url, endpoint);
              requestOverview.cachedResult = cachedVal;
              requestOverview.cachedDoc_expired = cachedDoc_expired;
             
              if (null == cachedVal) {
                requestOverview.responseFuture = asyncRequest.execute();           
              }         
              else {
                //DEBUG
                if (_DEBUG) _logger.debug("DEB: preQA6b: Cache: " + url + " , " + cachedVal);
               
View Full Code Here

TOP

Related Classes of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder

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.