From 679991ae33ce8880d7a1739c5a10ab1b2146d31a Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 8 Jan 2024 14:24:36 +0100 Subject: [PATCH] HTTPCLIENT-2315: client builders fails to apply system properties to the default connection manager --- .../hc/client5/http/impl/async/HttpAsyncClientBuilder.java | 6 +++++- .../hc/client5/http/impl/classic/HttpClientBuilder.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java index 346d315c8e..a3c45dc0fa 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java @@ -779,7 +779,11 @@ protected void addCloseable(final Closeable closeable) { public CloseableHttpAsyncClient build() { AsyncClientConnectionManager connManagerCopy = this.connManager; if (connManagerCopy == null) { - connManagerCopy = PoolingAsyncClientConnectionManagerBuilder.create().build(); + final PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder.create(); + if (systemProperties) { + connectionManagerBuilder.useSystemProperties(); + } + connManagerCopy = connectionManagerBuilder.build(); } ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java index 8711f43150..c040bf84d7 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java @@ -749,7 +749,11 @@ public CloseableHttpClient build() { } HttpClientConnectionManager connManagerCopy = this.connManager; if (connManagerCopy == null) { - connManagerCopy = PoolingHttpClientConnectionManagerBuilder.create().build(); + final PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create(); + if (systemProperties) { + connectionManagerBuilder.useSystemProperties(); + } + connManagerCopy = connectionManagerBuilder.build(); } ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy; if (reuseStrategyCopy == null) {