Skip to content

Commit 1d1419b

Browse files
committed
Respect system properties by default
1 parent b78c2ad commit 1d1419b

14 files changed

+46
-146
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ private ExecInterceptorEntry(
201201
private boolean evictIdleConnections;
202202
private TimeValue maxIdleTime;
203203

204-
private boolean systemProperties;
205204
private boolean automaticRetriesDisabled;
206205
private boolean redirectHandlingDisabled;
207206
private boolean cookieManagementDisabled;
@@ -669,13 +668,12 @@ public final H2AsyncClientBuilder setDefaultConnectionConfig(final ConnectionCon
669668
}
670669

671670
/**
672-
* Use system properties when creating and configuring default
673-
* implementations.
671+
* Ignored.
674672
*
675673
* @return this instance.
676674
*/
675+
@Deprecated
677676
public final H2AsyncClientBuilder useSystemProperties() {
678-
this.systemProperties = true;
679677
return this;
680678
}
681679

@@ -789,14 +787,14 @@ public CloseableHttpAsyncClient build() {
789787

790788
final HttpProcessorBuilder b = HttpProcessorBuilder.create();
791789
if (requestInterceptors != null) {
792-
for (final RequestInterceptorEntry entry: requestInterceptors) {
790+
for (final H2AsyncClientBuilder.RequestInterceptorEntry entry: requestInterceptors) {
793791
if (entry.position == RequestInterceptorEntry.Position.FIRST) {
794792
b.addFirst(entry.interceptor);
795793
}
796794
}
797795
}
798796
if (responseInterceptors != null) {
799-
for (final ResponseInterceptorEntry entry: responseInterceptors) {
797+
for (final H2AsyncClientBuilder.ResponseInterceptorEntry entry: responseInterceptors) {
800798
if (entry.position == ResponseInterceptorEntry.Position.FIRST) {
801799
b.addFirst(entry.interceptor);
802800
}
@@ -911,7 +909,7 @@ public CloseableHttpAsyncClient build() {
911909
ioSession -> ioSession.enqueue(new ShutdownCommand(CloseMode.GRACEFUL), Command.Priority.IMMEDIATE));
912910

913911
if (execInterceptors != null) {
914-
for (final ExecInterceptorEntry entry: execInterceptors) {
912+
for (final H2AsyncClientBuilder.ExecInterceptorEntry entry: execInterceptors) {
915913
switch (entry.position) {
916914
case AFTER:
917915
execChainDefinition.addAfter(entry.existing, entry.interceptor, entry.name);
@@ -964,20 +962,12 @@ public CloseableHttpAsyncClient build() {
964962

965963
CredentialsProvider credentialsProviderCopy = this.credentialsProvider;
966964
if (credentialsProviderCopy == null) {
967-
if (systemProperties) {
968-
credentialsProviderCopy = new SystemDefaultCredentialsProvider();
969-
} else {
970-
credentialsProviderCopy = new BasicCredentialsProvider();
971-
}
965+
credentialsProviderCopy = new SystemDefaultCredentialsProvider();
972966
}
973967

974968
TlsStrategy tlsStrategyCopy = this.tlsStrategy;
975969
if (tlsStrategyCopy == null) {
976-
if (systemProperties) {
977-
tlsStrategyCopy = DefaultClientTlsStrategy.createSystemDefault();
978-
} else {
979-
tlsStrategyCopy = DefaultClientTlsStrategy.createDefault();
980-
}
970+
tlsStrategyCopy = DefaultClientTlsStrategy.createDefault();
981971
}
982972

983973
final MultihomeConnectionInitiator connectionInitiator = new MultihomeConnectionInitiator(ioReactor, dnsResolver);

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClientBuilder.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@
6565
import org.apache.hc.client5.http.impl.DefaultUserTokenHandler;
6666
import org.apache.hc.client5.http.impl.IdleConnectionEvictor;
6767
import org.apache.hc.client5.http.impl.NoopUserTokenHandler;
68-
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
6968
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
7069
import org.apache.hc.client5.http.impl.auth.BearerSchemeFactory;
7170
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
7271
import org.apache.hc.client5.http.impl.auth.ScramSchemeFactory;
7372
import org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider;
7473
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
7574
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
76-
import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
7775
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
7876
import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
7977
import org.apache.hc.client5.http.protocol.H2RequestPriority;
@@ -252,7 +250,6 @@ private ExecInterceptorEntry(
252250
private boolean evictIdleConnections;
253251
private TimeValue maxIdleTime;
254252

255-
private boolean systemProperties;
256253
private boolean automaticRetriesDisabled;
257254
private boolean redirectHandlingDisabled;
258255
private boolean cookieManagementDisabled;
@@ -776,13 +773,12 @@ public final HttpAsyncClientBuilder setDefaultRequestConfig(final RequestConfig
776773
}
777774

778775
/**
779-
* Use system properties when creating and configuring default
780-
* implementations.
776+
* Ignored.
781777
*
782778
* @return this instance.
783779
*/
780+
@Deprecated
784781
public final HttpAsyncClientBuilder useSystemProperties() {
785-
this.systemProperties = true;
786782
return this;
787783
}
788784

@@ -1010,11 +1006,7 @@ public AsyncClientConnectionManager getConnManager() {
10101006
public CloseableHttpAsyncClient build() {
10111007
AsyncClientConnectionManager connManagerCopy = this.connManager;
10121008
if (connManagerCopy == null) {
1013-
final PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder.create();
1014-
if (systemProperties) {
1015-
connectionManagerBuilder.useSystemProperties();
1016-
}
1017-
connManagerCopy = connectionManagerBuilder.build();
1009+
connManagerCopy = PoolingAsyncClientConnectionManagerBuilder.create().build();
10181010
}
10191011

10201012
ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy;
@@ -1166,11 +1158,9 @@ public CloseableHttpAsyncClient build() {
11661158
routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
11671159
} else if (this.proxySelector != null) {
11681160
routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, this.proxySelector);
1169-
} else if (systemProperties) {
1161+
} else {
11701162
final ProxySelector defaultProxySelector = ProxySelector.getDefault();
11711163
routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, defaultProxySelector);
1172-
} else {
1173-
routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
11741164
}
11751165
}
11761166

@@ -1276,11 +1266,7 @@ public CloseableHttpAsyncClient build() {
12761266

12771267
CredentialsProvider credentialsProviderCopy = this.credentialsProvider;
12781268
if (credentialsProviderCopy == null) {
1279-
if (systemProperties) {
1280-
credentialsProviderCopy = new SystemDefaultCredentialsProvider();
1281-
} else {
1282-
credentialsProviderCopy = new BasicCredentialsProvider();
1283-
}
1269+
credentialsProviderCopy = new SystemDefaultCredentialsProvider();
12841270
}
12851271

12861272
return new InternalHttpAsyncClient(

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ public static CloseableHttpAsyncClient createDefault() {
9090
* Creates {@link CloseableHttpAsyncClient} instance with default
9191
* configuration and system properties.
9292
*/
93+
@Deprecated
9394
public static CloseableHttpAsyncClient createSystem() {
94-
return HttpAsyncClientBuilder.create().useSystemProperties().build();
95+
return HttpAsyncClientBuilder.create().build();
9596
}
9697

9798
/**
@@ -112,11 +113,11 @@ public static CloseableHttpAsyncClient createHttp2Default() {
112113
}
113114

114115
/**
115-
* Creates HTTP/2 {@link CloseableHttpAsyncClient} instance with default configuration and
116-
* system properties optimized for HTTP/2 protocol and message multiplexing.
116+
* Creates HTTP/2 {@link CloseableHttpAsyncClient} instance with default configuration.
117117
*/
118+
@Deprecated
118119
public static CloseableHttpAsyncClient createHttp2System() {
119-
return H2AsyncClientBuilder.create().useSystemProperties().build();
120+
return createHttp2Default();
120121
}
121122

122123
private static HttpProcessor createMinimalProtocolProcessor() {

httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClientBuilder.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@
6767
import org.apache.hc.client5.http.impl.DefaultUserTokenHandler;
6868
import org.apache.hc.client5.http.impl.IdleConnectionEvictor;
6969
import org.apache.hc.client5.http.impl.NoopUserTokenHandler;
70-
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
7170
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
7271
import org.apache.hc.client5.http.impl.auth.BearerSchemeFactory;
7372
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
7473
import org.apache.hc.client5.http.impl.auth.ScramSchemeFactory;
7574
import org.apache.hc.client5.http.impl.auth.SystemDefaultCredentialsProvider;
7675
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
7776
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
78-
import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner;
7977
import org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner;
8078
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
8179
import org.apache.hc.client5.http.protocol.HttpClientContext;
@@ -225,7 +223,6 @@ private ExecInterceptorEntry(
225223
private boolean evictIdleConnections;
226224
private TimeValue maxIdleTime;
227225

228-
private boolean systemProperties;
229226
private boolean redirectHandlingDisabled;
230227
private boolean automaticRetriesDisabled;
231228
private boolean contentCompressionDisabled;
@@ -732,13 +729,12 @@ public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig confi
732729
}
733730

734731
/**
735-
* Use system properties when creating and configuring default
736-
* implementations.
732+
* Ignored.
737733
*
738734
* @return this instance.
739735
*/
736+
@Deprecated
740737
public final HttpClientBuilder useSystemProperties() {
741-
this.systemProperties = true;
742738
return this;
743739
}
744740

@@ -882,11 +878,7 @@ public CloseableHttpClient build() {
882878
}
883879
HttpClientConnectionManager connManagerCopy = this.connManager;
884880
if (connManagerCopy == null) {
885-
final PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create();
886-
if (systemProperties) {
887-
connectionManagerBuilder.useSystemProperties();
888-
}
889-
connManagerCopy = connectionManagerBuilder.build();
881+
connManagerCopy = PoolingHttpClientConnectionManagerBuilder.create().build();
890882
}
891883
ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
892884
if (reuseStrategyCopy == null) {
@@ -1039,11 +1031,9 @@ public CloseableHttpClient build() {
10391031
routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
10401032
} else if (this.proxySelector != null) {
10411033
routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, this.proxySelector);
1042-
} else if (systemProperties) {
1034+
} else {
10431035
final ProxySelector defaultProxySelector = ProxySelector.getDefault();
10441036
routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, defaultProxySelector);
1045-
} else {
1046-
routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
10471037
}
10481038
}
10491039

@@ -1118,11 +1108,7 @@ public CloseableHttpClient build() {
11181108

11191109
CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
11201110
if (defaultCredentialsProvider == null) {
1121-
if (systemProperties) {
1122-
defaultCredentialsProvider = new SystemDefaultCredentialsProvider();
1123-
} else {
1124-
defaultCredentialsProvider = new BasicCredentialsProvider();
1125-
}
1111+
defaultCredentialsProvider = new SystemDefaultCredentialsProvider();
11261112
}
11271113

11281114
List<Closeable> closeablesCopy = closeables != null ? new ArrayList<>(closeables) : null;

httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClients.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ public static CloseableHttpClient createDefault() {
5757
return HttpClientBuilder.create().build();
5858
}
5959

60-
/**
61-
* Creates {@link CloseableHttpClient} instance with default
62-
* configuration based on system properties.
63-
*/
60+
@Deprecated
6461
public static CloseableHttpClient createSystem() {
65-
return HttpClientBuilder.create().useSystemProperties().build();
62+
return createDefault();
6663
}
6764

6865
/**

httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public class PoolingHttpClientConnectionManagerBuilder {
8888
private Resolver<HttpRoute, ConnectionConfig> connectionConfigResolver;
8989
private Resolver<HttpHost, TlsConfig> tlsConfigResolver;
9090

91-
private boolean systemProperties;
92-
9391
private int maxConnTotal;
9492
private int maxConnPerRoute;
9593

@@ -311,13 +309,10 @@ public final PoolingHttpClientConnectionManagerBuilder setValidateAfterInactivit
311309
}
312310

313311
/**
314-
* Use system properties when creating and configuring default
315-
* implementations.
316-
*
317-
* @return this instance.
312+
* Ignored.
318313
*/
314+
@Deprecated
319315
public final PoolingHttpClientConnectionManagerBuilder useSystemProperties() {
320-
this.systemProperties = true;
321316
return this;
322317
}
323318

@@ -358,11 +353,7 @@ public PoolingHttpClientConnectionManager build() {
358353
if (tlsSocketStrategy != null) {
359354
tlsSocketStrategyCopy = tlsSocketStrategy;
360355
} else {
361-
if (systemProperties) {
362-
tlsSocketStrategyCopy = DefaultClientTlsStrategy.createSystemDefault();
363-
} else {
364-
tlsSocketStrategyCopy = DefaultClientTlsStrategy.createDefault();
365-
}
356+
tlsSocketStrategyCopy = DefaultClientTlsStrategy.createDefault();
366357
}
367358

368359
final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(

httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public class PoolingAsyncClientConnectionManagerBuilder {
8080
private PoolConcurrencyPolicy poolConcurrencyPolicy;
8181
private PoolReusePolicy poolReusePolicy;
8282

83-
private boolean systemProperties;
84-
8583
private int maxConnTotal;
8684
private int maxConnPerRoute;
8785

@@ -259,13 +257,12 @@ public final PoolingAsyncClientConnectionManagerBuilder setValidateAfterInactivi
259257
}
260258

261259
/**
262-
* Use system properties when creating and configuring default
263-
* implementations.
260+
* Ignored.
264261
*
265262
* @return this instance.
266263
*/
264+
@Deprecated
267265
public final PoolingAsyncClientConnectionManagerBuilder useSystemProperties() {
268-
this.systemProperties = true;
269266
return this;
270267
}
271268

@@ -306,17 +303,9 @@ public PoolingAsyncClientConnectionManager build() {
306303
tlsStrategyCopy = tlsStrategy;
307304
} else {
308305
if (ReflectionUtils.determineJRELevel() <= 8 && ConscryptClientTlsStrategy.isSupported()) {
309-
if (systemProperties) {
310-
tlsStrategyCopy = ConscryptClientTlsStrategy.getSystemDefault();
311-
} else {
312-
tlsStrategyCopy = ConscryptClientTlsStrategy.getDefault();
313-
}
306+
tlsStrategyCopy = ConscryptClientTlsStrategy.getDefault();
314307
} else {
315-
if (systemProperties) {
316-
tlsStrategyCopy = DefaultClientTlsStrategy.createSystemDefault();
317-
} else {
318-
tlsStrategyCopy = DefaultClientTlsStrategy.createDefault();
319-
}
308+
tlsStrategyCopy = DefaultClientTlsStrategy.createDefault();
320309
}
321310
}
322311
final PoolingAsyncClientConnectionManager poolingmgr = new PoolingAsyncClientConnectionManager(

httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ClientTlsStrategyBuilder.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ public static ClientTlsStrategyBuilder create() {
7474
private SSLBufferMode sslBufferMode;
7575
private HostnameVerificationPolicy hostnameVerificationPolicy;
7676
private HostnameVerifier hostnameVerifier;
77-
private boolean systemProperties;
7877

7978
/**
8079
* Sets {@link SSLContext} instance.
@@ -171,13 +170,10 @@ public ClientTlsStrategyBuilder setTlsDetailsFactory(final Factory<SSLEngine, Tl
171170
}
172171

173172
/**
174-
* Use system properties when creating and configuring default
175-
* implementations.
176-
*
177-
* @return this instance.
173+
* Ignored.
178174
*/
175+
@Deprecated
179176
public final ClientTlsStrategyBuilder useSystemProperties() {
180-
this.systemProperties = true;
181177
return this;
182178
}
183179

@@ -204,12 +200,7 @@ public TlsSocketStrategy buildClassic() {
204200
}
205201

206202
private DefaultClientTlsStrategy buildImpl() {
207-
final SSLContext sslContextCopy;
208-
if (sslContext != null) {
209-
sslContextCopy = sslContext;
210-
} else {
211-
sslContextCopy = systemProperties ? SSLContexts.createSystemDefault() : SSLContexts.createDefault();
212-
}
203+
final SSLContext sslContextCopy = sslContext != null ? sslContext : SSLContexts.createDefault();
213204
final HostnameVerificationPolicy hostnameVerificationPolicyCopy = hostnameVerificationPolicy != null ? hostnameVerificationPolicy :
214205
(hostnameVerifier == null ? HostnameVerificationPolicy.BUILTIN : HostnameVerificationPolicy.BOTH);
215206
return new DefaultClientTlsStrategy(

0 commit comments

Comments
 (0)