com.ning.http.client
Class AsyncHttpClientConfig.Builder

java.lang.Object
  extended by com.ning.http.client.AsyncHttpClientConfig.Builder
Enclosing class:
AsyncHttpClientConfig

public static class AsyncHttpClientConfig.Builder
extends Object

Builder for an AsyncHttpClient


Constructor Summary
AsyncHttpClientConfig.Builder()
           
AsyncHttpClientConfig.Builder(AsyncHttpClientConfig prototype)
          Create a config builder with values taken from the given prototype configuration.
 
Method Summary
 AsyncHttpClientConfig.Builder addIOExceptionFilter(IOExceptionFilter ioExceptionFilter)
          Add an IOExceptionFilter that will be invoked when an IOException occurs during the download/upload operations.
 AsyncHttpClientConfig.Builder addRequestFilter(RequestFilter requestFilter)
          Add an RequestFilter that will be invoked before AsyncHttpClient.executeRequest(Request)
 AsyncHttpClientConfig.Builder addResponseFilter(ResponseFilter responseFilter)
          Add an ResponseFilter that will be invoked as soon as the response is received, and before AsyncHandler.onStatusReceived(HttpResponseStatus).
 AsyncHttpClientConfig build()
          Build an AsyncHttpClientConfig
 int getRequestCompressionLevel()
          Return the compression level, or -1 if no compression is used.
 AsyncHttpClientConfig.Builder removeIOExceptionFilter(IOExceptionFilter ioExceptionFilter)
          Remove an IOExceptionFilter tthat will be invoked when an IOException occurs during the download/upload operations.
 AsyncHttpClientConfig.Builder removeRequestFilter(RequestFilter requestFilter)
          Remove an RequestFilter that will be invoked before AsyncHttpClient.executeRequest(Request)
 AsyncHttpClientConfig.Builder removeResponseFilter(ResponseFilter responseFilter)
          Remove an ResponseFilter that will be invoked as soon as the response is received, and before AsyncHandler.onStatusReceived(HttpResponseStatus).
 AsyncHttpClientConfig.Builder setAcceptAnyCertificate(boolean acceptAnyCertificate)
           
 AsyncHttpClientConfig.Builder setAllowPoolingConnection(boolean allowPoolingConnection)
          Set true if connection can be pooled by a ConnectionsPool.
 AsyncHttpClientConfig.Builder setAllowSslConnectionPool(boolean allowSslConnectionPool)
          Return true is if connections pooling is enabled.
 AsyncHttpClientConfig.Builder setAsyncHttpClientProviderConfig(AsyncHttpProviderConfig<?,?> providerConfig)
          Set the AsyncHttpProviderConfig
 AsyncHttpClientConfig.Builder setCompressionEnabled(boolean compressionEnabled)
          Enable HTTP compression.
 AsyncHttpClientConfig.Builder setConnectionsPool(ConnectionsPool<?,?> connectionsPool)
          Set the ConnectionsPool
 AsyncHttpClientConfig.Builder setConnectionTimeoutInMs(int connectionTimeOutInMs)
          Set the maximum time in millisecond an AsyncHttpClient can wait when connecting to a remote host
 AsyncHttpClientConfig.Builder setDisableUrlEncodingForBoundedRequests(boolean disableUrlEncodingForBoundedRequests)
          Disable automatic url escaping
 AsyncHttpClientConfig.Builder setExecutorService(ExecutorService applicationThreadPool)
          Set the ExecutorService an AsyncHttpClient use for handling asynchronous response.
 AsyncHttpClientConfig.Builder setFollowRedirect(boolean followRedirect)
          Set to true to enable HTTP redirect
 AsyncHttpClientConfig.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
          Set the HostnameVerifier
 AsyncHttpClientConfig.Builder setIdleConnectionInPoolTimeoutInMs(int idleConnectionInPoolTimeoutInMs)
          Set the maximum time in millisecond an AsyncHttpClient will keep connection idle in pool.
 AsyncHttpClientConfig.Builder setIdleConnectionTimeoutInMs(int idleConnectionTimeoutInMs)
          Set the maximum time in millisecond an AsyncHttpClient can stay idle.
 AsyncHttpClientConfig.Builder setIOThreadMultiplier(int multiplier)
           
 AsyncHttpClientConfig.Builder setMaxConnectionLifeTimeInMs(int maxConnectionLifeTimeInMs)
          Set the maximum time in millisecond connection can be added to the pool for further reuse
 AsyncHttpClientConfig.Builder setMaximumConnectionsPerHost(int maxConnectionPerHost)
          Set the maximum number of connections per hosts an AsyncHttpClient can handle.
 AsyncHttpClientConfig.Builder setMaximumConnectionsTotal(int maxTotalConnections)
          Set the maximum number of connections an AsyncHttpClient can handle.
 AsyncHttpClientConfig.Builder setMaximumNumberOfRedirects(int maxDefaultRedirects)
          Set the maximum number of HTTP redirect
 AsyncHttpClientConfig.Builder setMaxRequestRetry(int maxRequestRetry)
          Set the number of time a request will be retried when an IOException occurs because of a Network exception.
 AsyncHttpClientConfig.Builder setProxyServer(ProxyServer proxyServer)
          Set an instance of ProxyServer used by an AsyncHttpClient
 AsyncHttpClientConfig.Builder setProxyServerSelector(ProxyServerSelector proxyServerSelector)
          Set an instance of ProxyServerSelector used by an AsyncHttpClient
 AsyncHttpClientConfig.Builder setRealm(Realm realm)
          Set the Realm that will be used for all requests.
 AsyncHttpClientConfig.Builder setRemoveQueryParamsOnRedirect(boolean removeQueryParamOnRedirect)
          Set to false if you don't want the query parameters removed when a redirect occurs.
 AsyncHttpClientConfig.Builder setRequestCompressionLevel(int requestCompressionLevel)
          Set the compression level, or -1 if no compression is used.
 AsyncHttpClientConfig.Builder setRequestTimeoutInMs(int requestTimeoutInMs)
          Set the maximum time in millisecond an AsyncHttpClient wait for a response
 AsyncHttpClientConfig.Builder setSSLContext(SSLContext sslContext)
          Set the SSLContext for secure connection.
 AsyncHttpClientConfig.Builder setStrict302Handling(boolean strict302Handling)
          Configures this AHC instance to be strict in it's handling of 302 redirects in a POST/Redirect/GET situation.
 AsyncHttpClientConfig.Builder setTimeConverter(TimeConverter timeConverter)
           
 AsyncHttpClientConfig.Builder setUseProxyProperties(boolean useProxyProperties)
          Sets whether AHC should use the default http.proxy* system properties to obtain proxy information.
 AsyncHttpClientConfig.Builder setUseProxySelector(boolean useProxySelector)
          Sets whether AHC should use the default JDK ProxySelector to select a proxy server.
 AsyncHttpClientConfig.Builder setUserAgent(String userAgent)
          Set the USER_AGENT header value
 AsyncHttpClientConfig.Builder setUseRelativeURIsWithSSLProxies(boolean useRelativeURIsWithSSLProxies)
          Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy.
 AsyncHttpClientConfig.Builder setWebSocketIdleTimeoutInMs(int webSocketIdleTimeoutInMs)
          Set the maximum time in millisecond an WebSocket can stay idle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncHttpClientConfig.Builder

public AsyncHttpClientConfig.Builder()

AsyncHttpClientConfig.Builder

public AsyncHttpClientConfig.Builder(AsyncHttpClientConfig prototype)
Create a config builder with values taken from the given prototype configuration.

Parameters:
prototype - the configuration to use as a prototype.
Method Detail

setMaximumConnectionsTotal

public AsyncHttpClientConfig.Builder setMaximumConnectionsTotal(int maxTotalConnections)
Set the maximum number of connections an AsyncHttpClient can handle.

Parameters:
maxTotalConnections - the maximum number of connections an AsyncHttpClient can handle.
Returns:
a AsyncHttpClientConfig.Builder

setMaximumConnectionsPerHost

public AsyncHttpClientConfig.Builder setMaximumConnectionsPerHost(int maxConnectionPerHost)
Set the maximum number of connections per hosts an AsyncHttpClient can handle.

Parameters:
maxConnectionPerHost - the maximum number of connections per host an AsyncHttpClient can handle.
Returns:
a AsyncHttpClientConfig.Builder

setConnectionTimeoutInMs

public AsyncHttpClientConfig.Builder setConnectionTimeoutInMs(int connectionTimeOutInMs)
Set the maximum time in millisecond an AsyncHttpClient can wait when connecting to a remote host

Parameters:
connectionTimeOutInMs - the maximum time in millisecond an AsyncHttpClient can wait when connecting to a remote host
Returns:
a AsyncHttpClientConfig.Builder

setWebSocketIdleTimeoutInMs

public AsyncHttpClientConfig.Builder setWebSocketIdleTimeoutInMs(int webSocketIdleTimeoutInMs)
Set the maximum time in millisecond an WebSocket can stay idle.

Parameters:
webSocketIdleTimeoutInMs - the maximum time in millisecond an WebSocket can stay idle.
Returns:
a AsyncHttpClientConfig.Builder

setIdleConnectionTimeoutInMs

public AsyncHttpClientConfig.Builder setIdleConnectionTimeoutInMs(int idleConnectionTimeoutInMs)
Set the maximum time in millisecond an AsyncHttpClient can stay idle.

Parameters:
idleConnectionTimeoutInMs - the maximum time in millisecond an AsyncHttpClient can stay idle.
Returns:
a AsyncHttpClientConfig.Builder

setIdleConnectionInPoolTimeoutInMs

public AsyncHttpClientConfig.Builder setIdleConnectionInPoolTimeoutInMs(int idleConnectionInPoolTimeoutInMs)
Set the maximum time in millisecond an AsyncHttpClient will keep connection idle in pool.

Parameters:
idleConnectionInPoolTimeoutInMs - the maximum time in millisecond an AsyncHttpClient will keep connection idle in pool.
Returns:
a AsyncHttpClientConfig.Builder

setRequestTimeoutInMs

public AsyncHttpClientConfig.Builder setRequestTimeoutInMs(int requestTimeoutInMs)
Set the maximum time in millisecond an AsyncHttpClient wait for a response

Parameters:
requestTimeoutInMs - the maximum time in millisecond an AsyncHttpClient wait for a response
Returns:
a AsyncHttpClientConfig.Builder

setFollowRedirect

public AsyncHttpClientConfig.Builder setFollowRedirect(boolean followRedirect)
Set to true to enable HTTP redirect

Parameters:
redirectEnabled - true if enabled.
Returns:
a AsyncHttpClientConfig.Builder

setMaximumNumberOfRedirects

public AsyncHttpClientConfig.Builder setMaximumNumberOfRedirects(int maxDefaultRedirects)
Set the maximum number of HTTP redirect

Parameters:
maxDefaultRedirects - the maximum number of HTTP redirect
Returns:
a AsyncHttpClientConfig.Builder

setCompressionEnabled

public AsyncHttpClientConfig.Builder setCompressionEnabled(boolean compressionEnabled)
Enable HTTP compression.

Parameters:
compressionEnabled - true if compression is enabled
Returns:
a AsyncHttpClientConfig.Builder

setUserAgent

public AsyncHttpClientConfig.Builder setUserAgent(String userAgent)
Set the USER_AGENT header value

Parameters:
userAgent - the USER_AGENT header value
Returns:
a AsyncHttpClientConfig.Builder

setAllowPoolingConnection

public AsyncHttpClientConfig.Builder setAllowPoolingConnection(boolean allowPoolingConnection)
Set true if connection can be pooled by a ConnectionsPool. Default is true.

Parameters:
allowPoolingConnection - true if connection can be pooled by a ConnectionsPool
Returns:
a AsyncHttpClientConfig.Builder

setExecutorService

public AsyncHttpClientConfig.Builder setExecutorService(ExecutorService applicationThreadPool)
Set the ExecutorService an AsyncHttpClient use for handling asynchronous response.

Parameters:
applicationThreadPool - the ExecutorService an AsyncHttpClient use for handling asynchronous response.
Returns:
a AsyncHttpClientConfig.Builder

setProxyServerSelector

public AsyncHttpClientConfig.Builder setProxyServerSelector(ProxyServerSelector proxyServerSelector)
Set an instance of ProxyServerSelector used by an AsyncHttpClient

Parameters:
proxyServerSelector - instance of ProxyServerSelector
Returns:
a AsyncHttpClientConfig.Builder

setProxyServer

public AsyncHttpClientConfig.Builder setProxyServer(ProxyServer proxyServer)
Set an instance of ProxyServer used by an AsyncHttpClient

Parameters:
proxyServer - instance of ProxyServer
Returns:
a AsyncHttpClientConfig.Builder

setSSLContext

public AsyncHttpClientConfig.Builder setSSLContext(SSLContext sslContext)
Set the SSLContext for secure connection.

Parameters:
sslContext - the SSLContext for secure connection
Returns:
a AsyncHttpClientConfig.Builder

setAsyncHttpClientProviderConfig

public AsyncHttpClientConfig.Builder setAsyncHttpClientProviderConfig(AsyncHttpProviderConfig<?,?> providerConfig)
Set the AsyncHttpProviderConfig

Parameters:
providerConfig - the AsyncHttpProviderConfig
Returns:
a AsyncHttpClientConfig.Builder

setConnectionsPool

public AsyncHttpClientConfig.Builder setConnectionsPool(ConnectionsPool<?,?> connectionsPool)
Set the ConnectionsPool

Parameters:
connectionsPool - the ConnectionsPool
Returns:
a AsyncHttpClientConfig.Builder

setRealm

public AsyncHttpClientConfig.Builder setRealm(Realm realm)
Set the Realm that will be used for all requests.

Parameters:
realm - the Realm
Returns:
a AsyncHttpClientConfig.Builder

addRequestFilter

public AsyncHttpClientConfig.Builder addRequestFilter(RequestFilter requestFilter)
Add an RequestFilter that will be invoked before AsyncHttpClient.executeRequest(Request)

Parameters:
requestFilter - RequestFilter
Returns:
this

removeRequestFilter

public AsyncHttpClientConfig.Builder removeRequestFilter(RequestFilter requestFilter)
Remove an RequestFilter that will be invoked before AsyncHttpClient.executeRequest(Request)

Parameters:
requestFilter - RequestFilter
Returns:
this

addResponseFilter

public AsyncHttpClientConfig.Builder addResponseFilter(ResponseFilter responseFilter)
Add an ResponseFilter that will be invoked as soon as the response is received, and before AsyncHandler.onStatusReceived(HttpResponseStatus).

Parameters:
responseFilter - an ResponseFilter
Returns:
this

removeResponseFilter

public AsyncHttpClientConfig.Builder removeResponseFilter(ResponseFilter responseFilter)
Remove an ResponseFilter that will be invoked as soon as the response is received, and before AsyncHandler.onStatusReceived(HttpResponseStatus).

Parameters:
responseFilter - an ResponseFilter
Returns:
this

addIOExceptionFilter

public AsyncHttpClientConfig.Builder addIOExceptionFilter(IOExceptionFilter ioExceptionFilter)
Add an IOExceptionFilter that will be invoked when an IOException occurs during the download/upload operations.

Parameters:
ioExceptionFilter - an ResponseFilter
Returns:
this

removeIOExceptionFilter

public AsyncHttpClientConfig.Builder removeIOExceptionFilter(IOExceptionFilter ioExceptionFilter)
Remove an IOExceptionFilter tthat will be invoked when an IOException occurs during the download/upload operations.

Parameters:
ioExceptionFilter - an ResponseFilter
Returns:
this

getRequestCompressionLevel

public int getRequestCompressionLevel()
Return the compression level, or -1 if no compression is used.

Returns:
the compression level, or -1 if no compression is use

setRequestCompressionLevel

public AsyncHttpClientConfig.Builder setRequestCompressionLevel(int requestCompressionLevel)
Set the compression level, or -1 if no compression is used.

Parameters:
requestCompressionLevel - compression level, or -1 if no compression is use
Returns:
this

setMaxRequestRetry

public AsyncHttpClientConfig.Builder setMaxRequestRetry(int maxRequestRetry)
Set the number of time a request will be retried when an IOException occurs because of a Network exception.

Parameters:
maxRequestRetry - the number of time a request will be retried
Returns:
this

setAllowSslConnectionPool

public AsyncHttpClientConfig.Builder setAllowSslConnectionPool(boolean allowSslConnectionPool)
Return true is if connections pooling is enabled.

Parameters:
allowSslConnectionPool - true if enabled
Returns:
this

setDisableUrlEncodingForBoundedRequests

public AsyncHttpClientConfig.Builder setDisableUrlEncodingForBoundedRequests(boolean disableUrlEncodingForBoundedRequests)
Disable automatic url escaping

Parameters:
disableUrlEncodingForBoundedRequests -
Returns:
this

setRemoveQueryParamsOnRedirect

public AsyncHttpClientConfig.Builder setRemoveQueryParamsOnRedirect(boolean removeQueryParamOnRedirect)
Set to false if you don't want the query parameters removed when a redirect occurs.

Parameters:
removeQueryParamOnRedirect -
Returns:
this

setUseProxySelector

public AsyncHttpClientConfig.Builder setUseProxySelector(boolean useProxySelector)
Sets whether AHC should use the default JDK ProxySelector to select a proxy server.

If useProxySelector is set to true but setProxyServer(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

public AsyncHttpClientConfig.Builder setUseProxyProperties(boolean useProxyProperties)
Sets whether AHC should use the default http.proxy* system properties to obtain proxy information. This differs from setUseProxySelector(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 to true but setUseProxySelector(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

public AsyncHttpClientConfig.Builder setIOThreadMultiplier(int multiplier)

setHostnameVerifier

public AsyncHttpClientConfig.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
Set the HostnameVerifier

Parameters:
hostnameVerifier - HostnameVerifier
Returns:
this

setStrict302Handling

public AsyncHttpClientConfig.Builder setStrict302Handling(boolean strict302Handling)
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

setUseRelativeURIsWithSSLProxies

public AsyncHttpClientConfig.Builder setUseRelativeURIsWithSSLProxies(boolean useRelativeURIsWithSSLProxies)
Configures this AHC instance to use relative URIs instead of absolute ones when talking with a SSL proxy.

Parameters:
useRelativeURIsWithSSLProxies -
Returns:
this
Since:
1.7.2

setMaxConnectionLifeTimeInMs

public AsyncHttpClientConfig.Builder setMaxConnectionLifeTimeInMs(int maxConnectionLifeTimeInMs)
Set the maximum time in millisecond connection can be added to the pool for further reuse

Parameters:
maxConnectionLifeTimeInMs - the maximum time in millisecond connection can be added to the pool for further reuse
Returns:
a AsyncHttpClientConfig.Builder

setTimeConverter

public AsyncHttpClientConfig.Builder setTimeConverter(TimeConverter timeConverter)

setAcceptAnyCertificate

public AsyncHttpClientConfig.Builder setAcceptAnyCertificate(boolean acceptAnyCertificate)

build

public AsyncHttpClientConfig build()
Build an AsyncHttpClientConfig

Returns:
an AsyncHttpClientConfig


Copyright © 2014. All Rights Reserved.