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(org.apache.hc.core5.http.HttpRequestInterceptor interceptor)
Adds this protocol interceptor to the head of the protocol processing list.
|
HttpAsyncClientBuilder |
addRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor)
Adds this protocol interceptor to the tail of the protocol processing list.
|
HttpAsyncClientBuilder |
addResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor)
Adds this protocol interceptor to the head of the protocol processing list.
|
HttpAsyncClientBuilder |
addResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor)
Adds this protocol interceptor to the tail of the protocol processing list.
|
CloseableHttpAsyncClient |
build() |
static HttpAsyncClientBuilder |
create() |
protected void |
customizeExecChain(org.apache.hc.core5.http.config.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(org.apache.hc.core5.util.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(org.apache.hc.core5.http.config.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(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy)
Assigns
ConnectionReuseStrategy instance. |
HttpAsyncClientBuilder |
setDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.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(org.apache.hc.core5.http.config.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 org.apache.hc.core5.http.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(org.apache.hc.core5.http2.config.H2Config h2Config)
Sets
H2Config configuration. |
HttpAsyncClientBuilder |
setHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config)
Sets
Http1Config configuration. |
HttpAsyncClientBuilder |
setIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig)
Sets
IOReactorConfig configuration. |
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.
|
HttpAsyncClientBuilder |
setIoSessionDecorator(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator)
Sets the
IOSession Decorator that will be use with the client's IOReactor. |
HttpAsyncClientBuilder |
setIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener)
Sets
IOSessionListener listener. |
HttpAsyncClientBuilder |
setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
Assigns
ConnectionKeepAliveStrategy instance. |
HttpAsyncClientBuilder |
setProxy(org.apache.hc.core5.http.HttpHost proxy)
Assigns default proxy value.
|
HttpAsyncClientBuilder |
setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy)
Assigns
AuthenticationStrategy instance for proxy
authentication. |
HttpAsyncClientBuilder |
setProxySelector(ProxySelector proxySelector)
Sets the
ProxySelector that will be used to select the proxies
to be used for establishing HTTP connections. |
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(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy)
Deprecated.
Use
TlsConfig and connection manager methods |
HttpAsyncClientBuilder |
useSystemProperties()
Use system properties when creating and configuring default
implementations.
|
public static HttpAsyncClientBuilder create()
@Deprecated public final HttpAsyncClientBuilder setVersionPolicy(org.apache.hc.core5.http2.HttpVersionPolicy versionPolicy)
TlsConfig
and connection manager methodspublic final HttpAsyncClientBuilder setHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config)
Http1Config
configuration.public final HttpAsyncClientBuilder setH2Config(org.apache.hc.core5.http2.config.H2Config h2Config)
H2Config
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 setIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig)
IOReactorConfig
configuration.public final HttpAsyncClientBuilder setIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener)
IOSessionListener
listener.public final HttpAsyncClientBuilder setIoReactorExceptionCallback(org.apache.hc.core5.function.Callback<Exception> ioReactorExceptionCallback)
public final HttpAsyncClientBuilder setCharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig charCodingConfig)
CharCodingConfig
configuration.public final HttpAsyncClientBuilder setConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy)
ConnectionReuseStrategy
instance.
Please note this strategy applies to HTTP/1.0 and HTTP/1.1 connections only
public final HttpAsyncClientBuilder setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
ConnectionKeepAliveStrategy
instance.public final HttpAsyncClientBuilder setUserTokenHandler(UserTokenHandler userTokenHandler)
UserTokenHandler
instance.
Please note this value can be overridden by the disableConnectionState()
method.
public final HttpAsyncClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy)
AuthenticationStrategy
instance for target
host authentication.public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy)
AuthenticationStrategy
instance for proxy
authentication.public final HttpAsyncClientBuilder setIoSessionDecorator(org.apache.hc.core5.function.Decorator<org.apache.hc.core5.reactor.IOSession> ioSessionDecorator)
IOSession
Decorator
that will be use with the client's IOReactor.public final HttpAsyncClientBuilder addResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor)
public final HttpAsyncClientBuilder addResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor)
public final HttpAsyncClientBuilder addExecInterceptorBefore(String existing, String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorAfter(String existing, String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder replaceExecInterceptor(String existing, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorFirst(String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addExecInterceptorLast(String name, AsyncExecChainHandler interceptor)
public final HttpAsyncClientBuilder addRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor)
public final HttpAsyncClientBuilder addRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor)
public final HttpAsyncClientBuilder setRetryStrategy(HttpRequestRetryStrategy retryStrategy)
HttpRequestRetryStrategy
instance.
Please note this value can be overridden by the disableAutomaticRetries()
method.
public HttpAsyncClientBuilder setRedirectStrategy(RedirectStrategy redirectStrategy)
RedirectStrategy
instance.
Please note this value can be overridden by the disableRedirectHandling()
method.
public final HttpAsyncClientBuilder setSchemePortResolver(SchemePortResolver schemePortResolver)
SchemePortResolver
instance.public final HttpAsyncClientBuilder setThreadFactory(ThreadFactory threadFactory)
ThreadFactory
instance.public final HttpAsyncClientBuilder setUserAgent(String userAgent)
User-Agent
value.public final HttpAsyncClientBuilder setDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders)
public final HttpAsyncClientBuilder setProxySelector(ProxySelector proxySelector)
ProxySelector
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.proxySelector
- the ProxySelector
to be used, or null to use
the default system proxy selector.HttpAsyncClientBuilder
instance, to allow for method chaining.public final HttpAsyncClientBuilder setProxy(org.apache.hc.core5.http.HttpHost proxy)
Please note this value can be overridden by the setRoutePlanner(
HttpRoutePlanner)
method.
public final HttpAsyncClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner)
HttpRoutePlanner
instance.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 setDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.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(org.apache.hc.core5.http.config.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 setDefaultRequestConfig(RequestConfig config)
RequestConfig
instance which will be used
for request execution if not explicitly set in the client execution
context.public final HttpAsyncClientBuilder useSystemProperties()
public final HttpAsyncClientBuilder disableConnectionState()
public final HttpAsyncClientBuilder disableRedirectHandling()
public final HttpAsyncClientBuilder disableAutomaticRetries()
public final HttpAsyncClientBuilder disableCookieManagement()
public final HttpAsyncClientBuilder disableAuthCaching()
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 configured to use a shared connection manager.
setConnectionManagerShared(boolean)
,
ConnPoolControl.closeExpired()
public final HttpAsyncClientBuilder evictIdleConnections(org.apache.hc.core5.util.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 configured 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)
@Internal protected void customizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<AsyncExecChainHandler> execChainDefinition)
For internal use.
@Internal protected void addCloseable(Closeable closeable)
Closeable
resources to be managed by the client.
For internal use.
public CloseableHttpAsyncClient build()
Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.