use of org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient in project feign by OpenFeign.
the class AsyncApacheHttp5Client method createStartedClient.
private static CloseableHttpAsyncClient createStartedClient() {
final CloseableHttpAsyncClient client = HttpAsyncClients.custom().build();
client.start();
return client;
}
use of org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient in project cxf by apache.
the class AsyncHTTPConduitFactory method restartReactor.
private void restartReactor() {
CloseableHttpAsyncClient client2 = client;
resetVars();
shutdown(client2);
}
use of org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient in project sslcontext-kickstart by Hakky54.
the class SSLFactoryIT method executeHttpsRequestWithMutualAuthenticationForAsyncClient.
@Test
@Tag("it-with-badssl.com")
void executeHttpsRequestWithMutualAuthenticationForAsyncClient() throws IOException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
LogCaptor logCaptor = LogCaptor.forName("nl.altindag.ssl");
SSLFactory sslFactory = SSLFactory.builder().withIdentityMaterial("keystore/badssl-identity.p12", "badssl.com".toCharArray()).withTrustMaterial("keystore/badssl-truststore.p12", "badssl.com".toCharArray()).withTrustMaterial(// Adding additional trust material forces usage of CompositeX509ExtendedTrustManager and verbose logging
KeyStoreUtils.createKeyStore()).build();
PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder.create().setTlsStrategy(Apache5SslUtils.toTlsStrategy(sslFactory)).build();
CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.custom().setConnectionManager(connectionManager).build();
httpAsyncClient.start();
SimpleHttpResponse response = httpAsyncClient.execute(new BasicRequestProducer(Method.GET, new URI("https://client.badssl.com/")), SimpleResponseConsumer.create(), null, null, null).get(10, TimeUnit.SECONDS);
logCaptor.close();
int statusCode = response.getCode();
if (statusCode == 400) {
fail("Certificate may have expired and needs to be updated");
} else {
assertThat(statusCode).isEqualTo(200);
assertThat(logCaptor.getLogs()).contains("Received the following server certificate: [CN=*.badssl.com, O=Lucas Garron Torres, L=Walnut Creek, ST=California, C=US]");
}
}
use of org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient in project mercury by yellow013.
the class AsyncClientConnectionEviction method main.
public static void main(final String[] args) throws Exception {
final IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(5)).build();
final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setIOReactorConfig(ioReactorConfig).evictExpiredConnections().evictIdleConnections(TimeValue.ofSeconds(10)).build();
client.start();
final SimpleHttpRequest request = SimpleRequestBuilder.get().setHttpHost(new HttpHost("httpbin.org")).setPath("/").build();
System.out.println("Executing request " + request);
final Future<SimpleHttpResponse> future1 = client.execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(final SimpleHttpResponse response) {
System.out.println(request + "->" + new StatusLine(response));
System.out.println(response.getBody());
}
@Override
public void failed(final Exception ex) {
System.out.println(request + "->" + ex);
}
@Override
public void cancelled() {
System.out.println(request + " cancelled");
}
});
future1.get();
Thread.sleep(TimeUnit.SECONDS.toMillis(30));
// Previous connection should get evicted from the pool by now
final Future<SimpleHttpResponse> future2 = client.execute(request, new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(final SimpleHttpResponse response) {
System.out.println(request + "->" + new StatusLine(response));
System.out.println(response.getBody());
}
@Override
public void failed(final Exception ex) {
System.out.println(request + "->" + ex);
}
@Override
public void cancelled() {
System.out.println(request + " cancelled");
}
});
future2.get();
System.out.println("Shutting down");
client.close(CloseMode.GRACEFUL);
}
use of org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient in project mercury by yellow013.
the class AsyncClientCustomSSL method main.
public static void main(final String[] args) throws Exception {
// Trust standard CA and those trusted by our custom strategy
final SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new TrustStrategy() {
@Override
public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
final X509Certificate cert = chain[0];
return "CN=httpbin.org".equalsIgnoreCase(cert.getSubjectDN().getName());
}
}).build();
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create().setSslContext(sslcontext).build();
final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create().setTlsStrategy(tlsStrategy).build();
try (final CloseableHttpAsyncClient client = HttpAsyncClients.custom().setConnectionManager(cm).build()) {
client.start();
final HttpHost target = new HttpHost("https", "httpbin.org");
final HttpClientContext clientContext = HttpClientContext.create();
final SimpleHttpRequest request = SimpleRequestBuilder.get().setHttpHost(target).setPath("/").build();
System.out.println("Executing request " + request);
final Future<SimpleHttpResponse> future = client.execute(SimpleRequestProducer.create(request), SimpleResponseConsumer.create(), clientContext, new FutureCallback<SimpleHttpResponse>() {
@Override
public void completed(final SimpleHttpResponse response) {
System.out.println(request + "->" + new StatusLine(response));
final SSLSession sslSession = clientContext.getSSLSession();
if (sslSession != null) {
System.out.println("SSL protocol " + sslSession.getProtocol());
System.out.println("SSL cipher suite " + sslSession.getCipherSuite());
}
System.out.println(response.getBody());
}
@Override
public void failed(final Exception ex) {
System.out.println(request + "->" + ex);
}
@Override
public void cancelled() {
System.out.println(request + " cancelled");
}
});
future.get();
System.out.println("Shutting down");
client.close(CloseMode.GRACEFUL);
}
}
Aggregations