use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.
the class LoadBalancerClientImpl method cancel.
@Override
public SingularityLoadBalancerUpdate cancel(LoadBalancerRequestId loadBalancerRequestId) {
final String uri = getLoadBalancerUri(loadBalancerRequestId);
final BoundRequestBuilder requestBuilder = httpClient.prepareDelete(uri);
if (loadBalancerQueryParams.isPresent()) {
addAllQueryParams(requestBuilder, loadBalancerQueryParams.get());
}
return sendRequestWrapper(loadBalancerRequestId, LoadBalancerMethod.CANCEL, requestBuilder.build(), BaragonRequestState.UNKNOWN);
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project Singularity by HubSpot.
the class SingularityWebhookSender method executeWebhookAsync.
// TODO handle retries, errors.
private <T> CompletableFuture<Response> executeWebhookAsync(SingularityWebhook webhook, Object payload, AbstractSingularityWebhookAsyncHandler<T> handler) {
LOG.trace("Sending {} to {}", payload, webhook.getUri());
BoundRequestBuilder postRequest = http.preparePost(webhook.getUri());
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
try {
postRequest.setBody(objectMapper.writeValueAsBytes(payload));
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
CompletableFuture<Response> webhookFuture = new CompletableFuture<>();
try {
handler.setCompletableFuture(webhookFuture);
postRequest.execute(handler);
} catch (IOException e) {
LOG.warn("Couldn't execute webhook to {}", webhook.getUri(), e);
if (handler.shouldDeleteUpdateDueToQueueAboveCapacity()) {
handler.deleteWebhookUpdate();
}
webhookFuture.completeExceptionally(e);
}
return webhookFuture;
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project traccar by traccar.
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 com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project apex-core by apache.
the class PubSubWebSocketClient method openConnection.
/**
* <p>openConnection.</p>
*
* @param timeoutMillis
* @throws IOException
* @throws ExecutionException
* @throws InterruptedException
* @throws TimeoutException
*/
public void openConnection(long timeoutMillis) throws IOException, ExecutionException, InterruptedException, TimeoutException {
throwable.set(null);
List<Cookie> cookies = null;
if (loginUrl != null && userName != null && password != null) {
// get the session key first before attempting web socket
JSONObject json = new JSONObject();
try {
json.put("userName", userName);
json.put("password", password);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
Response response = client.preparePost(loginUrl).setHeader("Content-Type", "application/json").setBody(json.toString()).execute().get();
cookies = response.getCookies();
}
BoundRequestBuilder brb = client.prepareGet(uri.toString());
if (cookies != null) {
for (Cookie cookie : cookies) {
brb.addCookie(cookie);
}
}
connection = brb.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new PubSubWebSocket()).build()).get(timeoutMillis, TimeUnit.MILLISECONDS);
}
use of com.ning.http.client.AsyncHttpClient.BoundRequestBuilder in project apex-core by apache.
the class PubSubWebSocketClient method openConnectionAsync.
public void openConnectionAsync() throws IOException {
throwable.set(null);
if (loginUrl != null && userName != null && password != null) {
// get the session key first before attempting web socket
JSONObject json = new JSONObject();
try {
json.put("userName", userName);
json.put("password", password);
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
client.preparePost(loginUrl).setHeader("Content-Type", "application/json").setBody(json.toString()).execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
List<Cookie> cookies = response.getCookies();
BoundRequestBuilder brb = client.prepareGet(uri.toString());
if (cookies != null) {
for (Cookie cookie : cookies) {
brb.addCookie(cookie);
}
}
connection = brb.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new PubSubWebSocket()).build()).get();
return response;
}
});
} else {
final PubSubWebSocket webSocket = new PubSubWebSocket() {
@Override
public void onOpen(WebSocket ws) {
connection = ws;
super.onOpen(ws);
}
};
client.prepareGet(uri.toString()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(webSocket).build());
}
}
Aggregations