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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
Aggregations