Search in sources :

Example 6 with RegistryBuilder

use of org.apache.hc.core5.http.config.RegistryBuilder in project geo-platform by geosdi.

the class GPServerProxy method createClientConnectionManager.

/**
 * @return {@link HttpClientConnectionManager}
 */
HttpClientConnectionManager createClientConnectionManager() {
    try {
        SSLContextBuilder builder = new SSLContextBuilder();
        builder.loadTrustMaterial(null, (chain, authType) -> true);
        SSLConnectionSocketFactory sslSF = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
        PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSF).build());
        cm.setMaxTotal(10);
        cm.setDefaultMaxPerRoute(3);
        return cm;
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IllegalStateException(ex);
    }
}
Also used : ConnectionSocketFactory(org.apache.hc.client5.http.socket.ConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.hc.client5.http.socket.PlainConnectionSocketFactory) SSLContextBuilder(org.apache.hc.core5.ssl.SSLContextBuilder) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) ServletException(javax.servlet.ServletException) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Example 7 with RegistryBuilder

use of org.apache.hc.core5.http.config.RegistryBuilder in project commercetools-jvm-sdk by commercetools.

the class IntegrationTest method createNoSSLClient.

private static CloseableHttpAsyncClient createNoSSLClient() {
    final TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
    try {
        final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
        Lookup<TlsStrategy> socketFactoryRegistry = RegistryBuilder.<TlsStrategy>create().register("https", new DefaultClientTlsStrategy(sslContext, NoopHostnameVerifier.INSTANCE)).build();
        PoolingAsyncClientConnectionManager connManager = new PoolingAsyncClientConnectionManager(socketFactoryRegistry);
        return HttpAsyncClients.createMinimal(connManager);
    } catch (Exception e) {
        logger.error("Could not create SSLContext", e);
        return null;
    }
}
Also used : TlsStrategy(org.apache.hc.core5.http.nio.ssl.TlsStrategy) DefaultClientTlsStrategy(org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy) DefaultClientTlsStrategy(org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy) TrustStrategy(org.apache.hc.core5.ssl.TrustStrategy) SSLContext(javax.net.ssl.SSLContext) PoolingAsyncClientConnectionManager(org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)5 ConnectionSocketFactory (org.apache.hc.client5.http.socket.ConnectionSocketFactory)5 PlainConnectionSocketFactory (org.apache.hc.client5.http.socket.PlainConnectionSocketFactory)4 SSLConnectionSocketFactory (org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory)4 IOException (java.io.IOException)3 SSLContext (javax.net.ssl.SSLContext)3 SSLContextBuilder (org.apache.hc.core5.ssl.SSLContextBuilder)3 HttpGet (org.apache.hc.client5.http.classic.methods.HttpGet)2 BasicCookieStore (org.apache.hc.client5.http.cookie.BasicCookieStore)2 CloseableHttpClient (org.apache.hc.client5.http.impl.classic.CloseableHttpClient)2 CloseableHttpResponse (org.apache.hc.client5.http.impl.classic.CloseableHttpResponse)2 PoolingAsyncClientConnectionManager (org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager)2 HttpClientContext (org.apache.hc.client5.http.protocol.HttpClientContext)2 DefaultClientTlsStrategy (org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy)2 HttpHost (org.apache.hc.core5.http.HttpHost)2 TimeoutException (com.codeborne.selenide.ex.TimeoutException)1 FileNotFoundException (java.io.FileNotFoundException)1 UncheckedIOException (java.io.UncheckedIOException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1