Digipost HTTP Client Builder
A tiny library for building instances of Apache HttpClient configured with sensible defaults.
Usage
Here are some common use cases to quickly get you started.
Client with sensible defaults:
CloseableHttpClient client = HttpClientFactory.createDefault();
Custom ssl context
PoolingHttpClientConnectionManager connectionManager = HttpClientConnectionManagerFactory
.createDefaultBuilder()
.setSSLSocketFactory(
SSLConnectionSocketFactoryBuilder.create()
.setSslContext(getSslContext())
.setTlsVersions(TLS.V_1_3)
.build()
)
.build();
CloseableHttpClient client = HttpClientFactory.create(connectionManager);
Disable connection monitor
The connection monitor evicts idle and expired connections. It is by default started when the client is built.
It can be disabled by the following code:
CloseableHttpClient client = HttpClientFactory.create(HttpClientSettings.DEFAULT.connectionEvictionPolicy(ConnectionEvictionPolicy.NONE));
PS: If connection monitor is not disabled, and a new connection manager is set after the client builder has been created (i.e clientBuilder.setConnectionManager(other)
), the 'old' connection monitor will still run and monitor the old connection manager.