use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.
the class BaragonLoadBalancerClientImpl method sendLoadBalancerRequest.
private SingularityLoadBalancerUpdate sendLoadBalancerRequest(LoadBalancerRequestId loadBalancerRequestId, BaragonRequest loadBalancerRequest, LoadBalancerMethod method) {
try {
LOG.trace("Preparing to send request {}", loadBalancerRequest);
final BoundRequestBuilder requestBuilder = httpClient.preparePost(loadBalancerUri).addHeader(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON).setBody(objectMapper.writeValueAsBytes(loadBalancerRequest));
loadBalancerQueryParams.ifPresent(stringStringMap -> addAllQueryParams(requestBuilder, stringStringMap));
return sendRequestWrapper(loadBalancerRequestId, method, requestBuilder.build(), BaragonRequestState.FAILED);
} catch (IOException e) {
return new SingularityLoadBalancerUpdate(LoadBalancerRequestState.UNKNOWN, loadBalancerRequestId, Optional.of(e.getMessage()), System.currentTimeMillis(), method, Optional.of(loadBalancerUri));
}
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project openhab1-addons by openhab.
the class PlexConnector method internalSendCommand.
private void internalSendCommand(String machineIdentifier, String url) throws IOException {
logger.debug("Calling url {}", url);
BoundRequestBuilder builder = client.prepareGet(url).setHeaders(getDefaultHeaders()).setHeader("X-Plex-Target-Client-Identifier", machineIdentifier);
builder.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
if (response.getStatusCode() != 200) {
logger.error("Error while sending command to Plex: {}\r\n{}", response.getStatusText(), response.getResponseBody());
}
return response;
}
@Override
public void onThrowable(Throwable t) {
logger.error("Error sending command to Plex", t);
}
});
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project traccar by tananaev.
the class EventForwarder method forwardEvent.
public final void forwardEvent(Event event, Position position, Set<Long> users) {
BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);
requestBuilder.setBodyEncoding(StandardCharsets.UTF_8.name());
requestBuilder.addHeader("Content-Type", getContentType());
if (header != null && !header.isEmpty()) {
FluentCaseInsensitiveStringsMap params = new FluentCaseInsensitiveStringsMap();
params.putAll(splitIntoKeyValues(header, ":"));
requestBuilder.setHeaders(params);
}
setContent(event, position, users, requestBuilder);
requestBuilder.execute();
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.
the class LoadBalancerClientImpl method sendBaragonRequest.
private SingularityLoadBalancerUpdate sendBaragonRequest(LoadBalancerRequestId loadBalancerRequestId, BaragonRequest loadBalancerRequest, LoadBalancerMethod method) {
try {
LOG.trace("Preparing to send request {}", loadBalancerRequest);
final BoundRequestBuilder requestBuilder = httpClient.preparePost(loadBalancerUri).addHeader(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON).setBody(objectMapper.writeValueAsBytes(loadBalancerRequest));
if (loadBalancerQueryParams.isPresent()) {
addAllQueryParams(requestBuilder, loadBalancerQueryParams.get());
}
return sendRequestWrapper(loadBalancerRequestId, method, requestBuilder.build(), BaragonRequestState.FAILED);
} catch (IOException e) {
return new SingularityLoadBalancerUpdate(BaragonRequestState.UNKNOWN, loadBalancerRequestId, Optional.of(e.getMessage()), System.currentTimeMillis(), method, Optional.of(loadBalancerUri));
}
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.
the class LoadBalancerClientImpl method getState.
@Override
public SingularityLoadBalancerUpdate getState(LoadBalancerRequestId loadBalancerRequestId) {
final String uri = getLoadBalancerUri(loadBalancerRequestId);
final BoundRequestBuilder requestBuilder = httpClient.prepareGet(uri);
if (loadBalancerQueryParams.isPresent()) {
addAllQueryParams(requestBuilder, loadBalancerQueryParams.get());
}
return sendRequestWrapper(loadBalancerRequestId, LoadBalancerMethod.CHECK_STATE, requestBuilder.build(), BaragonRequestState.UNKNOWN);
}
Aggregations