Search in sources :

Example 11 with BoundRequestBuilder

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));
    }
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 12 with BoundRequestBuilder

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);
        }
    });
}
Also used : Response(com.ning.http.client.Response) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) TimeoutException(org.jboss.netty.handler.timeout.TimeoutException) JAXBException(javax.xml.bind.JAXBException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 13 with BoundRequestBuilder

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();
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) FluentCaseInsensitiveStringsMap(com.ning.http.client.FluentCaseInsensitiveStringsMap)

Example 14 with BoundRequestBuilder

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));
    }
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) IOException(java.io.IOException)

Example 15 with BoundRequestBuilder

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);
}
Also used : BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)

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