Есть несколько точек плагинов.Пользовательский код может вводиться либо на уровне фабрики сокетов, либо на уровне оператора соединения.
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
new DefaultHttpClientConnectionOperator(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory() {
@Override
public Socket connectSocket(
int connectTimeout,
Socket socket,
HttpHost host,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
HttpContext context) throws IOException {
return super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
}
})
.register("https", new SSLConnectionSocketFactory(SSLContexts.createSystemDefault()) {
@Override
public Socket connectSocket(
int connectTimeout,
Socket socket,
HttpHost host,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
HttpContext context) throws IOException {
return super.connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
}
})
.build(),
DefaultSchemePortResolver.INSTANCE,
SystemDefaultDnsResolver.INSTANCE) {
@Override
public void connect(
ManagedHttpClientConnection conn,
HttpHost host,
InetSocketAddress localAddress,
int connectTimeout,
SocketConfig socketConfig,
HttpContext context) throws IOException {
super.connect(conn, host, localAddress, connectTimeout, socketConfig, context);
}
},
ManagedHttpClientConnectionFactory.INSTANCE,
0L, TimeUnit.MILLISECONDS);
CloseableHttpClient client = HttpClients.custom()
.setConnectionManager(cm)
.build();