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 HttpClientBuilderAdds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilderAdds this protocol interceptor to the head of the protocol processing list.final HttpClientBuilderAdds this protocol interceptor to the tail of the protocol processing list.final HttpClientBuilderAdds this protocol interceptor to the tail of the protocol processing list.build()static HttpClientBuildercreate()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(long maxIdleTime, TimeUnit maxIdleTimeUnit) Makes this instance of HttpClient proactively evict idle connections from the connection pool using a background thread.final HttpClientBuilderevictIdleConnections(Long maxIdleTime, TimeUnit maxIdleTimeUnit) Deprecated.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(ConnectionReuseStrategy reuseStrategy) AssignsConnectionReuseStrategyinstance.final HttpClientBuildersetConnectionTimeToLive(long connTimeToLive, TimeUnit connTimeToLiveTimeUnit) Sets maximum time to live for persistent connectionsfinal HttpClientBuildersetContentDecoderRegistry(Map<String, InputStreamFactory> contentDecoderMap) Assigns a map ofInputStreamFactorys to be used for automatic content decompression.final HttpClientBuildersetDefaultAuthSchemeRegistry(Lookup<AuthSchemeProvider> authSchemeRegistry) Assigns defaultAuthSchemeregistry which will be used for request execution if not explicitly set in the client execution context.final HttpClientBuilderAssigns defaultConnectionConfig.final HttpClientBuildersetDefaultCookieSpecRegistry(Lookup<CookieSpecProvider> 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 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 HttpClientBuildersetDefaultSocketConfig(SocketConfig config) Assigns defaultSocketConfig.final HttpClientBuildersetDnsResolver(DnsResolver dnsResolver) AssignsDnsResolverinstance.final HttpClientBuildersetHostnameVerifier(X509HostnameVerifier hostnameVerifier) Deprecated.(4.4)final HttpClientBuildersetHttpProcessor(HttpProcessor httpprocessor) AssignsHttpProcessorinstance.final HttpClientBuildersetKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy) AssignsConnectionKeepAliveStrategyinstance.final HttpClientBuildersetMaxConnPerRoute(int maxConnPerRoute) Assigns maximum connection per route value.final HttpClientBuildersetMaxConnTotal(int maxConnTotal) Assigns maximum total connection value.final HttpClientBuilderAssigns default proxy value.final HttpClientBuildersetProxyAuthenticationStrategy(AuthenticationStrategy proxyAuthStrategy) AssignsAuthenticationStrategyinstance for proxy authentication.final HttpClientBuildersetPublicSuffixMatcher(PublicSuffixMatcher publicSuffixMatcher) Assigns file containing public suffix matcher.final HttpClientBuildersetRedirectStrategy(RedirectStrategy redirectStrategy) AssignsRedirectStrategyinstance.final HttpClientBuildersetRequestExecutor(HttpRequestExecutor requestExec) AssignsHttpRequestExecutorinstance.final HttpClientBuildersetRetryHandler(HttpRequestRetryHandler retryHandler) AssignsHttpRequestRetryHandlerinstance.final HttpClientBuildersetRoutePlanner(HttpRoutePlanner routePlanner) AssignsHttpRoutePlannerinstance.final HttpClientBuildersetSchemePortResolver(SchemePortResolver schemePortResolver) AssignsSchemePortResolverinstance.final HttpClientBuildersetServiceUnavailableRetryStrategy(ServiceUnavailableRetryStrategy serviceUnavailStrategy) AssignsServiceUnavailableRetryStrategyinstance.final HttpClientBuildersetSslcontext(SSLContext sslcontext) Deprecated.(4.5) usesetSSLContext(SSLContext)final HttpClientBuildersetSSLContext(SSLContext sslContext) AssignsSSLContextinstance.final HttpClientBuildersetSSLHostnameVerifier(HostnameVerifier hostnameVerifier) AssignsHostnameVerifierinstance.final HttpClientBuildersetSSLSocketFactory(LayeredConnectionSocketFactory sslSocketFactory) AssignsLayeredConnectionSocketFactoryinstance.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.
-
Method Details
-
create
-
setRequestExecutor
AssignsHttpRequestExecutorinstance. -
setHostnameVerifier
@Deprecated public final HttpClientBuilder setHostnameVerifier(X509HostnameVerifier hostnameVerifier) Deprecated.(4.4)AssignsX509HostnameVerifierinstance.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
AssignsHostnameVerifierinstance.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)AssignsSSLContextinstance.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
AssignsSSLContextinstance.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
AssignsLayeredConnectionSocketFactoryinstance.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
AssignsHttpClientConnectionManagerinstance. -
setConnectionReuseStrategy
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.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
AssignsHttpProcessorinstance. -
setDnsResolver
AssignsDnsResolverinstance.Please note this value can be overridden by the
setConnectionManager(HttpClientConnectionManager)method. -
setRetryHandler
AssignsHttpRequestRetryHandlerinstance.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
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(Lookup<AuthSchemeProvider> authSchemeRegistry) Assigns defaultAuthSchemeregistry 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 defaultCookieSpecregistry 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 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 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)