Search in sources :

Example 6 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method postUrlAsString.

/**
 * 通过POST方法请求url
 *
 * @param url
 * @param params
 */
public static void postUrlAsString(String url, Map<String, String> params, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.setBodyEncoding("utf-8");
        setPostParams(params, rb);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 7 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method uploadFile.

public static void uploadFile(String url, Map<String, String> params, File file, String inputName, String fileName, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        setPostParams(params, rb);
        FilePart part = new FilePart(inputName, fileName, file);
        rb.addBodyPart(part);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException) FilePart(com.ning.http.multipart.FilePart)

Example 8 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method getUrlAsString.

/**
 * 通过GET方法请求url
 *
 * @param url
 * @param params
 */
public static void getUrlAsString(String url, Map<String, String> params, int reqTimeout, HttpResultCallback callback) {
    if (StringUtils.isBlank(url)) {
        return;
    }
    String gurl = getFullUrl(url, params, "utf-8");
    try {
        BoundRequestBuilder rb = getAsyncHttpClient(reqTimeout).prepareGet(gurl);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 9 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project new-cloud by xie-summer.

the class AsyncHttpUtils method postBodyAsString.

/**
 * 通过POST方法请求url
 *
 * @param url
 * @param body
 */
public static void postBodyAsString(String url, String body, HttpResultCallback callback) {
    try {
        BoundRequestBuilder rb = getDefault().preparePost(url);
        rb.setHeader("Accept-Encoding", "gzip,deflate");
        rb.setBodyEncoding("utf-8");
        rb.setBody(body);
        rb.execute(new AsynchHandler(callback));
    } catch (IOException e) {
        DB_LOGGER.error(e, 30);
    }
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 10 with BoundRequestBuilder

use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.

the class BaragonLoadBalancerClientImpl method getUpstreamsForRequest.

public List<LoadBalancerUpstream> getUpstreamsForRequest(String singularityRequestId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    final String loadBalancerStateUri = getLoadBalancerStateUri(singularityRequestId);
    final BoundRequestBuilder requestBuilder = httpClient.prepareGet(loadBalancerStateUri);
    final Request request = requestBuilder.build();
    LOG.debug("Sending load balancer {} request for {} to {}", request.getMethod(), singularityRequestId, request.getUrl());
    ListenableFuture<Response> future = httpClient.executeRequest(request);
    Response response = future.get(loadBalancerTimeoutMillis, TimeUnit.MILLISECONDS);
    LOG.debug("Load balancer {} request {} returned with code {}", request.getMethod(), singularityRequestId, response.getStatusCode());
    Optional<BaragonServiceState> maybeBaragonServiceState = Optional.ofNullable(objectMapper.readValue(response.getResponseBodyAsBytes(), BaragonServiceState.class));
    return maybeBaragonServiceState.map(BaragonServiceState::getUpstreams).orElse(Collections.emptyList()).stream().map(LoadBalancerUpstream::fromBaragonUpstream).collect(Collectors.toList());
}
Also used : Response(com.ning.http.client.Response) BaragonResponse(com.hubspot.baragon.models.BaragonResponse) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) BaragonServiceState(com.hubspot.baragon.models.BaragonServiceState) Request(com.ning.http.client.Request) SingularityRequest(com.hubspot.singularity.SingularityRequest) BaragonRequest(com.hubspot.baragon.models.BaragonRequest)

Aggregations

BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)21 IOException (java.io.IOException)13 Response (com.ning.http.client.Response)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ExecutionException (java.util.concurrent.ExecutionException)3 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)2 FluentCaseInsensitiveStringsMap (com.ning.http.client.FluentCaseInsensitiveStringsMap)2 Request (com.ning.http.client.Request)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 BoundRequestBuilder (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)2 Response (org.apache.apex.shaded.ning19.com.ning.http.client.Response)2 Cookie (org.apache.apex.shaded.ning19.com.ning.http.client.cookie.Cookie)2 WebSocketUpgradeHandler (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 BaragonRequest (com.hubspot.baragon.models.BaragonRequest)1 BaragonResponse (com.hubspot.baragon.models.BaragonResponse)1 BaragonServiceState (com.hubspot.baragon.models.BaragonServiceState)1