On 2/15/16 12:52 PM, Matt Chambers wrote:
> Hi Oleg,
>
> Well, I finally got it working.
>
> Apparently you can’t use PoolingClientConnectionManager with a custom SSL 
> context without registering the SSLConnectionSocket factory, like so:
>
>         Registry<ConnectionSocketFactory> socketFactoryRegistry = 
> RegistryBuilder
>                 .<ConnectionSocketFactory> create().register("https", factory)
>                 .build();
>
>         PoolingHttpClientConnectionManager cm = new 
> PoolingHttpClientConnectionManager(socketFactoryRegistry);
>
>         this.client = HttpClients.custom()
>                 .setConnectionManager(cm)
>                 .build();
>

Ah, ok.  Just wanted to note a couple of things:  There are indeed
numerous properties on the HttpClientBuilder (used by HttpClients) which
are overridden and not used if you specify a non-default connection
manager, including the SSL socket factory.  I believe these are all
documented in Javadoc on each method.

Also, in your original example:

this.client = HttpClients.custom()
        .setConnectionManager(new PoolingHttpClientConnectionManager())
        .setSSLSocketFactory(new SSLConnectionSocketFactory(SSLContexts.custom()
                .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                .build()))
        .setSSLHostnameVerifier(new NoopHostnameVerifier())
        .build();


since PoolingHttpClientConnectionManager is actually the builder
internal default, if you simply omitted the call to explicitly create
and set it, the above would have worked.  You'd really only need to
supply a connection manager explicitly like that if you wanted to set
other properties that the builder doesn't support, and/or use a
different connection manager impl.


--Brent

Reply via email to