public class HttpAsyncClientBuilder extends Object
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()
.
Please note that some settings used by this class can be mutually
exclusive and may not apply when building CloseableHttpAsyncClient
instances.
Modifier | Constructor and Description |
---|---|
protected |
HttpAsyncClientBuilder() |
Modifier and Type | Method and Description |
---|---|
protected void |
addCloseable(Closeable closeable)
Adds to the list of
Closeable resources to be managed by the client. |
HttpAsyncClientBuilder |
addExecInterceptorAfter(String existing,
String name,
AsyncExecChainHandler interceptor)
Adds this execution interceptor after interceptor with the given name.
|
HttpAsyncClientBuilder |
addExecInterceptorBefore(String existing,
String name,
AsyncExecChainHandler interceptor)
Adds this execution interceptor before an existing interceptor.
|
HttpAsyncClientBuilder |
addExecInterceptorFirst(String name,
AsyncExecChainHandler interceptor)
Add an interceptor to the head of the processing list.
|
HttpAsyncClientBuilder |
addExecInterceptorLast(String name,
AsyncExecChainHandler interceptor)
Add an interceptor to the tail of the processing list.
|
HttpAsyncClientBuilder |
addRequestInterceptorFirst(HttpRequestInterceptor interceptor)
Adds this protocol interceptor to the head of the protocol processing list.
|
HttpAsyncClientBuilder |
addRequestInterceptorLast(HttpRequestInterceptor interceptor)
Adds this protocol interceptor to the tail of the protocol processing list.
|
HttpAsyncClientBuilder |
addResponseInterceptorFirst(HttpResponseInterceptor interceptor)
Adds this protocol interceptor to the head of the protocol processing list.
|
HttpAsyncClientBuilder |
addResponseInterceptorLast(HttpResponseInterceptor interceptor)
Adds this protocol interceptor to the tail of the protocol processing list.
|
CloseableHttpAsyncClient |
build() |
static HttpAsyncClientBuilder |
create() |
protected void |
customizeExecChain(NamedElementChain<AsyncExecChainHandler> execChainDefinition)
Request exec chain customization and extension.
|
HttpAsyncClientBuilder |
disableAuthCaching()
Disables authentication scheme caching.
|
HttpAsyncClientBuilder |
disableAutomaticRetries()
Disables automatic request recovery and re-execution.
|
HttpAsyncClientBuilder |
disableConnectionState()
Disables connection state tracking.
|
HttpAsyncClientBuilder |
disableCookieManagement()
Disables state (cookie) management.
|
HttpAsyncClientBuilder |
disableRedirectHandling()
Disables automatic redirect handling.
|
HttpAsyncClientBuilder |
evictExpiredConnections()
Makes this instance of HttpClient proactively evict expired connections from the
connection pool using a background thread.
|
HttpAsyncClientBuilder |
evictIdleConnections(TimeValue maxIdleTime)
Makes this instance of HttpClient proactively evict idle connections from the
connection pool using a background thread.
|
HttpAsyncClientBuilder |
replaceExecInterceptor(String existing,
AsyncExecChainHandler interceptor)
Replace an existing interceptor with the given name with new interceptor.
|
HttpAsyncClientBuilder |
setCharCodingConfig(CharCodingConfig charCodingConfig)
Sets
CharCodingConfig configuration. |
HttpAsyncClientBuilder |
setConnectionManager(AsyncClientConnectionManager connManager)
Assigns
AsyncClientConnectionManager instance. |
HttpAsyncClientBuilder |
setConnectionManagerShared(boolean shared)
Defines the connection manager is to be shared by multiple
client instances.
|
HttpAsyncClientBuilder |
setConnectionReuseStrategy(ConnectionReuseStrategy reuseStrategy)
Assigns
ConnectionReuseStrategy instance. |
HttpAsyncClientBuilder |
setDefaultAuthSchemeRegistry(Lookup<AuthSchemeFactory> authSchemeRegistry)
Assigns default
AuthScheme registry which will
be used for request execution if not explicitly set in the client execution
context. |
HttpAsyncClientBuilder |
setDefaultCookieSpecRegistry(Lookup<CookieSpecFactory> cookieSpecRegistry)
Assigns default
CookieSpec registry
which will be used for request execution if not explicitly set in the client
execution context. |
HttpAsyncClientBuilder |
setDefaultCookieStore(CookieStore cookieStore)
Assigns default
CookieStore instance which will be used for
request execution if not explicitly set in the client execution context. |
HttpAsyncClientBuilder |
setDefaultCredentialsProvider(CredentialsProvider credentialsProvider)
Assigns default
CredentialsProvider instance which will be used
for request execution if not explicitly set in the client execution
context. |
HttpAsyncClientBuilder |
setDefaultHeaders(Collection<? extends Header> defaultHeaders)
Assigns default request header values.
|
HttpAsyncClientBuilder |
setDefaultRequestConfig(RequestConfig config)
Assigns default
RequestConfig instance which will be used
for request execution if not explicitly set in the client execution
context. |
HttpAsyncClientBuilder |
setH2Config(H2Config h2Config)
Sets
H2Config configuration. |
HttpAsyncClientBuilder |
setHttp1Config(Http1Config h1Config)
Sets
Http1Config configuration. |
HttpAsyncClientBuilder |
setIOReactorConfig(IOReactorConfig ioReactorConfig)
Sets
IOReactorConfig configuration. |
HttpAsyncClientBuilder |
setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
Assigns
ConnectionKeepAliveStrategy instance. |
HttpAsyncClientBuilder |
setProxy(HttpHost proxy)
Assigns default proxy value.
|
HttpAsyncClientBuilder |
setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy)
Assigns
AuthenticationStrategy instance for proxy
authentication. |
HttpAsyncClientBuilder |
setRedirectStrategy(RedirectStrategy redirectStrategy)
Assigns
RedirectStrategy instance. |
HttpAsyncClientBuilder |
setRetryStrategy(HttpRequestRetryStrategy retryStrategy)
Assigns
HttpRequestRetryStrategy instance. |
HttpAsyncClientBuilder |
setRoutePlanner(HttpRoutePlanner routePlanner)
Assigns
HttpRoutePlanner instance. |
HttpAsyncClientBuilder |
setSchemePortResolver(SchemePortResolver schemePortResolver)
Assigns
SchemePortResolver instance. |
HttpAsyncClientBuilder |
setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy)
Assigns
AuthenticationStrategy instance for target
host authentication. |
HttpAsyncClientBuilder |
setThreadFactory(ThreadFactory threadFactory)
Assigns
ThreadFactory instance. |
HttpAsyncClientBuilder |
setUserAgent(String userAgent)
Assigns
User-Agent value. |
HttpAsyncClientBuilder |
setUserTokenHandler(UserTokenHandler userTokenHandler)
Assigns
UserTokenHandler instance. |
HttpAsyncClientBuilder |
setVersionPolicy(HttpVersionPolicy versionPolicy)
Sets HTTP protocol version policy.
|
HttpAsyncClientBuilder |
useSystemProperties()
Use system properties when creating and configuring default
implementations.
|
@Internal protected void addCloseable(Closeable closeable)
Closeable
resources to be managed by the client.
For internal use.
public final HttpAsyncClientBuilder addExecInterceptorAfter(String existing, String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorBefore(String existing, String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorFirst(String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorLast(String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addRequestInterceptorFirst(HttpRequestInterceptor interceptor)
public final HttpAsyncClientBuilder addRequestInterceptorLast(HttpRequestInterceptor interceptor)
public final HttpAsyncClientBuilder addResponseInterceptorFirst(HttpResponseInterceptor interceptor)
public final HttpAsyncClientBuilder addResponseInterceptorLast(HttpResponseInterceptor interceptor)
public CloseableHttpAsyncClient build()
public static HttpAsyncClientBuilder create()
@Internal protected void customizeExecChain(NamedElementChain<AsyncExecChainHandler> execChainDefinition)
For internal use.
public final HttpAsyncClientBuilder disableAuthCaching()
public final HttpAsyncClientBuilder disableAutomaticRetries()
public final HttpAsyncClientBuilder disableConnectionState()
public final HttpAsyncClientBuilder disableCookieManagement()
public final HttpAsyncClientBuilder disableRedirectHandling()
public final HttpAsyncClientBuilder evictExpiredConnections()
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 configuted to use a shared connection manager.
public final HttpAsyncClientBuilder evictIdleConnections(TimeValue maxIdleTime)
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 configuted to use a shared connection manager.
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.setConnectionManagerShared(boolean)
,
ConnPoolControl.closeIdle(TimeValue)
public final HttpAsyncClientBuilder replaceExecInterceptor(String existing, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder setCharCodingConfig(CharCodingConfig charCodingConfig)
CharCodingConfig
configuration.public final HttpAsyncClientBuilder setConnectionManager(AsyncClientConnectionManager connManager)
AsyncClientConnectionManager
instance.public final HttpAsyncClientBuilder setConnectionManagerShared(boolean shared)
If the connection manager is shared its life-cycle is expected to be managed by the caller and it will not be shut down if the client is closed.
shared
- defines whether or not the connection manager can be shared
by multiple clients.public final HttpAsyncClientBuilder setConnectionReuseStrategy(ConnectionReuseStrategy reuseStrategy)
ConnectionReuseStrategy
instance.
Please note this strategy applies to HTTP/1.0 and HTTP/1.1 connections only
public final HttpAsyncClientBuilder setDefaultAuthSchemeRegistry(Lookup<AuthSchemeFactory> authSchemeRegistry)
AuthScheme
registry which will
be used for request execution if not explicitly set in the client execution
context.public final HttpAsyncClientBuilder setDefaultCookieSpecRegistry(Lookup<CookieSpecFactory> cookieSpecRegistry)
CookieSpec
registry
which will be used for request execution if not explicitly set in the client
execution context.public final HttpAsyncClientBuilder setDefaultCookieStore(CookieStore cookieStore)
CookieStore
instance which will be used for
request execution if not explicitly set in the client execution context.public final HttpAsyncClientBuilder setDefaultCredentialsProvider(CredentialsProvider credentialsProvider)
CredentialsProvider
instance which will be used
for request execution if not explicitly set in the client execution
context.public final HttpAsyncClientBuilder setDefaultHeaders(Collection<? extends Header> defaultHeaders)
public final HttpAsyncClientBuilder setDefaultRequestConfig(RequestConfig config)
RequestConfig
instance which will be used
for request execution if not explicitly set in the client execution
context.public final HttpAsyncClientBuilder setH2Config(H2Config h2Config)
H2Config
configuration.public final HttpAsyncClientBuilder setHttp1Config(Http1Config h1Config)
Http1Config
configuration.public final HttpAsyncClientBuilder setIOReactorConfig(IOReactorConfig ioReactorConfig)
IOReactorConfig
configuration.public final HttpAsyncClientBuilder setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
ConnectionKeepAliveStrategy
instance.public final HttpAsyncClientBuilder setProxy(HttpHost proxy)
Please note this value can be overridden by the setRoutePlanner(
HttpRoutePlanner)
method.
public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy)
AuthenticationStrategy
instance for proxy
authentication.public HttpAsyncClientBuilder setRedirectStrategy(RedirectStrategy redirectStrategy)
RedirectStrategy
instance.
Please note this value can be overridden by the disableRedirectHandling()
method.
public final HttpAsyncClientBuilder setRetryStrategy(HttpRequestRetryStrategy retryStrategy)
HttpRequestRetryStrategy
instance.
Please note this value can be overridden by the disableAutomaticRetries()
method.
public final HttpAsyncClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner)
HttpRoutePlanner
instance.public final HttpAsyncClientBuilder setSchemePortResolver(SchemePortResolver schemePortResolver)
SchemePortResolver
instance.public final HttpAsyncClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy)
AuthenticationStrategy
instance for target
host authentication.public final HttpAsyncClientBuilder setThreadFactory(ThreadFactory threadFactory)
ThreadFactory
instance.public final HttpAsyncClientBuilder setUserAgent(String userAgent)
User-Agent
value.public final HttpAsyncClientBuilder setUserTokenHandler(UserTokenHandler userTokenHandler)
UserTokenHandler
instance.
Please note this value can be overridden by the disableConnectionState()
method.
public final HttpAsyncClientBuilder setVersionPolicy(HttpVersionPolicy versionPolicy)
public final HttpAsyncClientBuilder useSystemProperties()