Class HttpClientBuilder
- Direct Known Subclasses:
CachingHttpClientBuilder
CloseableHttpClient instances.
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
- https.proxyUser
- http.proxyUser
- https.proxyPassword
- http.proxyPassword
- http.keepAlive
- http.agent
Please note that some settings used by this class can be mutually
exclusive and may not apply when building CloseableHttpClient
instances.
- Since:
- 4.3
-
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 BackoffManagerprivate ConnectionBackoffStrategyprivate booleanprivate HttpClientConnectionManagerprivate booleanprivate booleanprivate LinkedHashMap<String, InputStreamFactory> private booleanprivate org.apache.hc.core5.http.config.Lookup<CookieSpecFactory> private CookieStoreprivate CredentialsProviderprivate Collection<? extends org.apache.hc.core5.http.Header> private RequestConfigprivate booleanprivate booleanprivate booleanprivate ConnectionKeepAliveStrategyprivate org.apache.hc.core5.util.TimeValueprivate org.apache.hc.core5.http.HttpHostprivate AuthenticationStrategyprivate ProxySelectorprivate booleanprivate RedirectStrategyprivate org.apache.hc.core5.http.impl.io.HttpRequestExecutorprivate HttpRequestRetryStrategyprivate org.apache.hc.core5.http.ConnectionReuseStrategyprivate HttpRoutePlannerprivate SchemePortResolverprivate booleanprivate AuthenticationStrategyprivate 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 HttpClientBuilderaddExecInterceptorAfter(String existing, String name, ExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name.final HttpClientBuilderaddExecInterceptorBefore(String existing, String name, ExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor.final HttpClientBuilderaddExecInterceptorFirst(String name, ExecChainHandler interceptor) Add an interceptor to the head of the processing list.final HttpClientBuilderaddExecInterceptorLast(String name, ExecChainHandler interceptor) Add an interceptor to the tail of the processing list.final HttpClientBuilderaddRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilderaddRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.final HttpClientBuilderaddResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilderaddResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list.build()static HttpClientBuildercreate()protected voidcustomizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<ExecChainHandler> execChainDefinition) Request exec chain customization and extension.final HttpClientBuilderDisables authentication scheme caching.final HttpClientBuilderDisables automatic request recovery and re-execution.final HttpClientBuilderDisables connection state tracking.final HttpClientBuilderDisables automatic content decompression.final HttpClientBuilderDisables state (cookie) management.final HttpClientBuilderDisables the default user agent set by this builder if none has been provided by the user.final HttpClientBuilderDisables automatic redirect handling.final HttpClientBuilderMakes this instance of HttpClient proactively evict expired connections from the connection pool using a background thread.final HttpClientBuilderevictIdleConnections(org.apache.hc.core5.util.TimeValue maxIdleTime) Makes this instance of HttpClient proactively evict idle connections from the connection pool using a background thread.final HttpClientBuilderreplaceExecInterceptor(String existing, ExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor.final HttpClientBuildersetBackoffManager(BackoffManager backoffManager) AssignsBackoffManagerinstance.final HttpClientBuildersetConnectionBackoffStrategy(ConnectionBackoffStrategy connectionBackoffStrategy) AssignsConnectionBackoffStrategyinstance.final HttpClientBuildersetConnectionManager(HttpClientConnectionManager connManager) AssignsHttpClientConnectionManagerinstance.final HttpClientBuildersetConnectionManagerShared(boolean shared) Defines the connection manager is to be shared by multiple client instances.final HttpClientBuildersetConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategyinstance.final HttpClientBuildersetContentDecoderRegistry(LinkedHashMap<String, InputStreamFactory> contentDecoderMap) Assigns a map ofInputStreamFactorys to be used for automatic content decompression.final HttpClientBuildersetDefaultAuthSchemeRegistry(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 HttpClientBuildersetDefaultCookieSpecRegistry(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 HttpClientBuildersetDefaultCookieStore(CookieStore cookieStore) Assigns defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuildersetDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProviderinstance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuildersetDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Assigns default request header values.final HttpClientBuildersetDefaultRequestConfig(RequestConfig config) Assigns defaultRequestConfiginstance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuildersetKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategyinstance.final HttpClientBuildersetProxy(org.apache.hc.core5.http.HttpHost proxy) Assigns default proxy value.final HttpClientBuildersetProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategyinstance for proxy authentication.final HttpClientBuildersetProxySelector(ProxySelector proxySelector) Sets theProxySelectorthat will be used to select the proxies to be used for establishing HTTP connections.final HttpClientBuildersetRedirectStrategy(RedirectStrategy redirectStrategy) AssignsRedirectStrategyinstance.final HttpClientBuildersetRequestExecutor(org.apache.hc.core5.http.impl.io.HttpRequestExecutor requestExec) AssignsHttpRequestExecutorinstance.final HttpClientBuildersetRetryStrategy(HttpRequestRetryStrategy retryStrategy) AssignsHttpRequestRetryStrategyinstance.final HttpClientBuildersetRoutePlanner(HttpRoutePlanner routePlanner) AssignsHttpRoutePlannerinstance.final HttpClientBuildersetSchemePortResolver(SchemePortResolver schemePortResolver) AssignsSchemePortResolverinstance.final HttpClientBuildersetTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategyinstance for target host authentication.final HttpClientBuildersetUserAgent(String userAgent) AssignsUser-Agentvalue.final HttpClientBuildersetUserTokenHandler(UserTokenHandler userTokenHandler) AssignsUserTokenHandlerinstance.final HttpClientBuilderUse system properties when creating and configuring default implementations.
-
Field Details
-
requestExec
private org.apache.hc.core5.http.impl.io.HttpRequestExecutor requestExec -
connManager
-
schemePortResolver
-
reuseStrategy
private org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy -
keepAliveStrategy
-
targetAuthStrategy
-
proxyAuthStrategy
-
userTokenHandler
-
requestInterceptors
-
responseInterceptors
-
execInterceptors
-
retryStrategy
-
routePlanner
-
redirectStrategy
-
connectionBackoffStrategy
-
backoffManager
-
authSchemeRegistry
-
cookieSpecRegistry
-
contentDecoderMap
-
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 -
redirectHandlingDisabled
private boolean redirectHandlingDisabled -
automaticRetriesDisabled
private boolean automaticRetriesDisabled -
contentCompressionDisabled
private boolean contentCompressionDisabled -
cookieManagementDisabled
private boolean cookieManagementDisabled -
authCachingDisabled
private boolean authCachingDisabled -
connectionStateDisabled
private boolean connectionStateDisabled -
defaultUserAgentDisabled
private boolean defaultUserAgentDisabled -
proxySelector
-
closeables
-
-
Constructor Details
-
HttpClientBuilder
protected HttpClientBuilder()
-
-
Method Details
-
create
-
setRequestExecutor
public final HttpClientBuilder setRequestExecutor(org.apache.hc.core5.http.impl.io.HttpRequestExecutor requestExec) AssignsHttpRequestExecutorinstance. -
setConnectionManager
AssignsHttpClientConnectionManagerinstance. -
setConnectionReuseStrategy
public final HttpClientBuilder setConnectionReuseStrategy(org.apache.hc.core5.http.ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategyinstance. -
setKeepAliveStrategy
AssignsConnectionKeepAliveStrategyinstance. -
setTargetAuthenticationStrategy
public final HttpClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategyinstance for target host authentication. -
setProxyAuthenticationStrategy
public final HttpClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategyinstance for proxy authentication. -
setUserTokenHandler
AssignsUserTokenHandlerinstance.Please note this value can be overridden by the
disableConnectionState()method. -
disableConnectionState
Disables connection state tracking. -
setSchemePortResolver
AssignsSchemePortResolverinstance. -
setUserAgent
AssignsUser-Agentvalue. -
setDefaultHeaders
public final HttpClientBuilder setDefaultHeaders(Collection<? extends org.apache.hc.core5.http.Header> defaultHeaders) Assigns default request header values. -
addResponseInterceptorFirst
public final HttpClientBuilder addResponseInterceptorFirst(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list. -
addResponseInterceptorLast
public final HttpClientBuilder addResponseInterceptorLast(org.apache.hc.core5.http.HttpResponseInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list. -
addRequestInterceptorFirst
public final HttpClientBuilder addRequestInterceptorFirst(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the head of the protocol processing list. -
addRequestInterceptorLast
public final HttpClientBuilder addRequestInterceptorLast(org.apache.hc.core5.http.HttpRequestInterceptor interceptor) Adds this protocol interceptor to the tail of the protocol processing list. -
addExecInterceptorBefore
public final HttpClientBuilder addExecInterceptorBefore(String existing, String name, ExecChainHandler interceptor) Adds this execution interceptor before an existing interceptor. -
addExecInterceptorAfter
public final HttpClientBuilder addExecInterceptorAfter(String existing, String name, ExecChainHandler interceptor) Adds this execution interceptor after interceptor with the given name. -
replaceExecInterceptor
public final HttpClientBuilder replaceExecInterceptor(String existing, ExecChainHandler interceptor) Replace an existing interceptor with the given name with new interceptor. -
addExecInterceptorFirst
Add an interceptor to the head of the processing list. -
addExecInterceptorLast
Add an interceptor to the tail of the processing list. -
disableCookieManagement
Disables state (cookie) management. -
disableContentCompression
Disables automatic content decompression. -
disableAuthCaching
Disables authentication scheme caching. -
setRetryStrategy
AssignsHttpRequestRetryStrategyinstance.Please note this value can be overridden by the
disableAutomaticRetries()method. -
disableAutomaticRetries
Disables automatic request recovery and re-execution. -
setProxy
Assigns default proxy value.Please note this value can be overridden by the
setRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner)method. -
setRoutePlanner
AssignsHttpRoutePlannerinstance. -
setRedirectStrategy
AssignsRedirectStrategyinstance.Please note this value can be overridden by the
`disableRedirectHandling()method. -
disableRedirectHandling
Disables automatic redirect handling. -
setConnectionBackoffStrategy
public final HttpClientBuilder setConnectionBackoffStrategy(ConnectionBackoffStrategy connectionBackoffStrategy) AssignsConnectionBackoffStrategyinstance. -
setBackoffManager
AssignsBackoffManagerinstance. -
setDefaultCookieStore
Assigns defaultCookieStoreinstance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCredentialsProvider
public final HttpClientBuilder setDefaultCredentialsProvider(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProviderinstance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultAuthSchemeRegistry
public final HttpClientBuilder 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 HttpClientBuilder 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.- See Also:
-
setContentDecoderRegistry
public final HttpClientBuilder setContentDecoderRegistry(LinkedHashMap<String, InputStreamFactory> contentDecoderMap) Assigns a map ofInputStreamFactorys to be used for automatic content decompression. -
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. -
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.
- Since:
- 4.4
- See Also:
-
evictIdleConnections
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.- Since:
- 4.4
- See Also:
-
disableDefaultUserAgent
Disables the default user agent set by this builder if none has been provided by the user.- Since:
- 4.5.7
-
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
HttpClientBuilderinstance, to allow for method chaining.
-
customizeExecChain
@Internal protected void customizeExecChain(org.apache.hc.core5.http.config.NamedElementChain<ExecChainHandler> 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
-