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 class
private static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private org.apache.hc.core5.http.config.Lookup
<AuthSchemeFactory> private boolean
private org.apache.hc.core5.http.config.CharCodingConfig
private boolean
private AsyncClientConnectionManager
private boolean
private boolean
private org.apache.hc.core5.http.config.Lookup
<CookieSpecFactory> private CookieStore
private CredentialsProvider
private Collection
<? extends org.apache.hc.core5.http.Header> private RequestConfig
private boolean
private boolean
private org.apache.hc.core5.http.config.Http1Config
private org.apache.hc.core5.http2.config.H2Config
private org.apache.hc.core5.reactor.IOReactorConfig
private 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.IOSessionListener
private ConnectionKeepAliveStrategy
private org.apache.hc.core5.util.TimeValue
private org.apache.hc.core5.http.HttpHost
private AuthenticationStrategy
private ProxySelector
private boolean
private RedirectStrategy
private HttpRequestRetryStrategy
private org.apache.hc.core5.http.ConnectionReuseStrategy
private HttpRoutePlanner
private SchemePortResolver
private boolean
private AuthenticationStrategy
private ThreadFactory
private TlsConfig
Deprecated.TLS should be configured by the connection managerprivate String
private UserTokenHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCloseable
(Closeable closeable) Adds to the list ofCloseable
resources to be managed by the client.final HttpAsyncClientBuilder
addExecInterceptorAfter
(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name.final HttpAsyncClientBuilder
addExecInterceptorBefore
(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor.final HttpAsyncClientBuilder
addExecInterceptorFirst
(String name, AsyncExecChainHandler interceptor) Add an interceptor to the head of the processing list.final HttpAsyncClientBuilder
addExecInterceptorLast
(String name, AsyncExecChainHandler interceptor) Add an interceptor to the tail of the processing list.final HttpAsyncClientBuilder
addRequestInterceptorFirst
(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpAsyncClientBuilder
addRequestInterceptorLast
(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.final HttpAsyncClientBuilder
addResponseInterceptorFirst
(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpAsyncClientBuilder
addResponseInterceptorLast
(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.build()
static HttpAsyncClientBuilder
create()
protected void
customizeExecChain
(org.apache.hc.core5.http.config.NamedElementChain<AsyncExecChainHandler> execChainDefinition) Request exec chain customization and extension.final HttpAsyncClientBuilder
Disables authentication scheme caching.final HttpAsyncClientBuilder
Disables automatic request recovery and re-execution.final HttpAsyncClientBuilder
Disables connection state tracking.final HttpAsyncClientBuilder
Disables state (cookie) management.final HttpAsyncClientBuilder
Disables automatic redirect handling.final HttpAsyncClientBuilder
Makes this instance of HttpClient proactively evict expired connections from the connection pool using a background thread.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.private String
getProperty
(String key, String defaultValue) final HttpAsyncClientBuilder
replaceExecInterceptor
(String existing, AsyncExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor.final HttpAsyncClientBuilder
setCharCodingConfig
(org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig) SetsCharCodingConfig
configuration.final HttpAsyncClientBuilder
setConnectionManager
(AsyncClientConnectionManager connManager) AssignsAsyncClientConnectionManager
instance.final HttpAsyncClientBuilder
setConnectionManagerShared
(boolean shared) Defines the connection manager is to be shared by multiple client instances.final HttpAsyncClientBuilder
setConnectionReuseStrategy
(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategy
instance.final HttpAsyncClientBuilder
setDefaultAuthSchemeRegistry
(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> authSchemeRegistry) Assigns defaultAuthScheme
registry which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuilder
setDefaultCookieSpecRegistry
(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> cookieSpecRegistry) Assigns defaultCookieSpec
registry which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuilder
setDefaultCookieStore
(CookieStore cookieStore) Assigns defaultCookieStore
instance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuilder
setDefaultCredentialsProvider
(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProvider
instance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuilder
setDefaultHeaders
(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Assigns default request header values.final HttpAsyncClientBuilder
setDefaultRequestConfig
(RequestConfig config) Assigns defaultRequestConfig
instance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuilder
setH2Config
(org.apache.hc.core5.http2.config.H2Config h2Config) SetsH2Config
configuration.final HttpAsyncClientBuilder
setHttp1Config
(org.apache.hc.core5.http.config.Http1Config h1Config) SetsHttp1Config
configuration.final HttpAsyncClientBuilder
setIOReactorConfig
(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig) SetsIOReactorConfig
configuration.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.final HttpAsyncClientBuilder
setIoSessionDecorator
(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator) Sets theIOSession
Decorator
that will be use with the client's IOReactor.final HttpAsyncClientBuilder
setIOSessionListener
(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener) SetsIOSessionListener
listener.final HttpAsyncClientBuilder
setKeepAliveStrategy
(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategy
instance.final HttpAsyncClientBuilder
setProxy
(org.apache.hc.core5.http.HttpHost proxy) Assigns default proxy value.final HttpAsyncClientBuilder
setProxyAuthenticationStrategy
(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategy
instance for proxy authentication.final HttpAsyncClientBuilder
setProxySelector
(ProxySelector proxySelector) Sets theProxySelector
that will be used to select the proxies to be used for establishing HTTP connections.setRedirectStrategy
(RedirectStrategy redirectStrategy) AssignsRedirectStrategy
instance.final HttpAsyncClientBuilder
setRetryStrategy
(HttpRequestRetryStrategy retryStrategy) AssignsHttpRequestRetryStrategy
instance.final HttpAsyncClientBuilder
setRoutePlanner
(HttpRoutePlanner routePlanner) AssignsHttpRoutePlanner
instance.final HttpAsyncClientBuilder
setSchemePortResolver
(SchemePortResolver schemePortResolver) AssignsSchemePortResolver
instance.final HttpAsyncClientBuilder
setTargetAuthenticationStrategy
(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategy
instance for target host authentication.final HttpAsyncClientBuilder
setThreadFactory
(ThreadFactory threadFactory) AssignsThreadFactory
instance.final HttpAsyncClientBuilder
setUserAgent
(String userAgent) AssignsUser-Agent
value.final HttpAsyncClientBuilder
setUserTokenHandler
(UserTokenHandler userTokenHandler) AssignsUserTokenHandler
instance.final HttpAsyncClientBuilder
setVersionPolicy
(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy) Deprecated.UseTlsConfig
and connection manager methodsfinal HttpAsyncClientBuilder
Use 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
-
-
Constructor Details
-
HttpAsyncClientBuilder
protected HttpAsyncClientBuilder()
-
-
Method Details
-
create
-
setVersionPolicy
@Deprecated public final HttpAsyncClientBuilder setVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy) Deprecated.UseTlsConfig
and connection manager methodsSets HTTP protocol version policy. -
setHttp1Config
public final HttpAsyncClientBuilder setHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config) SetsHttp1Config
configuration. -
setH2Config
SetsH2Config
configuration. -
setConnectionManager
AssignsAsyncClientConnectionManager
instance. -
setIOReactorConfig
public final HttpAsyncClientBuilder setIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig) SetsIOReactorConfig
configuration. -
setIOSessionListener
public final HttpAsyncClientBuilder setIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener) SetsIOSessionListener
listener.- 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.- Since:
- 5.1
-
setCharCodingConfig
public final HttpAsyncClientBuilder setCharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig) SetsCharCodingConfig
configuration. -
setConnectionReuseStrategy
public final HttpAsyncClientBuilder setConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategy
instance.Please note this strategy applies to HTTP/1.0 and HTTP/1.1 connections only
-
setKeepAliveStrategy
public final HttpAsyncClientBuilder setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategy
instance. -
setUserTokenHandler
AssignsUserTokenHandler
instance.Please note this value can be overridden by the
disableConnectionState()
method. -
setTargetAuthenticationStrategy
public final HttpAsyncClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategy
instance for target host authentication. -
setProxyAuthenticationStrategy
public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategy
instance for proxy authentication. -
setIoSessionDecorator
public final HttpAsyncClientBuilder setIoSessionDecorator(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator) Sets theIOSession
Decorator
that will be use with the client's IOReactor.- 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. -
addResponseInterceptorLast
public final HttpAsyncClientBuilder addResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list. -
addExecInterceptorBefore
public final HttpAsyncClientBuilder addExecInterceptorBefore(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor. -
addExecInterceptorAfter
public final HttpAsyncClientBuilder addExecInterceptorAfter(String existing, String name, AsyncExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name. -
replaceExecInterceptor
public final HttpAsyncClientBuilder replaceExecInterceptor(String existing, AsyncExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor. -
addExecInterceptorFirst
public final HttpAsyncClientBuilder addExecInterceptorFirst(String name, AsyncExecChainHandler interceptor) Add an interceptor to the head of the processing list. -
addExecInterceptorLast
public final HttpAsyncClientBuilder addExecInterceptorLast(String name, AsyncExecChainHandler interceptor) Add an interceptor to the tail of the processing list. -
addRequestInterceptorFirst
public final HttpAsyncClientBuilder addRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list. -
addRequestInterceptorLast
public final HttpAsyncClientBuilder addRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list. -
setRetryStrategy
AssignsHttpRequestRetryStrategy
instance.Please note this value can be overridden by the
disableAutomaticRetries()
method. -
setRedirectStrategy
AssignsRedirectStrategy
instance.Please note this value can be overridden by the
disableRedirectHandling()
method. -
setSchemePortResolver
AssignsSchemePortResolver
instance. -
setThreadFactory
AssignsThreadFactory
instance. -
setUserAgent
AssignsUser-Agent
value. -
setDefaultHeaders
public final HttpAsyncClientBuilder setDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Assigns default request header values. -
setProxySelector
Sets theProxySelector
that 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
- theProxySelector
to be used, or null to use the default system proxy selector.- Returns:
- this
HttpAsyncClientBuilder
instance, to allow for method chaining.
-
setProxy
Assigns default proxy value.Please note this value can be overridden by the
setRoutePlanner(HttpRoutePlanner)
method. -
setRoutePlanner
AssignsHttpRoutePlanner
instance. -
setDefaultCredentialsProvider
public final HttpAsyncClientBuilder setDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProvider
instance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultAuthSchemeRegistry
public final HttpAsyncClientBuilder setDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> authSchemeRegistry) Assigns defaultAuthScheme
registry which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCookieSpecRegistry
public final HttpAsyncClientBuilder setDefaultCookieSpecRegistry(org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> cookieSpecRegistry) Assigns defaultCookieSpec
registry which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCookieStore
Assigns defaultCookieStore
instance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultRequestConfig
Assigns defaultRequestConfig
instance which will be used for request execution if not explicitly set in the client execution context. -
useSystemProperties
Use system properties when creating and configuring default implementations. -
disableConnectionState
Disables connection state tracking. -
disableRedirectHandling
Disables automatic redirect handling. -
disableAutomaticRetries
Disables automatic request recovery and re-execution. -
disableCookieManagement
Disables state (cookie) management. -
disableAuthCaching
Disables authentication scheme caching. -
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.
- 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.- See Also:
-
customizeExecChain
@Internal protected void customizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<AsyncExecChainHandler> execChainDefinition) Request exec chain customization and extension.For internal use.
-
addCloseable
Adds to the list ofCloseable
resources to be managed by the client.For internal use.
-
build
-
getProperty
-