Package com.ning.http.client
Class AsyncHttpClientConfig.Builder
java.lang.Object
com.ning.http.client.AsyncHttpClientConfig.Builder
- Enclosing class:
- AsyncHttpClientConfig
Builder for an
AsyncHttpClient-
Constructor Summary
ConstructorsConstructorDescriptionBuilder()Builder(AsyncHttpClientConfig prototype) Create a config builder with values taken from the given prototype configuration. -
Method Summary
Modifier and TypeMethodDescriptionaddIOExceptionFilter(IOExceptionFilter ioExceptionFilter) Add anIOExceptionFilterthat will be invoked when anIOExceptionoccurs during the download/upload operations.addRequestFilter(RequestFilter requestFilter) Add anRequestFilterthat will be invoked beforeAsyncHttpClient.executeRequest(Request)addResponseFilter(ResponseFilter responseFilter) Add anResponseFilterthat will be invoked as soon as the response is received, and beforeAsyncHandler.onStatusReceived(HttpResponseStatus).build()Build anAsyncHttpClientConfigremoveIOExceptionFilter(IOExceptionFilter ioExceptionFilter) Remove anIOExceptionFiltertthat will be invoked when anIOExceptionoccurs during the download/upload operations.removeRequestFilter(RequestFilter requestFilter) Remove anRequestFilterthat will be invoked beforeAsyncHttpClient.executeRequest(Request)removeResponseFilter(ResponseFilter responseFilter) Remove anResponseFilterthat will be invoked as soon as the response is received, and beforeAsyncHandler.onStatusReceived(HttpResponseStatus).setAcceptAnyCertificate(boolean acceptAnyCertificate) setAllowPoolingConnections(boolean allowPoolingConnections) Set true if connection can be pooled by aChannelPool.setAllowPoolingSslConnections(boolean allowPoolingSslConnections) Return true is if connections pooling is enabled.setAsyncHttpClientProviderConfig(AsyncHttpProviderConfig<?, ?> providerConfig) Set theAsyncHttpProviderConfigsetCompressionEnforced(boolean compressionEnforced) Enforce HTTP compression.setConnectionTTL(int connectionTTL) Set the maximum time in millisecond connection can be added to the pool for further reusesetConnectTimeout(int connectTimeOut) Set the maximum time in millisecond anAsyncHttpClientcan wait when connecting to a remote hostsetDisableUrlEncodingForBoundedRequests(boolean disableUrlEncodingForBoundedRequests) Disable automatic url escapingsetEnabledCipherSuites(String[] enabledCipherSuites) setEnabledProtocols(String[] enabledProtocols) setExecutorService(ExecutorService applicationThreadPool) Set theExecutorServiceanAsyncHttpClientuse for handling asynchronous response.setFollowRedirect(boolean followRedirect) Set to true to enable HTTP redirectsetHostnameVerifier(HostnameVerifier hostnameVerifier) Set theHostnameVerifiersetIOThreadMultiplier(int multiplier) setMaxConnections(int maxConnections) Set the maximum number of connections anAsyncHttpClientcan handle.setMaxConnectionsPerHost(int maxConnectionsPerHost) Set the maximum number of connections per (scheme, host, port) anAsyncHttpClientcan handle.setMaxRedirects(int maxRedirects) Set the maximum number of HTTP redirectsetMaxRequestHeaders(int maxRequestHeaders) setMaxRequestRetry(int maxRequestRetry) Set the number of time a request will be retried when anIOExceptionoccurs because of a Network exception.setNtlmAvoidSendPayloadOnType1(boolean ntlmAvoidSendPayloadOnType1) setPooledConnectionIdleTimeout(int pooledConnectionIdleTimeout) Set the maximum time in millisecond anAsyncHttpClientwill keep connection idle in pool.setProxyServer(ProxyServer proxyServer) Set an instance ofProxyServerused by anAsyncHttpClientsetProxyServerSelector(ProxyServerSelector proxyServerSelector) Set an instance ofProxyServerSelectorused by anAsyncHttpClientsetReadTimeout(int readTimeout) Set the maximum time in millisecond anAsyncHttpClientcan stay idle.Set theRealmthat will be used for all requests.setRequestTimeout(int requestTimeout) Set the maximum time in millisecond anAsyncHttpClientwaits until the response is completed.setSSLContext(SSLContext sslContext) Set theSSLContextfor secure connection.setSslSessionCacheSize(Integer sslSessionCacheSize) setSslSessionTimeout(Integer sslSessionTimeout) setStrict302Handling(boolean strict302Handling) Configures this AHC instance to be strict in it's handling of 302 redirects in a POST/Redirect/GET situation.setUseProxyProperties(boolean useProxyProperties) Sets whether AHC should use the default http.proxy* system properties to obtain proxy information.setUseProxySelector(boolean useProxySelector) Sets whether AHC should use the default JDK ProxySelector to select a proxy server.setUserAgent(String userAgent) Set the USER_AGENT header valuesetUseRelativeURIsWithConnectProxies(boolean useRelativeURIsWithConnectProxies) Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy or WebSocket proxy.setWebSocketTimeout(int webSocketTimeout) Set the maximum time in millisecond anWebSocketcan stay idle.
-
Constructor Details
-
Builder
public Builder() -
Builder
Create a config builder with values taken from the given prototype configuration.- Parameters:
prototype- the configuration to use as a prototype.
-
-
Method Details
-
setMaxConnections
Set the maximum number of connections anAsyncHttpClientcan handle.- Parameters:
maxConnections- the maximum number of connections anAsyncHttpClientcan handle.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setMaxConnectionsPerHost
Set the maximum number of connections per (scheme, host, port) anAsyncHttpClientcan handle.- Parameters:
maxConnectionsPerHost- the maximum number of connections per (scheme, host, port) anAsyncHttpClientcan handle.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setConnectTimeout
Set the maximum time in millisecond anAsyncHttpClientcan wait when connecting to a remote host- Parameters:
connectTimeOut- the maximum time in millisecond anAsyncHttpClientcan wait when connecting to a remote host- Returns:
- a
AsyncHttpClientConfig.Builder
-
setWebSocketTimeout
Set the maximum time in millisecond anWebSocketcan stay idle.- Parameters:
webSocketTimeout- the maximum time in millisecond anWebSocketcan stay idle.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setReadTimeout
Set the maximum time in millisecond anAsyncHttpClientcan stay idle.- Parameters:
readTimeout- the maximum time in millisecond anAsyncHttpClientcan stay idle.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setPooledConnectionIdleTimeout
public AsyncHttpClientConfig.Builder setPooledConnectionIdleTimeout(int pooledConnectionIdleTimeout) Set the maximum time in millisecond anAsyncHttpClientwill keep connection idle in pool.- Parameters:
idleConnectionInPoolTimeout- the maximum time in millisecond anAsyncHttpClientwill keep connection idle in pool.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setRequestTimeout
Set the maximum time in millisecond anAsyncHttpClientwaits until the response is completed.- Parameters:
requestTimeout- the maximum time in millisecond anAsyncHttpClientwaits until the response is completed.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setFollowRedirect
Set to true to enable HTTP redirect- Parameters:
redirectEnabled- true if enabled.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setMaxRedirects
Set the maximum number of HTTP redirect- Parameters:
maxRedirects- the maximum number of HTTP redirect- Returns:
- a
AsyncHttpClientConfig.Builder
-
setCompressionEnforced
Enforce HTTP compression.- Parameters:
compressionEnforced- true if compression is enforced- Returns:
- a
AsyncHttpClientConfig.Builder
-
setUserAgent
Set the USER_AGENT header value- Parameters:
userAgent- the USER_AGENT header value- Returns:
- a
AsyncHttpClientConfig.Builder
-
setAllowPoolingConnections
Set true if connection can be pooled by aChannelPool. Default is true.- Parameters:
allowPoolingConnections- true if connection can be pooled by aChannelPool- Returns:
- a
AsyncHttpClientConfig.Builder
-
setExecutorService
Set theExecutorServiceanAsyncHttpClientuse for handling asynchronous response.- Parameters:
applicationThreadPool- theExecutorServiceanAsyncHttpClientuse for handling asynchronous response.- Returns:
- a
AsyncHttpClientConfig.Builder
-
setProxyServerSelector
public AsyncHttpClientConfig.Builder setProxyServerSelector(ProxyServerSelector proxyServerSelector) Set an instance ofProxyServerSelectorused by anAsyncHttpClient- Parameters:
proxyServerSelector- instance ofProxyServerSelector- Returns:
- a
AsyncHttpClientConfig.Builder
-
setProxyServer
Set an instance ofProxyServerused by anAsyncHttpClient- Parameters:
proxyServer- instance ofProxyServer- Returns:
- a
AsyncHttpClientConfig.Builder
-
setSSLContext
Set theSSLContextfor secure connection.- Parameters:
sslContext- theSSLContextfor secure connection- Returns:
- a
AsyncHttpClientConfig.Builder
-
setAsyncHttpClientProviderConfig
public AsyncHttpClientConfig.Builder setAsyncHttpClientProviderConfig(AsyncHttpProviderConfig<?, ?> providerConfig) Set theAsyncHttpProviderConfig- Parameters:
providerConfig- theAsyncHttpProviderConfig- Returns:
- a
AsyncHttpClientConfig.Builder
-
setRealm
Set theRealmthat will be used for all requests.- Parameters:
realm- theRealm- Returns:
- a
AsyncHttpClientConfig.Builder
-
addRequestFilter
Add anRequestFilterthat will be invoked beforeAsyncHttpClient.executeRequest(Request)- Parameters:
requestFilter-RequestFilter- Returns:
- this
-
removeRequestFilter
Remove anRequestFilterthat will be invoked beforeAsyncHttpClient.executeRequest(Request)- Parameters:
requestFilter-RequestFilter- Returns:
- this
-
addResponseFilter
Add anResponseFilterthat will be invoked as soon as the response is received, and beforeAsyncHandler.onStatusReceived(HttpResponseStatus).- Parameters:
responseFilter- anResponseFilter- Returns:
- this
-
removeResponseFilter
Remove anResponseFilterthat will be invoked as soon as the response is received, and beforeAsyncHandler.onStatusReceived(HttpResponseStatus).- Parameters:
responseFilter- anResponseFilter- Returns:
- this
-
addIOExceptionFilter
Add anIOExceptionFilterthat will be invoked when anIOExceptionoccurs during the download/upload operations.- Parameters:
ioExceptionFilter- anResponseFilter- Returns:
- this
-
removeIOExceptionFilter
Remove anIOExceptionFiltertthat will be invoked when anIOExceptionoccurs during the download/upload operations.- Parameters:
ioExceptionFilter- anResponseFilter- Returns:
- this
-
setMaxRequestRetry
Set the number of time a request will be retried when anIOExceptionoccurs because of a Network exception.- Parameters:
maxRequestRetry- the number of time a request will be retried- Returns:
- this
-
setAllowPoolingSslConnections
public AsyncHttpClientConfig.Builder setAllowPoolingSslConnections(boolean allowPoolingSslConnections) Return true is if connections pooling is enabled.- Parameters:
allowPoolingSslConnections- true if enabled- Returns:
- this
-
setDisableUrlEncodingForBoundedRequests
public AsyncHttpClientConfig.Builder setDisableUrlEncodingForBoundedRequests(boolean disableUrlEncodingForBoundedRequests) Disable automatic url escaping- Parameters:
disableUrlEncodingForBoundedRequests-- Returns:
- this
-
setUseProxySelector
Sets whether AHC should use the default JDK ProxySelector to select a proxy server. If useProxySelector is set totruebutsetProxyServer(ProxyServer)was used to explicitly set a proxy server, the latter is preferred. See http://docs.oracle.com/javase/7/docs/api/java/net/ProxySelector.html -
setUseProxyProperties
Sets whether AHC should use the default http.proxy* system properties to obtain proxy information. This differs fromsetUseProxySelector(boolean)in that AsyncHttpClient will use its own logic to handle the system properties, potentially supporting other protocols that the the JDK ProxySelector doesn't. If useProxyProperties is set totruebutsetUseProxySelector(boolean)was also set to true, the latter is preferred. See http://download.oracle.com/javase/1.4.2/docs/guide/net/properties.html -
setIOThreadMultiplier
-
setHostnameVerifier
Set theHostnameVerifier- Parameters:
hostnameVerifier-HostnameVerifier- Returns:
- this
-
setStrict302Handling
Configures this AHC instance to be strict in it's handling of 302 redirects in a POST/Redirect/GET situation.- Parameters:
strict302Handling- strict handling- Returns:
- this
- Since:
- 1.7.2
-
setUseRelativeURIsWithConnectProxies
public AsyncHttpClientConfig.Builder setUseRelativeURIsWithConnectProxies(boolean useRelativeURIsWithConnectProxies) Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy or WebSocket proxy.- Parameters:
useRelativeURIsWithConnectProxies-- Returns:
- this
- Since:
- 1.8.13
-
setConnectionTTL
Set the maximum time in millisecond connection can be added to the pool for further reuse- Parameters:
connectionTTL- the maximum time in millisecond connection can be added to the pool for further reuse- Returns:
- a
AsyncHttpClientConfig.Builder
-
setAcceptAnyCertificate
-
setEnabledProtocols
-
setEnabledCipherSuites
-
setSslSessionCacheSize
-
setSslSessionTimeout
-
setMaxRequestHeaders
-
setNtlmAvoidSendPayloadOnType1
public AsyncHttpClientConfig.Builder setNtlmAvoidSendPayloadOnType1(boolean ntlmAvoidSendPayloadOnType1) -
build
Build anAsyncHttpClientConfig- Returns:
- an
AsyncHttpClientConfig
-