From 554d612b892ca894a246d1cbd504f8324612f80b Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 20 Jan 2026 20:22:52 +0100 Subject: [PATCH] HTTPCLIENT-2381: use system properties as defaults in builder classes --- .../http/impl/async/H2AsyncClientBuilder.java | 35 ++++++++-------- .../impl/async/HttpAsyncClientBuilder.java | 35 ++++++++++------ .../http/impl/async/HttpAsyncClients.java | 22 ++++++++-- .../http/impl/classic/HttpClientBuilder.java | 40 ++++++++++++------- .../http/impl/classic/HttpClients.java | 18 ++++++++- .../io/BasicHttpClientConnectionManager.java | 2 +- .../PoolingHttpClientConnectionManager.java | 2 +- ...ingHttpClientConnectionManagerBuilder.java | 25 +++++++----- .../PoolingAsyncClientConnectionManager.java | 2 +- ...ngAsyncClientConnectionManagerBuilder.java | 31 +++++++------- .../http/ssl/ClientTlsStrategyBuilder.java | 21 +++++++--- .../http/ssl/ConscryptClientTlsStrategy.java | 21 ++++++++++ .../http/ssl/DefaultClientTlsStrategy.java | 19 +++++++++ .../SSLConnectionSocketFactoryBuilder.java | 3 +- .../AsyncClientDeflateCompressionExample.java | 2 +- .../AsyncClientGzipCompressionExample.java | 2 +- .../AsyncClientGzipDecompressionExample.java | 5 +-- ...syncClientInflateDecompressionExample.java | 2 +- .../client5/http/examples/AsyncClientSNI.java | 2 +- .../AsyncClientServerBrotliRoundTrip.java | 2 +- .../AsyncClientServerZstdExample.java | 4 +- .../AsyncClientZstdCompressionExample.java | 2 +- ...ncPreemptiveBasicClientAuthentication.java | 2 +- .../http/examples/ClientAbortMethod.java | 2 +- .../http/examples/ClientChunkEncodedPost.java | 2 +- .../http/examples/ClientClassicOverAsync.java | 2 +- .../examples/ClientConnectionRelease.java | 2 +- .../http/examples/ClientCustomContext.java | 2 +- .../examples/ClientMultipartFormPost.java | 2 +- .../ClientPreemptiveBasicAuthentication.java | 2 +- .../ClientPreemptiveDigestAuthentication.java | 2 +- .../examples/ClientRemoteEndpointDetails.java | 2 +- .../examples/ClientResponseProcessing.java | 2 +- .../hc/client5/http/examples/ClientSNI.java | 2 +- .../ClientServerCompressionExample.java | 2 +- 35 files changed, 219 insertions(+), 104 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java index d280997901..27c8b23e70 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/H2AsyncClientBuilder.java @@ -70,7 +70,6 @@ import org.apache.hc.client5.http.protocol.RequestExpectContinue; import org.apache.hc.client5.http.protocol.ResponseProcessCookies; import org.apache.hc.client5.http.routing.HttpRoutePlanner; -import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy; import org.apache.hc.core5.annotation.Experimental; import org.apache.hc.core5.annotation.Internal; import org.apache.hc.core5.concurrent.DefaultThreadFactory; @@ -201,7 +200,7 @@ private ExecInterceptorEntry( private boolean evictIdleConnections; private TimeValue maxIdleTime; - private boolean systemProperties; + private boolean ignoreSystemProperties; private boolean automaticRetriesDisabled; private boolean redirectHandlingDisabled; private boolean cookieManagementDisabled; @@ -669,13 +668,24 @@ public final H2AsyncClientBuilder setDefaultConnectionConfig(final ConnectionCon } /** - * Use system properties when creating and configuring default - * implementations. + * Use system properties when creating new instances. * * @return this instance. */ public final H2AsyncClientBuilder useSystemProperties() { - this.systemProperties = true; + this.ignoreSystemProperties = false; + return this; + } + + /** + * Ignore system properties when creating new instances. + * + * @return this instance. + * + * @since 5.7 + */ + public final H2AsyncClientBuilder ignoreSystemProperties() { + this.ignoreSystemProperties = true; return this; } @@ -964,24 +974,15 @@ public CloseableHttpAsyncClient build() { CredentialsProvider credentialsProviderCopy = this.credentialsProvider; if (credentialsProviderCopy == null) { - if (systemProperties) { - credentialsProviderCopy = new SystemDefaultCredentialsProvider(); - } else { + if (ignoreSystemProperties) { credentialsProviderCopy = new BasicCredentialsProvider(); - } - } - - TlsStrategy tlsStrategyCopy = this.tlsStrategy; - if (tlsStrategyCopy == null) { - if (systemProperties) { - tlsStrategyCopy = DefaultClientTlsStrategy.createSystemDefault(); } else { - tlsStrategyCopy = DefaultClientTlsStrategy.createDefault(); + credentialsProviderCopy = new SystemDefaultCredentialsProvider(); } } final MultihomeConnectionInitiator connectionInitiator = new MultihomeConnectionInitiator(ioReactor, dnsResolver); - final InternalH2ConnPool connPool = new InternalH2ConnPool(connectionInitiator, host -> null, tlsStrategyCopy); + final InternalH2ConnPool connPool = new InternalH2ConnPool(connectionInitiator, host -> null, tlsStrategy); connPool.setConnectionConfigResolver(connectionConfigResolver); List closeablesCopy = closeables != null ? new ArrayList<>(closeables) : null; 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 1f68dedc99..f199f476b9 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 @@ -252,7 +252,7 @@ private ExecInterceptorEntry( private boolean evictIdleConnections; private TimeValue maxIdleTime; - private boolean systemProperties; + private boolean ignoreSystemProperties; private boolean automaticRetriesDisabled; private boolean redirectHandlingDisabled; private boolean cookieManagementDisabled; @@ -776,13 +776,24 @@ public final HttpAsyncClientBuilder setDefaultRequestConfig(final RequestConfig } /** - * Use system properties when creating and configuring default - * implementations. + * Use system properties when creating new instances. * * @return this instance. */ public final HttpAsyncClientBuilder useSystemProperties() { - this.systemProperties = true; + this.ignoreSystemProperties = false; + return this; + } + + /** + * Ignore system properties when creating new instances. + * + * @return this instance. + * + * @since 5.7 + */ + public final HttpAsyncClientBuilder ignoreSystemProperties() { + this.ignoreSystemProperties = true; return this; } @@ -1011,8 +1022,8 @@ public CloseableHttpAsyncClient build() { AsyncClientConnectionManager connManagerCopy = this.connManager; if (connManagerCopy == null) { final PoolingAsyncClientConnectionManagerBuilder connectionManagerBuilder = PoolingAsyncClientConnectionManagerBuilder.create(); - if (systemProperties) { - connectionManagerBuilder.useSystemProperties(); + if (ignoreSystemProperties) { + connectionManagerBuilder.ignoreSystemProperties(); } connManagerCopy = connectionManagerBuilder.build(); } @@ -1166,11 +1177,11 @@ public CloseableHttpAsyncClient build() { routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy); } else if (this.proxySelector != null) { routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, this.proxySelector); - } else if (systemProperties) { + } else if (ignoreSystemProperties) { + routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy); + } else { final ProxySelector defaultProxySelector = ProxySelector.getDefault(); routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, defaultProxySelector); - } else { - routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy); } } @@ -1276,10 +1287,10 @@ public CloseableHttpAsyncClient build() { CredentialsProvider credentialsProviderCopy = this.credentialsProvider; if (credentialsProviderCopy == null) { - if (systemProperties) { - credentialsProviderCopy = new SystemDefaultCredentialsProvider(); - } else { + if (ignoreSystemProperties) { credentialsProviderCopy = new BasicCredentialsProvider(); + } else { + credentialsProviderCopy = new SystemDefaultCredentialsProvider(); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java index 3ef487a8e6..fdea360575 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java @@ -81,7 +81,10 @@ public static HttpAsyncClientBuilder custom() { /** * Creates {@link CloseableHttpAsyncClient} instance with default configuration. + * + * @deprecated Use {@link #create()} */ + @Deprecated public static CloseableHttpAsyncClient createDefault() { return HttpAsyncClientBuilder.create().build(); } @@ -89,9 +92,22 @@ public static CloseableHttpAsyncClient createDefault() { /** * Creates {@link CloseableHttpAsyncClient} instance with default * configuration and system properties. + * + * @deprecated Use {@link #create()} */ + @Deprecated public static CloseableHttpAsyncClient createSystem() { - return HttpAsyncClientBuilder.create().useSystemProperties().build(); + return HttpAsyncClientBuilder.create().build(); + } + + /** + * Creates {@link CloseableHttpAsyncClient} instance with default + * configuration and system properties. + * + * @since 5.7 + */ + public static CloseableHttpAsyncClient create() { + return HttpAsyncClientBuilder.create().build(); } /** @@ -116,7 +132,7 @@ public static CloseableHttpAsyncClient createHttp2Default() { * system properties optimized for HTTP/2 protocol and message multiplexing. */ public static CloseableHttpAsyncClient createHttp2System() { - return H2AsyncClientBuilder.create().useSystemProperties().build(); + return H2AsyncClientBuilder.create().build(); } private static HttpProcessor createMinimalProtocolProcessor() { @@ -325,7 +341,7 @@ public static MinimalH2AsyncClient createHttp2Minimal( public static MinimalH2AsyncClient createHttp2Minimal( final H2Config h2Config, final IOReactorConfig ioReactorConfig) { - return createHttp2Minimal(h2Config, ioReactorConfig, DefaultClientTlsStrategy.createDefault()); + return createHttp2Minimal(h2Config, ioReactorConfig, DefaultClientTlsStrategy.create()); } /** 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 d7c4a53ac3..dbbb1eb6f5 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 @@ -225,14 +225,13 @@ private ExecInterceptorEntry( private boolean evictIdleConnections; private TimeValue maxIdleTime; - private boolean systemProperties; + private boolean ignoreSystemProperties; private boolean redirectHandlingDisabled; private boolean automaticRetriesDisabled; private boolean contentCompressionDisabled; private boolean cookieManagementDisabled; private boolean authCachingDisabled; private boolean connectionStateDisabled; - private boolean defaultUserAgentDisabled; private ProxySelector proxySelector; private boolean tlsRequired; @@ -732,13 +731,24 @@ public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig confi } /** - * Use system properties when creating and configuring default - * implementations. + * Use system properties when creating new instances. * * @return this instance. */ public final HttpClientBuilder useSystemProperties() { - this.systemProperties = true; + this.ignoreSystemProperties = false; + return this; + } + + /** + * Ignore system properties when creating new instances. + * + * @return this instance. + * + * @since 5.7 + */ + public final HttpClientBuilder ignoreSystemProperties() { + this.ignoreSystemProperties = true; return this; } @@ -798,9 +808,11 @@ public final HttpClientBuilder evictIdleConnections(final TimeValue maxIdleTime) * * @return this instance. * @since 4.5.7 + * + * @deprecated Do not use. */ + @Deprecated public final HttpClientBuilder disableDefaultUserAgent() { - this.defaultUserAgentDisabled = true; return this; } @@ -883,8 +895,8 @@ public CloseableHttpClient build() { HttpClientConnectionManager connManagerCopy = this.connManager; if (connManagerCopy == null) { final PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder.create(); - if (systemProperties) { - connectionManagerBuilder.useSystemProperties(); + if (ignoreSystemProperties) { + connectionManagerBuilder.ignoreSystemProperties(); } connManagerCopy = connectionManagerBuilder.build(); } @@ -1039,11 +1051,11 @@ public CloseableHttpClient build() { routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy); } else if (this.proxySelector != null) { routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, this.proxySelector); - } else if (systemProperties) { + } else if (ignoreSystemProperties) { + routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy); + } else { final ProxySelector defaultProxySelector = ProxySelector.getDefault(); routePlannerCopy = new SystemDefaultRoutePlanner(schemePortResolverCopy, defaultProxySelector); - } else { - routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy); } } @@ -1118,10 +1130,10 @@ public CloseableHttpClient build() { CredentialsProvider defaultCredentialsProvider = this.credentialsProvider; if (defaultCredentialsProvider == null) { - if (systemProperties) { - defaultCredentialsProvider = new SystemDefaultCredentialsProvider(); - } else { + if (ignoreSystemProperties) { defaultCredentialsProvider = new BasicCredentialsProvider(); + } else { + defaultCredentialsProvider = new SystemDefaultCredentialsProvider(); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClients.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClients.java index 55ccb58309..7de2aae9a1 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClients.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpClients.java @@ -52,7 +52,10 @@ public static HttpClientBuilder custom() { /** * Creates {@link CloseableHttpClient} instance with default * configuration. + * + * @deprecated Use {@link #create()} */ + @Deprecated public static CloseableHttpClient createDefault() { return HttpClientBuilder.create().build(); } @@ -60,9 +63,22 @@ public static CloseableHttpClient createDefault() { /** * Creates {@link CloseableHttpClient} instance with default * configuration based on system properties. + * + * @deprecated Use {@link #create()} */ + @Deprecated public static CloseableHttpClient createSystem() { - return HttpClientBuilder.create().useSystemProperties().build(); + return HttpClientBuilder.create().build(); + } + + /** + * Creates {@link CloseableHttpClient} instance with default + * configuration based on system properties. + * + * @since 5.7 + */ + public static CloseableHttpClient create() { + return HttpClientBuilder.create().build(); } /** diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java index d634d94682..0e6534414e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java @@ -206,7 +206,7 @@ public BasicHttpClientConnectionManager( public BasicHttpClientConnectionManager() { this(new DefaultHttpClientConnectionOperator(null, null, RegistryBuilder.create() - .register(URIScheme.HTTPS.id, DefaultClientTlsStrategy.createDefault()) + .register(URIScheme.HTTPS.id, DefaultClientTlsStrategy.create()) .build()), null); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java index 1e464d7386..fc462dd576 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java @@ -132,7 +132,7 @@ public class PoolingHttpClientConnectionManager public PoolingHttpClientConnectionManager() { this(new DefaultHttpClientConnectionOperator(null, null, RegistryBuilder.create() - .register(URIScheme.HTTPS.id, DefaultClientTlsStrategy.createDefault()) + .register(URIScheme.HTTPS.id, DefaultClientTlsStrategy.create()) .build()), PoolConcurrencyPolicy.STRICT, PoolReusePolicy.LIFO, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java index 2f39e9ddfe..937ca1dc48 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManagerBuilder.java @@ -88,7 +88,7 @@ public class PoolingHttpClientConnectionManagerBuilder { private Resolver connectionConfigResolver; private Resolver tlsConfigResolver; - private boolean systemProperties; + private boolean ignoreSystemProperties; private int maxConnTotal; private int maxConnPerRoute; @@ -311,13 +311,24 @@ public final PoolingHttpClientConnectionManagerBuilder setValidateAfterInactivit } /** - * Use system properties when creating and configuring default - * implementations. + * Use system properties when creating new instances. * * @return this instance. */ public final PoolingHttpClientConnectionManagerBuilder useSystemProperties() { - this.systemProperties = true; + this.ignoreSystemProperties = false; + return this; + } + + /** + * Ignore system properties when creating new instances. + * + * @return this instance. + * + * @since 5.7 + */ + public final PoolingHttpClientConnectionManagerBuilder ignoreSystemProperties() { + this.ignoreSystemProperties = true; return this; } @@ -358,11 +369,7 @@ public PoolingHttpClientConnectionManager build() { if (tlsSocketStrategy != null) { tlsSocketStrategyCopy = tlsSocketStrategy; } else { - if (systemProperties) { - tlsSocketStrategyCopy = DefaultClientTlsStrategy.createSystemDefault(); - } else { - tlsSocketStrategyCopy = DefaultClientTlsStrategy.createDefault(); - } + tlsSocketStrategyCopy = DefaultClientTlsStrategy.create(); } final PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index 48180774b2..f61542c2c3 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -136,7 +136,7 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio public PoolingAsyncClientConnectionManager() { this(RegistryBuilder.create() - .register(URIScheme.HTTPS.getId(), DefaultClientTlsStrategy.createDefault()) + .register(URIScheme.HTTPS.getId(), DefaultClientTlsStrategy.create()) .build()); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java index e899071003..c5a40ef771 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManagerBuilder.java @@ -80,7 +80,7 @@ public class PoolingAsyncClientConnectionManagerBuilder { private PoolConcurrencyPolicy poolConcurrencyPolicy; private PoolReusePolicy poolReusePolicy; - private boolean systemProperties; + private boolean ignoreSystemProperties; private int maxConnTotal; private int maxConnPerRoute; @@ -259,13 +259,24 @@ public final PoolingAsyncClientConnectionManagerBuilder setValidateAfterInactivi } /** - * Use system properties when creating and configuring default - * implementations. + * Use system properties when creating new instances. * * @return this instance. */ public final PoolingAsyncClientConnectionManagerBuilder useSystemProperties() { - this.systemProperties = true; + this.ignoreSystemProperties = false; + return this; + } + + /** + * Ignore system properties when creating new instances. + * + * @return this instance. + * + * @since 5.7 + */ + public final PoolingAsyncClientConnectionManagerBuilder ignoreSystemProperties() { + this.ignoreSystemProperties = true; return this; } @@ -306,17 +317,9 @@ public PoolingAsyncClientConnectionManager build() { tlsStrategyCopy = tlsStrategy; } else { if (ReflectionUtils.determineJRELevel() <= 8 && ConscryptClientTlsStrategy.isSupported()) { - if (systemProperties) { - tlsStrategyCopy = ConscryptClientTlsStrategy.getSystemDefault(); - } else { - tlsStrategyCopy = ConscryptClientTlsStrategy.getDefault(); - } + tlsStrategyCopy = ConscryptClientTlsStrategy.create(); } else { - if (systemProperties) { - tlsStrategyCopy = DefaultClientTlsStrategy.createSystemDefault(); - } else { - tlsStrategyCopy = DefaultClientTlsStrategy.createDefault(); - } + tlsStrategyCopy = DefaultClientTlsStrategy.create(); } } final PoolingAsyncClientConnectionManager poolingmgr = new PoolingAsyncClientConnectionManager( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ClientTlsStrategyBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ClientTlsStrategyBuilder.java index 12e254a929..cd04939cc5 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ClientTlsStrategyBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/ClientTlsStrategyBuilder.java @@ -74,7 +74,7 @@ public static ClientTlsStrategyBuilder create() { private SSLBufferMode sslBufferMode; private HostnameVerificationPolicy hostnameVerificationPolicy; private HostnameVerifier hostnameVerifier; - private boolean systemProperties; + private boolean ignoreSystemProperties; /** * Sets {@link SSLContext} instance. @@ -171,13 +171,24 @@ public ClientTlsStrategyBuilder setTlsDetailsFactory(final FactoryExample – transparent GZIP de-compression with the async API * *

{@code ContentCompressionAsyncExec} is included by default in - * {@link HttpAsyncClients#createDefault()}. - * The interceptor adds the header + * {@link HttpAsyncClients#create()}. The interceptor adds the header * {@code Accept-Encoding: gzip, deflate} and automatically wraps the * downstream consumer in a {@code InflatingGzipDataConsumer} when the * server replies with {@code Content-Encoding: gzip}.

@@ -64,7 +63,7 @@ public final class AsyncClientGzipDecompressionExample { public static void main(final String[] args) throws Exception { - try (final CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) { + try (final CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); final SimpleHttpRequest request = diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java index c5eb1fd014..aa5ed5ed63 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientInflateDecompressionExample.java @@ -69,7 +69,7 @@ public static void main(final String[] args) throws Exception { /* The default builder now contains ContentCompressionAsyncExec, so transparent decompression is automatic. */ - try (final CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) { + try (final CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); final SimpleHttpRequest request = diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientSNI.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientSNI.java index 9b38baa82c..8f87258ae7 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientSNI.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientSNI.java @@ -51,7 +51,7 @@ public class AsyncClientSNI { public static void main(final String[] args) throws Exception { - try (final CloseableHttpAsyncClient client = HttpAsyncClients.createSystem()) { + try (final CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java index 2924bc5561..4f32653b8c 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerBrotliRoundTrip.java @@ -95,7 +95,7 @@ public static void main(final String[] args) throws Exception { final int port = server.getLocalPort(); final String url = "http://localhost:" + port + "/echo"; - try (final CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) { + try (final CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); final String requestBody = "Hello Brotli world (round-trip)!"; diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java index 74c2fdbefb..b57c5f442b 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientServerZstdExample.java @@ -68,7 +68,7 @@ * *

This example starts a tiny {@code HttpCore 5} classic server that always replies * with {@code Content-Encoding: zstd}. The async client is the regular - * {@link org.apache.hc.client5.http.impl.async.HttpAsyncClients#createDefault() default} client. + * {@link org.apache.hc.client5.http.impl.async.HttpAsyncClients#create() default} client. * When the response carries the {@code zstd} content-coding, the execution chain * (see {@code ContentCompressionAsyncExec}) transparently installs * {@link org.apache.hc.client5.http.async.methods.InflatingZstdDataConsumer} and delivers @@ -110,7 +110,7 @@ public static void main(final String[] args) throws Exception { final int port = server.getLocalPort(); final String url = "http://localhost:" + port + "/echo"; - try (final CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) { + try (final CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); final String requestBody = "Hello Zstandard world!"; diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java index 58ad574e4f..0284c22e9a 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientZstdCompressionExample.java @@ -123,7 +123,7 @@ public static void main(final String[] args) throws Exception { final int port = server.getLocalPort(); final String url = "http://localhost:" + port + "/echo"; - try (CloseableHttpAsyncClient client = HttpAsyncClients.createDefault()) { + try (CloseableHttpAsyncClient client = HttpAsyncClients.create()) { client.start(); final String payload = "Hello Zstandard request body!"; diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncPreemptiveBasicClientAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncPreemptiveBasicClientAuthentication.java index 4670b2f585..c08717d977 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncPreemptiveBasicClientAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncPreemptiveBasicClientAuthentication.java @@ -50,7 +50,7 @@ public class AsyncPreemptiveBasicClientAuthentication { public static void main(final String[] args) throws Exception { - final CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); + final CloseableHttpAsyncClient httpclient = HttpAsyncClients.create(); httpclient.start(); final HttpClientContext localContext = ContextBuilder.create() diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java index 1c01d8420c..afd0a9d4f9 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientAbortMethod.java @@ -44,7 +44,7 @@ public class ClientAbortMethod { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1, diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java index 64504fd5a2..28b3e5f1ef 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientChunkEncodedPost.java @@ -47,7 +47,7 @@ public static void main(final String[] args) throws Exception { System.out.println("File path not given"); System.exit(1); } - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpPost httppost = new HttpPost("http://httpbin.org/post"); final File file = new File(args[0]); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientClassicOverAsync.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientClassicOverAsync.java index dd6d61c23f..94282d79e9 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientClassicOverAsync.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientClassicOverAsync.java @@ -52,7 +52,7 @@ public class ClientClassicOverAsync { public static void main(final String[] args) throws Exception { try (final CloseableHttpClient httpclient = HttpAsyncClients.classic( - HttpAsyncClients.createDefault(), + HttpAsyncClients.create(), Timeout.ofMinutes(1))) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java index a78e5a76d5..87563b7d1e 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientConnectionRelease.java @@ -42,7 +42,7 @@ public class ClientConnectionRelease { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpHost target = new HttpHost("http", "httpbin.org"); final HttpGet httpget = new HttpGet("/get"); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java index dff8586317..6ab853aea0 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientCustomContext.java @@ -47,7 +47,7 @@ public class ClientCustomContext { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { // Create a local instance of cookie store final CookieStore cookieStore = new BasicCookieStore(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java index c819068156..3b0d811065 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientMultipartFormPost.java @@ -48,7 +48,7 @@ public static void main(final String[] args) throws Exception { System.out.println("File path not given"); System.exit(1); } - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpPost httppost = new HttpPost("http://httpbin.org/post"); final FileBody bin = new FileBody(new File(args[0])); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java index 6f4a864da8..a851dd0d43 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveBasicAuthentication.java @@ -47,7 +47,7 @@ public class ClientPreemptiveBasicAuthentication { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpClientContext localContext = ContextBuilder.create() .preemptiveBasicAuth(new HttpHost("http", "httpbin.org"), diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java index f056fb60e2..23d5a2b750 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientPreemptiveDigestAuthentication.java @@ -49,7 +49,7 @@ public class ClientPreemptiveDigestAuthentication { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpHost target = new HttpHost("http", "httpbin.org", 80); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientRemoteEndpointDetails.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientRemoteEndpointDetails.java index 15e5cb96f9..05855cc2a2 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientRemoteEndpointDetails.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientRemoteEndpointDetails.java @@ -42,7 +42,7 @@ public class ClientRemoteEndpointDetails { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { // Create local HTTP context final HttpClientContext localContext = HttpClientContext.create(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java index ad7c45542f..cf78c1ba4a 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientResponseProcessing.java @@ -40,7 +40,7 @@ public class ClientResponseProcessing { public static void main(final String[] args) throws Exception { - try (final CloseableHttpClient httpclient = HttpClients.createDefault()) { + try (final CloseableHttpClient httpclient = HttpClients.create()) { final HttpGet httpget = new HttpGet("http://httpbin.org/get"); System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri()); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientSNI.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientSNI.java index 17736e884e..780577c131 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientSNI.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientSNI.java @@ -44,7 +44,7 @@ public class ClientSNI { public final static void main(final String[] args) throws Exception { - try (CloseableHttpClient httpclient = HttpClients.createSystem()) { + try (CloseableHttpClient httpclient = HttpClients.create()) { final HttpHost target = new HttpHost("https", "www.google.com"); final HttpGet httpget = new HttpGet("https://www.google.ch/"); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java index 76a579bb88..0e07b84e5f 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientServerCompressionExample.java @@ -97,7 +97,7 @@ public static void main(final String[] args) throws Exception { server.start(); final int actualPort = server.getLocalPort(); - try (CloseableHttpClient client = HttpClients.createDefault()) { + try (CloseableHttpClient client = HttpClients.create()) { final String requestBody = "Hello Zstandard world!"; System.out.println("Request : " + requestBody);