Class HttpAsyncClientBuilder
- Direct Known Subclasses:
CachingHttpAsyncClientBuilder
CloseableHttpAsyncClient instances that can negotiate
the most optimal HTTP protocol version during the TLS handshake
with ALPN extension if supported by the Java runtime.
Concurrent message exchanges executed by CloseableHttpAsyncClient
instances created with this builder will get automatically assigned to
separate connections leased from the connection pool.
When a particular component is not explicitly set this class will
use its default implementation. System properties will be taken
into account when configuring the default implementations when
useSystemProperties() method is called prior to calling
build().
- http.proxyHost
- http.proxyPort
- https.proxyHost
- https.proxyPort
- http.nonProxyHosts
- http.keepAlive
- http.agent
Please note that some settings used by this class can be mutually
exclusive and may not apply when building CloseableHttpAsyncClient
instances.
- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> private booleanprivate org.apache.hc.core5.http.config.CharCodingConfigprivate booleanprivate AsyncClientConnectionManagerprivate booleanprivate booleanWhentruethe client skips all transparent response decompression.private LinkedHashMap<String, UnaryOperator<org.apache.hc.core5.http.nio.AsyncDataConsumer>> MapsContent-Encodingtokens to decoder factories in insertion order.private booleanprivate org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> private CookieStoreprivate CredentialsProviderprivate Collection<? extends org.apache.hc.core5.http.Header> private RequestConfigprivate EarlyHintsListenerprivate booleanprivate booleanprivate org.apache.hc.core5.http.config.Http1Configprivate org.apache.hc.core5.http2.config.H2Configprivate org.apache.hc.core5.reactor.IOReactorConfigprivate org.apache.hc.core5.function.Callback<Exception> private org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> private org.apache.hc.core5.reactor.IOSessionListenerprivate ConnectionKeepAliveStrategyprivate org.apache.hc.core5.util.TimeValueprivate booleanprivate org.apache.hc.core5.http.HttpHostprivate AuthenticationStrategyprivate ProxySelectorprivate booleanprivate RedirectStrategyprivate HttpRequestRetryStrategyprivate org.apache.hc.core5.http.ConnectionReuseStrategyprivate HttpRoutePlannerprivate SchemePortResolverprivate booleanprivate AuthenticationStrategyprivate ThreadFactoryprivate TlsConfigDeprecated.TLS should be configured by the connection managerprivate Stringprivate UserTokenHandler -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCloseable(Closeable closeable) Adds to the list ofCloseableresources to be managed by the client.final HttpAsyncClientBuilderaddExecInterceptorAfter(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name.final HttpAsyncClientBuilderaddExecInterceptorBefore(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor.final HttpAsyncClientBuilderaddExecInterceptorFirst(String name, AsyncExecChainHandler interceptor) Add an interceptor to the head of the processing list.final HttpAsyncClientBuilderaddExecInterceptorLast(String name, AsyncExecChainHandler interceptor) Add an interceptor to the tail of the processing list.final HttpAsyncClientBuilderaddRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpAsyncClientBuilderaddRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.final HttpAsyncClientBuilderaddResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpAsyncClientBuilderaddResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.build()protected Function<org.apache.hc.core5.http.protocol.HttpContext, HttpClientContext> static HttpAsyncClientBuildercreate()protected voidcustomizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<AsyncExecChainHandler> execChainDefinition) Request exec chain customization and extension.final HttpAsyncClientBuilderDisables authentication scheme caching.final HttpAsyncClientBuilderDisables automatic request recovery and re-execution.final HttpAsyncClientBuilderDisables connection state tracking.Disables transparent response decompression for the client produced by this builder.final HttpAsyncClientBuilderDisables state (cookie) management.final HttpAsyncClientBuilderDisables automatic redirect handling.final HttpAsyncClientBuilderDisable installing the HTTP/2 Priority header interceptor by default.final HttpAsyncClientBuilderMakes this instance of HttpClient proactively evict expired connections from the connection pool using a background thread.final HttpAsyncClientBuilderevictIdleConnections(org.apache.hc.core5.util.TimeValue maxIdleTime) Makes this instance of HttpClient proactively evict idle connections from the connection pool using a background thread.private StringgetProperty(String key, String defaultValue) final HttpAsyncClientBuilderreplaceExecInterceptor(String existing, AsyncExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor.final HttpAsyncClientBuildersetCharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig) SetsCharCodingConfigconfiguration.final HttpAsyncClientBuildersetConnectionManager(AsyncClientConnectionManager connManager) SetsAsyncClientConnectionManagerinstance.final HttpAsyncClientBuildersetConnectionManagerShared(boolean shared) Defines the connection manager is to be shared by multiple client instances.final HttpAsyncClientBuildersetConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) SetsConnectionReuseStrategyinstance.setContentDecoderMap(LinkedHashMap<String, UnaryOperator<org.apache.hc.core5.http.nio.AsyncDataConsumer>> contentDecoderMap) Replaces the current decoder registry withcontentDecoderMap.final HttpAsyncClientBuildersetDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> authSchemeRegistry) Sets defaultAuthSchemeregistry which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultCookieSpecRegistry(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> cookieSpecRegistry) Sets defaultCookieSpecregistry which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultCookieStore(CookieStore cookieStore) Sets defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Sets defaultCredentialsProviderinstance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Sets default request header values.final HttpAsyncClientBuildersetDefaultRequestConfig(RequestConfig config) Sets defaultRequestConfiginstance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetEarlyHintsListener(EarlyHintsListener listener) Registers a globalEarlyHintsListenerthat will be notified when the client receives103 Early Hintsinformational responses for any request executed by the built client.final HttpAsyncClientBuildersetH2Config(org.apache.hc.core5.http2.config.H2Config h2Config) SetsH2Configconfiguration.final HttpAsyncClientBuildersetHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config) SetsHttp1Configconfiguration.final HttpAsyncClientBuildersetIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig) SetsIOReactorConfigconfiguration.final HttpAsyncClientBuildersetIoReactorExceptionCallback(org.apache.hc.core5.function.Callback<Exception> ioReactorExceptionCallback) Sets the callback that will be invoked when the client's IOReactor encounters an uncaught exception.final HttpAsyncClientBuildersetIoSessionDecorator(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator) Sets theIOSessionDecoratorthat will be use with the client's IOReactor.final HttpAsyncClientBuildersetIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener) SetsIOSessionListenerlistener.final HttpAsyncClientBuildersetKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) SetsConnectionKeepAliveStrategyinstance.final HttpAsyncClientBuildersetProxy(org.apache.hc.core5.http.HttpHost proxy) Sets default proxy value.final HttpAsyncClientBuildersetProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) SetsAuthenticationStrategyinstance for proxy authentication.final HttpAsyncClientBuildersetProxySelector(ProxySelector proxySelector) Sets theProxySelectorthat will be used to select the proxies to be used for establishing HTTP connections.setRedirectStrategy(RedirectStrategy redirectStrategy) SetsRedirectStrategyinstance.final HttpAsyncClientBuildersetRetryStrategy(HttpRequestRetryStrategy retryStrategy) SetsHttpRequestRetryStrategyinstance.final HttpAsyncClientBuildersetRoutePlanner(HttpRoutePlanner routePlanner) SetsHttpRoutePlannerinstance.final HttpAsyncClientBuildersetSchemePortResolver(SchemePortResolver schemePortResolver) SetsSchemePortResolverinstance.final HttpAsyncClientBuildersetTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) SetsAuthenticationStrategyinstance for target host authentication.final HttpAsyncClientBuildersetThreadFactory(ThreadFactory threadFactory) SetsThreadFactoryinstance.final HttpAsyncClientBuildersetUserAgent(String userAgent) SetsUser-Agentvalue.final HttpAsyncClientBuildersetUserTokenHandler(UserTokenHandler userTokenHandler) SetsUserTokenHandlerinstance.final HttpAsyncClientBuildersetVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy) Deprecated.UseTlsConfigand connection manager methodsfinal HttpAsyncClientBuilderUse system properties when creating and configuring default implementations.
-
Field Details
-
tlsConfig
Deprecated.TLS should be configured by the connection manager -
connManager
-
ioReactorConfig
private org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig -
ioSessionListener
private org.apache.hc.core5.reactor.IOSessionListener ioSessionListener -
ioReactorExceptionCallback
-
h1Config
private org.apache.hc.core5.http.config.Http1Config h1Config -
h2Config
private org.apache.hc.core5.http2.config.H2Config h2Config -
charCodingConfig
private org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig -
schemePortResolver
-
keepAliveStrategy
-
userTokenHandler
-
targetAuthStrategy
-
proxyAuthStrategy
-
ioSessionDecorator
private org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator -
requestInterceptors
-
responseInterceptors
-
execInterceptors
-
routePlanner
-
redirectStrategy
-
retryStrategy
-
reuseStrategy
private org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy -
authSchemeRegistry
-
cookieSpecRegistry
-
cookieStore
-
credentialsProvider
-
userAgent
-
proxy
private org.apache.hc.core5.http.HttpHost proxy -
defaultHeaders
-
defaultRequestConfig
-
evictExpiredConnections
private boolean evictExpiredConnections -
evictIdleConnections
private boolean evictIdleConnections -
maxIdleTime
private org.apache.hc.core5.util.TimeValue maxIdleTime -
systemProperties
private boolean systemProperties -
automaticRetriesDisabled
private boolean automaticRetriesDisabled -
redirectHandlingDisabled
private boolean redirectHandlingDisabled -
cookieManagementDisabled
private boolean cookieManagementDisabled -
authCachingDisabled
private boolean authCachingDisabled -
connectionStateDisabled
private boolean connectionStateDisabled -
threadFactory
-
closeables
-
proxySelector
-
earlyHintsListener
-
priorityHeaderDisabled
private boolean priorityHeaderDisabled -
contentDecoderMap
private LinkedHashMap<String, UnaryOperator<org.apache.hc.core5.http.nio.AsyncDataConsumer>> contentDecoderMapMapsContent-Encodingtokens to decoder factories in insertion order. -
contentCompressionDisabled
private boolean contentCompressionDisabledWhentruethe client skips all transparent response decompression.
-
-
Constructor Details
-
HttpAsyncClientBuilder
protected HttpAsyncClientBuilder()
-
-
Method Details
-
create
-
setVersionPolicy
@Deprecated public final HttpAsyncClientBuilder setVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy) Deprecated.UseTlsConfigand connection manager methodsSets HTTP protocol version policy.- Returns:
- this instance.
-
setHttp1Config
public final HttpAsyncClientBuilder setHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config) SetsHttp1Configconfiguration.- Returns:
- this instance.
-
setH2Config
SetsH2Configconfiguration.- Returns:
- this instance.
-
setConnectionManager
SetsAsyncClientConnectionManagerinstance.- Returns:
- this instance.
-
setIOReactorConfig
public final HttpAsyncClientBuilder setIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig) SetsIOReactorConfigconfiguration.- Returns:
- this instance.
-
setIOSessionListener
public final HttpAsyncClientBuilder setIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener) SetsIOSessionListenerlistener.- Returns:
- this instance.
- Since:
- 5.2
-
setIoReactorExceptionCallback
public final HttpAsyncClientBuilder setIoReactorExceptionCallback(org.apache.hc.core5.function.Callback<Exception> ioReactorExceptionCallback) Sets the callback that will be invoked when the client's IOReactor encounters an uncaught exception.- Returns:
- this instance.
- Since:
- 5.1
-
setCharCodingConfig
public final HttpAsyncClientBuilder setCharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig) SetsCharCodingConfigconfiguration.- Returns:
- this instance.
-
setConnectionReuseStrategy
public final HttpAsyncClientBuilder setConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) SetsConnectionReuseStrategyinstance.Please note this strategy applies to HTTP/1.0 and HTTP/1.1 connections only
- Returns:
- this instance.
-
setKeepAliveStrategy
public final HttpAsyncClientBuilder setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) SetsConnectionKeepAliveStrategyinstance.- Returns:
- this instance.
-
setUserTokenHandler
SetsUserTokenHandlerinstance.Please note this value can be overridden by the
disableConnectionState()method.- Returns:
- this instance.
-
setTargetAuthenticationStrategy
public final HttpAsyncClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) SetsAuthenticationStrategyinstance for target host authentication.- Returns:
- this instance.
-
setProxyAuthenticationStrategy
public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) SetsAuthenticationStrategyinstance for proxy authentication.- Returns:
- this instance.
-
setIoSessionDecorator
public final HttpAsyncClientBuilder setIoSessionDecorator(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator) Sets theIOSessionDecoratorthat will be use with the client's IOReactor.- Returns:
- this instance.
- Since:
- 5.2
-
addResponseInterceptorFirst
public final HttpAsyncClientBuilder addResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.- Returns:
- this instance.
-
addResponseInterceptorLast
public final HttpAsyncClientBuilder addResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.- Returns:
- this instance.
-
addExecInterceptorBefore
public final HttpAsyncClientBuilder addExecInterceptorBefore(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor.- Returns:
- this instance.
-
addExecInterceptorAfter
public final HttpAsyncClientBuilder addExecInterceptorAfter(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name.- Returns:
- this instance.
-
replaceExecInterceptor
public final HttpAsyncClientBuilder replaceExecInterceptor(String existing, AsyncExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor.- Returns:
- this instance.
-
addExecInterceptorFirst
public final HttpAsyncClientBuilder addExecInterceptorFirst(String name, AsyncExecChainHandler interceptor) Add an interceptor to the head of the processing list.- Returns:
- this instance.
-
addExecInterceptorLast
public final HttpAsyncClientBuilder addExecInterceptorLast(String name, AsyncExecChainHandler interceptor) Add an interceptor to the tail of the processing list.- Returns:
- this instance.
-
addRequestInterceptorFirst
public final HttpAsyncClientBuilder addRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.- Returns:
- this instance.
-
addRequestInterceptorLast
public final HttpAsyncClientBuilder addRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.- Returns:
- this instance.
-
setRetryStrategy
SetsHttpRequestRetryStrategyinstance.Please note this value can be overridden by the
disableAutomaticRetries()method.- Returns:
- this instance.
-
setRedirectStrategy
SetsRedirectStrategyinstance.Please note this value can be overridden by the
disableRedirectHandling()method.- Returns:
- this instance.
-
setSchemePortResolver
SetsSchemePortResolverinstance.- Returns:
- this instance.
-
setThreadFactory
SetsThreadFactoryinstance.- Returns:
- this instance.
-
setUserAgent
SetsUser-Agentvalue.- Returns:
- this instance.
-
setDefaultHeaders
public final HttpAsyncClientBuilder setDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Sets default request header values.- Returns:
- this instance.
-
setProxySelector
Sets theProxySelectorthat will be used to select the proxies to be used for establishing HTTP connections. If a non-null proxy selector is set, it will take precedence over the proxy settings configured in the client.- Parameters:
proxySelector- theProxySelectorto be used, or null to use the default system proxy selector.- Returns:
- this instance.
-
setProxy
Sets default proxy value.Please note this value can be overridden by the
setRoutePlanner(HttpRoutePlanner)method.- Returns:
- this instance.
-
setRoutePlanner
SetsHttpRoutePlannerinstance.- Returns:
- this instance.
-
setDefaultCredentialsProvider
public final HttpAsyncClientBuilder setDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Sets defaultCredentialsProviderinstance which will be used for request execution if not explicitly set in the client execution context.- Returns:
- this instance.
-
setDefaultAuthSchemeRegistry
public final HttpAsyncClientBuilder setDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> authSchemeRegistry) Sets defaultAuthSchemeregistry which will be used for request execution if not explicitly set in the client execution context.- Returns:
- this instance.
-
setDefaultCookieSpecRegistry
public final HttpAsyncClientBuilder setDefaultCookieSpecRegistry(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> cookieSpecRegistry) Sets defaultCookieSpecregistry which will be used for request execution if not explicitly set in the client execution context.- Returns:
- this instance.
-
setDefaultCookieStore
Sets defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context.- Returns:
- this instance.
-
setDefaultRequestConfig
Sets defaultRequestConfiginstance which will be used for request execution if not explicitly set in the client execution context.- Returns:
- this instance.
-
useSystemProperties
Use system properties when creating and configuring default implementations.- Returns:
- this instance.
-
disableConnectionState
Disables connection state tracking.- Returns:
- this instance.
-
disableRedirectHandling
Disables automatic redirect handling.- Returns:
- this instance.
-
disableAutomaticRetries
Disables automatic request recovery and re-execution.- Returns:
- this instance.
-
disableCookieManagement
Disables state (cookie) management.- Returns:
- this instance.
-
disableAuthCaching
Disables authentication scheme caching.- Returns:
- this instance.
-
evictExpiredConnections
Makes this instance of HttpClient proactively evict expired connections from the connection pool using a background thread.One MUST explicitly close HttpClient with
Closeable.close()in order to stop and release the background thread.Please note this method has no effect if the instance of HttpClient is configured to use a shared connection manager.
- Returns:
- this instance.
- See Also:
-
evictIdleConnections
public final HttpAsyncClientBuilder evictIdleConnections(org.apache.hc.core5.util.TimeValue maxIdleTime) Makes this instance of HttpClient proactively evict idle connections from the connection pool using a background thread.One MUST explicitly close HttpClient with
Closeable.close()in order to stop and release the background thread.Please note this method has no effect if the instance of HttpClient is configured to use a shared connection manager.
- Parameters:
maxIdleTime- maximum time persistent connections can stay idle while kept alive in the connection pool. Connections whose inactivity period exceeds this value will get closed and evicted from the pool.- Returns:
- this instance.
- See Also:
-
setContentDecoderMap
public HttpAsyncClientBuilder setContentDecoderMap(LinkedHashMap<String, UnaryOperator<org.apache.hc.core5.http.nio.AsyncDataConsumer>> contentDecoderMap) Replaces the current decoder registry withcontentDecoderMap.The map’s insertion order defines the
Accept-Encodingpreference list sent on every request.- Parameters:
contentDecoderMap- a non-emptyLinkedHashMapwhose keys are lower-case coding tokens and whose values create a fresh wrapper consumer for each response- Returns:
thisbuilder instance- Since:
- 5.6
-
disableContentCompression
Disables transparent response decompression for the client produced by this builder.- Returns:
thisbuilder instance- Since:
- 5.6
-
disableRequestPriority
Disable installing the HTTP/2 Priority header interceptor by default.- Since:
- 5.6
-
setEarlyHintsListener
Registers a globalEarlyHintsListenerthat will be notified when the client receives103 Early Hintsinformational responses for any request executed by the built client.- Parameters:
listener- the listener to receive103 Early Hintsevents, ornullto remove the listener- Returns:
- this builder
- Since:
- 5.6
-
customizeExecChain
@Internal protected void customizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<AsyncExecChainHandler> execChainDefinition) Request exec chain customization and extension.For internal use.
-
addCloseable
-
contextAdaptor
@Internal protected Function<org.apache.hc.core5.http.protocol.HttpContext, HttpClientContext> contextAdaptor() -
getConnManager
-
build
-
getProperty
-