TransportAuthenticationContext context = new TransportAuthenticationContext();
context.addAttribute("endpoint", endpoint);
credentialsProvider = authenticationProvider.authenticate(credentialsProvider, context);
final CloseableHttpAsyncClient httpClient = HttpAsyncClients.custom()
.setDefaultCredentialsProvider(credentialsProvider)
.build();
HttpGet get = new HttpGet(endpoint.getUri());
HttpHost target = URIUtils.extractHost(get.getURI());
BasicAsyncRequestProducer basicAsyncRequestProducer = new BasicAsyncRequestProducer(target, get);
httpClient.start();
try {
log.debug("sending request");
Future<HttpResponse> futureResponse = httpClient.execute(
basicAsyncRequestProducer,
new SSEResponseConsumer(requestHandler), new FutureCallback<HttpResponse>() {
public void completed(HttpResponse httpResponse) {
log.debug("response received {}", httpResponse);
}
public void failed(Exception e) {
log.warn("failed request {}", e.toString());
}
public void cancelled() {
log.warn("request cancelled");
}
});
requests.put(requestHandler.toString(), futureResponse);
futureResponse.get();
} catch (Exception e) {
log.warn("cannot communicate with {}", endpoint, e);
}
httpClient.close();
log.debug("request finished");
} catch (Exception e) {
log.error("cannot run event based replication {}", e);
}
}