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 booleanprivate org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> private CookieStoreprivate CredentialsProviderprivate Collection<? extends org.apache.hc.core5.http.Header> private RequestConfigprivate 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 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()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.final HttpAsyncClientBuilderDisables state (cookie) management.final HttpAsyncClientBuilderDisables automatic redirect handling.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) AssignsAsyncClientConnectionManagerinstance.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) AssignsConnectionReuseStrategyinstance.final HttpAsyncClientBuildersetDefaultAuthSchemeRegistry(org.apache.hc.core5.http.config.Lookup<AuthSchemeFactory> authSchemeRegistry) Assigns 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) Assigns defaultCookieSpecregistry which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultCookieStore(CookieStore cookieStore) Assigns defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context.final HttpAsyncClientBuildersetDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Assigns 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) Assigns default request header values.final HttpAsyncClientBuildersetDefaultRequestConfig(RequestConfig config) Assigns defaultRequestConfiginstance which will be used for request execution if not explicitly set in the client execution context.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) AssignsConnectionKeepAliveStrategyinstance.final HttpAsyncClientBuildersetProxy(org.apache.hc.core5.http.HttpHost proxy) Assigns default proxy value.final HttpAsyncClientBuildersetProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategyinstance 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) AssignsRedirectStrategyinstance.final HttpAsyncClientBuildersetRetryStrategy(HttpRequestRetryStrategy retryStrategy) AssignsHttpRequestRetryStrategyinstance.final HttpAsyncClientBuildersetRoutePlanner(HttpRoutePlanner routePlanner) AssignsHttpRoutePlannerinstance.final HttpAsyncClientBuildersetSchemePortResolver(SchemePortResolver schemePortResolver) AssignsSchemePortResolverinstance.final HttpAsyncClientBuildersetTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategyinstance for target host authentication.final HttpAsyncClientBuildersetThreadFactory(ThreadFactory threadFactory) AssignsThreadFactoryinstance.final HttpAsyncClientBuildersetUserAgent(String userAgent) AssignsUser-Agentvalue.final HttpAsyncClientBuildersetUserTokenHandler(UserTokenHandler userTokenHandler) AssignsUserTokenHandlerinstance.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
-
-
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. -
setHttp1Config
public final HttpAsyncClientBuilder setHttp1Config(org.apache.hc.core5.http.config.Http1Config h1Config) SetsHttp1Configconfiguration. -
setH2Config
SetsH2Configconfiguration. -
setConnectionManager
AssignsAsyncClientConnectionManagerinstance. -
setIOReactorConfig
public final HttpAsyncClientBuilder setIOReactorConfig(org.apache.hc.core5.reactor.IOReactorConfig ioReactorConfig) SetsIOReactorConfigconfiguration. -
setIOSessionListener
public final HttpAsyncClientBuilder setIOSessionListener(org.apache.hc.core5.reactor.IOSessionListener ioSessionListener) SetsIOSessionListenerlistener.- 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) SetsCharCodingConfigconfiguration. -
setConnectionReuseStrategy
public final HttpAsyncClientBuilder setConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategyinstance.Please note this strategy applies to HTTP/1.0 and HTTP/1.1 connections only
-
setKeepAliveStrategy
public final HttpAsyncClientBuilder setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategyinstance. -
setUserTokenHandler
AssignsUserTokenHandlerinstance.Please note this value can be overridden by the
disableConnectionState()method. -
setTargetAuthenticationStrategy
public final HttpAsyncClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategyinstance for target host authentication. -
setProxyAuthenticationStrategy
public final HttpAsyncClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategyinstance for proxy authentication. -
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.- 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
AssignsHttpRequestRetryStrategyinstance.Please note this value can be overridden by the
disableAutomaticRetries()method. -
setRedirectStrategy
AssignsRedirectStrategyinstance.Please note this value can be overridden by the
disableRedirectHandling()method. -
setSchemePortResolver
AssignsSchemePortResolverinstance. -
setThreadFactory
AssignsThreadFactoryinstance. -
setUserAgent
AssignsUser-Agentvalue. -
setDefaultHeaders
public final HttpAsyncClientBuilder setDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Assigns default request header values. -
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
HttpAsyncClientBuilderinstance, to allow for method chaining.
-
setProxy
Assigns default proxy value.Please note this value can be overridden by the
setRoutePlanner(HttpRoutePlanner)method. -
setRoutePlanner
AssignsHttpRoutePlannerinstance. -
setDefaultCredentialsProvider
public final HttpAsyncClientBuilder setDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProviderinstance 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 defaultAuthSchemeregistry 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 defaultCookieSpecregistry which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCookieStore
Assigns defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultRequestConfig
Assigns defaultRequestConfiginstance 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 ofCloseableresources to be managed by the client.For internal use.
-
build
-
getProperty
-