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()
.
- ssl.TrustManagerFactory.algorithm
- javax.net.ssl.trustStoreType
- javax.net.ssl.trustStore
- javax.net.ssl.trustStoreProvider
- javax.net.ssl.trustStorePassword
- ssl.KeyManagerFactory.algorithm
- javax.net.ssl.keyStoreType
- javax.net.ssl.keyStore
- javax.net.ssl.keyStoreProvider
- javax.net.ssl.keyStorePassword
- https.protocols
- https.cipherSuites
- http.proxyHost
- http.proxyPort
- https.proxyHost
- https.proxyPort
- http.nonProxyHosts
- http.keepAlive
- http.maxConnections
- 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
-
Method Summary
Modifier and TypeMethodDescriptionfinal HttpClientBuilder
Adds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilder
Adds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilder
Adds this protocol interceptor to the tail of the protocol processing list.final HttpClientBuilder
Adds this protocol interceptor to the tail of the protocol processing list.build()
static HttpClientBuilder
create()
final HttpClientBuilder
Disables authentication scheme caching.final HttpClientBuilder
Disables automatic request recovery and re-execution.final HttpClientBuilder
Disables connection state tracking.final HttpClientBuilder
Disables automatic content decompression.final HttpClientBuilder
Disables state (cookie) management.final HttpClientBuilder
Disables the default user agent set by this builder if none has been provided by the user.final HttpClientBuilder
Disables automatic redirect handling.final HttpClientBuilder
Makes this instance of HttpClient proactively evict expired connections from the connection pool using a background thread.final HttpClientBuilder
evictIdleConnections
(long maxIdleTime, TimeUnit maxIdleTimeUnit) Makes this instance of HttpClient proactively evict idle connections from the connection pool using a background thread.final HttpClientBuilder
evictIdleConnections
(Long maxIdleTime, TimeUnit maxIdleTimeUnit) Deprecated.final HttpClientBuilder
setBackoffManager
(BackoffManager backoffManager) AssignsBackoffManager
instance.final HttpClientBuilder
setConnectionBackoffStrategy
(ConnectionBackoffStrategy connectionBackoffStrategy) AssignsConnectionBackoffStrategy
instance.final HttpClientBuilder
setConnectionManager
(HttpClientConnectionManager connManager) AssignsHttpClientConnectionManager
instance.final HttpClientBuilder
setConnectionManagerShared
(boolean shared) Defines the connection manager is to be shared by multiple client instances.final HttpClientBuilder
setConnectionReuseStrategy
(ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategy
instance.final HttpClientBuilder
setConnectionTimeToLive
(long connTimeToLive, TimeUnit connTimeToLiveTimeUnit) Sets maximum time to live for persistent connectionsfinal HttpClientBuilder
setContentDecoderRegistry
(Map<String, InputStreamFactory> contentDecoderMap) Assigns a map ofInputStreamFactory
s to be used for automatic content decompression.final HttpClientBuilder
setDefaultAuthSchemeRegistry
(Lookup<AuthSchemeProvider> authSchemeRegistry) Assigns defaultAuthScheme
registry which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilder
Assigns defaultConnectionConfig
.final HttpClientBuilder
setDefaultCookieSpecRegistry
(Lookup<CookieSpecProvider> cookieSpecRegistry) Assigns defaultCookieSpec
registry which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilder
setDefaultCookieStore
(CookieStore cookieStore) Assigns defaultCookieStore
instance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilder
setDefaultCredentialsProvider
(CredentialsProvider credentialsProvider) Assigns defaultCredentialsProvider
instance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilder
setDefaultHeaders
(Collection<? extends Header> defaultHeaders) Assigns default request header values.final HttpClientBuilder
setDefaultRequestConfig
(RequestConfig config) Assigns defaultRequestConfig
instance which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilder
setDefaultSocketConfig
(SocketConfig config) Assigns defaultSocketConfig
.final HttpClientBuilder
setDnsResolver
(DnsResolver dnsResolver) AssignsDnsResolver
instance.final HttpClientBuilder
setHostnameVerifier
(X509HostnameVerifier hostnameVerifier) Deprecated.(4.4)final HttpClientBuilder
setHttpProcessor
(HttpProcessor httpprocessor) AssignsHttpProcessor
instance.final HttpClientBuilder
setKeepAliveStrategy
(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategy
instance.final HttpClientBuilder
setMaxConnPerRoute
(int maxConnPerRoute) Assigns maximum connection per route value.final HttpClientBuilder
setMaxConnTotal
(int maxConnTotal) Assigns maximum total connection value.final HttpClientBuilder
Assigns default proxy value.final HttpClientBuilder
setProxyAuthenticationStrategy
(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategy
instance for proxy authentication.final HttpClientBuilder
setPublicSuffixMatcher
(PublicSuffixMatcher publicSuffixMatcher) Assigns file containing public suffix matcher.final HttpClientBuilder
setRedirectStrategy
(RedirectStrategy redirectStrategy) AssignsRedirectStrategy
instance.final HttpClientBuilder
setRequestExecutor
(HttpRequestExecutor requestExec) AssignsHttpRequestExecutor
instance.final HttpClientBuilder
setRetryHandler
(HttpRequestRetryHandler retryHandler) AssignsHttpRequestRetryHandler
instance.final HttpClientBuilder
setRoutePlanner
(HttpRoutePlanner routePlanner) AssignsHttpRoutePlanner
instance.final HttpClientBuilder
setSchemePortResolver
(SchemePortResolver schemePortResolver) AssignsSchemePortResolver
instance.final HttpClientBuilder
setServiceUnavailableRetryStrategy
(ServiceUnavailableRetryStrategy serviceUnavailStrategy) AssignsServiceUnavailableRetryStrategy
instance.final HttpClientBuilder
setSslcontext
(SSLContext sslcontext) Deprecated.(4.5) usesetSSLContext(SSLContext)
final HttpClientBuilder
setSSLContext
(SSLContext sslContext) AssignsSSLContext
instance.final HttpClientBuilder
setSSLHostnameVerifier
(HostnameVerifier hostnameVerifier) AssignsHostnameVerifier
instance.final HttpClientBuilder
setSSLSocketFactory
(LayeredConnectionSocketFactory sslSocketFactory) AssignsLayeredConnectionSocketFactory
instance.final HttpClientBuilder
setTargetAuthenticationStrategy
(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategy
instance for target host authentication.final HttpClientBuilder
setUserAgent
(String userAgent) AssignsUser-Agent
value.final HttpClientBuilder
setUserTokenHandler
(UserTokenHandler userTokenHandler) AssignsUserTokenHandler
instance.final HttpClientBuilder
Use system properties when creating and configuring default implementations.
-
Method Details
-
create
-
setRequestExecutor
AssignsHttpRequestExecutor
instance. -
setHostnameVerifier
@Deprecated public final HttpClientBuilder setHostnameVerifier(X509HostnameVerifier hostnameVerifier) Deprecated.(4.4)AssignsX509HostnameVerifier
instance.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
and thesetSSLSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory)
methods. -
setSSLHostnameVerifier
AssignsHostnameVerifier
instance.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
and thesetSSLSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory)
methods.- Since:
- 4.4
-
setPublicSuffixMatcher
Assigns file containing public suffix matcher. Instances of this class can be created withPublicSuffixMatcherLoader
.- Since:
- 4.4
- See Also:
-
setSslcontext
Deprecated.(4.5) usesetSSLContext(SSLContext)
AssignsSSLContext
instance.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
and thesetSSLSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory)
methods. -
setSSLContext
AssignsSSLContext
instance.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
and thesetSSLSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory)
methods. -
setSSLSocketFactory
AssignsLayeredConnectionSocketFactory
instance.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method. -
setMaxConnTotal
Assigns maximum total connection value.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method. -
setMaxConnPerRoute
Assigns maximum connection per route value.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method. -
setDefaultSocketConfig
Assigns defaultSocketConfig
.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method. -
setDefaultConnectionConfig
Assigns defaultConnectionConfig
.Please note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method. -
setConnectionTimeToLive
public final HttpClientBuilder setConnectionTimeToLive(long connTimeToLive, TimeUnit connTimeToLiveTimeUnit) Sets maximum time to live for persistent connectionsPlease note this value can be overridden by the
setConnectionManager(org.apache.http.conn.HttpClientConnectionManager)
method.- Since:
- 4.4
-
setConnectionManager
AssignsHttpClientConnectionManager
instance. -
setConnectionReuseStrategy
AssignsConnectionReuseStrategy
instance. -
setKeepAliveStrategy
AssignsConnectionKeepAliveStrategy
instance. -
setTargetAuthenticationStrategy
public final HttpClientBuilder setTargetAuthenticationStrategy(AuthenticationStrategy targetAuthStrategy) AssignsAuthenticationStrategy
instance for target host authentication. -
setProxyAuthenticationStrategy
public final HttpClientBuilder setProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategy
instance for proxy authentication. -
setUserTokenHandler
AssignsUserTokenHandler
instance.Please note this value can be overridden by the
disableConnectionState()
method. -
disableConnectionState
Disables connection state tracking. -
setSchemePortResolver
AssignsSchemePortResolver
instance. -
setUserAgent
AssignsUser-Agent
value.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
setDefaultHeaders
Assigns default request header values.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
addInterceptorFirst
Adds this protocol interceptor to the head of the protocol processing list.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
addInterceptorLast
Adds this protocol interceptor to the tail of the protocol processing list.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
addInterceptorFirst
Adds this protocol interceptor to the head of the protocol processing list.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
addInterceptorLast
Adds this protocol interceptor to the tail of the protocol processing list.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
disableCookieManagement
Disables state (cookie) management.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
disableContentCompression
Disables automatic content decompression.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
disableAuthCaching
Disables authentication scheme caching.Please note this value can be overridden by the
setHttpProcessor(org.apache.http.protocol.HttpProcessor)
method. -
setHttpProcessor
AssignsHttpProcessor
instance. -
setDnsResolver
AssignsDnsResolver
instance.Please note this value can be overridden by the
setConnectionManager(HttpClientConnectionManager)
method. -
setRetryHandler
AssignsHttpRequestRetryHandler
instance.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.http.conn.routing.HttpRoutePlanner)
method. -
setRoutePlanner
AssignsHttpRoutePlanner
instance. -
setRedirectStrategy
AssignsRedirectStrategy
instance.Please note this value can be overridden by the
`disableRedirectHandling()
method. -
disableRedirectHandling
Disables automatic redirect handling. -
setConnectionBackoffStrategy
public final HttpClientBuilder setConnectionBackoffStrategy(ConnectionBackoffStrategy connectionBackoffStrategy) AssignsConnectionBackoffStrategy
instance. -
setBackoffManager
AssignsBackoffManager
instance. -
setDefaultCookieStore
Assigns defaultCookieStore
instance which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCredentialsProvider
public final HttpClientBuilder 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 HttpClientBuilder setDefaultAuthSchemeRegistry(Lookup<AuthSchemeProvider> authSchemeRegistry) Assigns defaultAuthScheme
registry which will be used for request execution if not explicitly set in the client execution context. -
setDefaultCookieSpecRegistry
public final HttpClientBuilder setDefaultCookieSpecRegistry(Lookup<CookieSpecProvider> cookieSpecRegistry) Assigns defaultCookieSpec
registry which will be used for request execution if not explicitly set in the client execution context.- See Also:
-
setContentDecoderRegistry
public final HttpClientBuilder setContentDecoderRegistry(Map<String, InputStreamFactory> contentDecoderMap) Assigns a map ofInputStreamFactory
s to be used for automatic content decompression. -
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. -
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 configuted to use a shared connection manager.
Please note this method may not be used when the instance of HttpClient is created inside an EJB container.
- Since:
- 4.4
- See Also:
-
evictIdleConnections
@Deprecated public final HttpClientBuilder evictIdleConnections(Long maxIdleTime, TimeUnit maxIdleTimeUnit) Deprecated.(4.5) useevictIdleConnections(long, TimeUnit)
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 configuted to use a shared connection manager.
Please note this method may not be used when the instance of HttpClient is created inside an EJB container.
- 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.maxIdleTimeUnit
- time unit for the above parameter.- 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 configuted to use a shared connection manager.
Please note this method may not be used when the instance of HttpClient is created inside an EJB container.
- 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.maxIdleTimeUnit
- time unit for the above parameter.- 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
-
build
-
evictIdleConnections(long, TimeUnit)