Package org.restlet.ext.httpclient
Class HttpClientHelper
- java.lang.Object
-
- org.restlet.engine.Helper
-
- org.restlet.engine.RestletHelper<T>
-
- org.restlet.engine.connector.ConnectorHelper<org.restlet.Client>
-
- org.restlet.engine.connector.ClientHelper
-
- org.restlet.engine.adapter.HttpClientHelper
-
- org.restlet.ext.httpclient.HttpClientHelper
-
public class HttpClientHelper extends org.restlet.engine.adapter.HttpClientHelper
HTTP client connector using the HttpMethodCall and Apache HTTP Client project. Note that the response must be fully read in all cases in order to surely release the underlying connection. Not doing so may cause future requests to block.
Here is the list of parameters that are supported. They should be set in the Client's context before it is started:list of supported parameters Parameter name Value type Default value Description followRedirects boolean false If true, the protocol will automatically follow redirects. If false, the protocol will not automatically follow redirects. hostnameVerifier String null Class name of the hostname verifier to use instead of HTTP Client default behavior. The given class name must implement org.apache.http.conn.ssl.X509HostnameVerifier and have default no-arg constructor. idleCheckInterval int 0 Time between checks for idle and expired connections. The check happens only if this property is set to a value greater than 0. idleTimeout long 60000 Returns the time in ms beyond which idle connections are eligible for reaping. The default value is 60000 ms. maxConnectionsPerHost int 10 The maximum number of connections that will be created for any particular host. maxTotalConnections int 20 (uses HttpClient's default) The maximum number of active connections. proxyHost String System property "http.proxyHost" The host name of the HTTP proxy. proxyPort int System property "http.proxyPort" or "3128" The port of the HTTP proxy. retryHandler String null Class name of the retry handler to use instead of HTTP Client default behavior. The given class name must extend the org.apache.http.client.HttpRequestRetryHandler class and have a default constructor socketConnectTimeoutMs int 15000 The socket connection timeout or 0 for unlimited wait. socketTimeout int 60000 Sets the socket timeout to a specified timeout, in milliseconds. A timeout of zero is interpreted as an infinite timeout. stopIdleTimeout int 60000 The minimum idle time, in milliseconds, for connections to be closed when stopping the connector. tcpNoDelay boolean false Indicate if Nagle's TCP_NODELAY algorithm should be used. sslContextFactory String org.restlet.engine.ssl.DefaultSslContextFactory Let you specify a SslContextFactory
qualified class name as a parameter, or an instance as an attribute for a more complete and flexible SSL context setting.DefaultSslContextFactory
class.- Author:
- Jerome Louvel
- See Also:
- Apache HTTP Client tutorial, Networking Features
-
-
Constructor Summary
Constructors Constructor Description HttpClientHelper(org.restlet.Client client)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
configure(SchemeRegistry schemeRegistry)
Configures the scheme registry.protected void
configure(DefaultHttpClient httpClient)
Configures the HTTP client.protected void
configure(HttpParams params)
Configures the various parameters of the connection manager and the HTTP client.org.restlet.engine.adapter.ClientCall
create(org.restlet.Request request)
Creates a low-level HTTP client call from a high-level uniform call.protected ClientConnectionManager
createClientConnectionManager(HttpParams params, SchemeRegistry schemeRegistry)
Creates the connection manager.java.lang.String
getHostnameVerifier()
Returns the class name of the hostname verifier to use instead of HTTP Client default behavior.HttpClient
getHttpClient()
Returns the wrapped Apache HTTP Client.long
getIdleCheckInterval()
Time in milliseconds between two checks for idle and expired connections.long
getIdleTimeout()
Returns the time in ms beyond which idle connections are eligible for reaping.int
getMaxConnectionsPerHost()
Returns the maximum number of connections that will be created for any particular host.int
getMaxTotalConnections()
Returns the maximum number of active connections.java.lang.String
getProxyHost()
Returns the host name of the HTTP proxy, if specified.int
getProxyPort()
Returns the port of the HTTP proxy, if specified, 3128 otherwise.java.lang.String
getRetryHandler()
Returns the class name of the retry handler to use instead of HTTP Client default behavior.int
getSocketConnectTimeoutMs()
Returns the connection timeout.int
getSocketTimeout()
Returns the socket timeout value.int
getStopIdleTimeout()
Returns the minimum idle time, in milliseconds, for connections to be closed when stopping the connector.boolean
getTcpNoDelay()
Indicates if the protocol will use Nagle's algorithmboolean
isFollowRedirects()
Indicates if the protocol will automatically follow redirects.void
setIdleConnectionReaper(org.restlet.ext.httpclient.internal.HttpIdleConnectionReaper connectionReaper)
Sets the idle connections reaper.void
start()
void
stop()
-
Methods inherited from class org.restlet.engine.adapter.HttpClientHelper
getAdapter, handle, setAdapter
-
Methods inherited from class org.restlet.engine.connector.ConnectorHelper
getConnectorService, getContext, getProtocols, update
-
-
-
-
Method Detail
-
configure
protected void configure(DefaultHttpClient httpClient)
Configures the HTTP client. By default, it try to set the retry handler.- Parameters:
httpClient
- The HTTP client to configure.
-
configure
protected void configure(HttpParams params)
Configures the various parameters of the connection manager and the HTTP client.- Parameters:
params
- The parameter list to update.
-
configure
protected void configure(SchemeRegistry schemeRegistry)
Configures the scheme registry. By default, it registers the HTTP and the HTTPS schemes.- Parameters:
schemeRegistry
- The scheme registry to configure.
-
create
public org.restlet.engine.adapter.ClientCall create(org.restlet.Request request)
Creates a low-level HTTP client call from a high-level uniform call.- Specified by:
create
in classorg.restlet.engine.adapter.HttpClientHelper
- Parameters:
request
- The high-level request.- Returns:
- A low-level HTTP client call.
-
createClientConnectionManager
protected ClientConnectionManager createClientConnectionManager(HttpParams params, SchemeRegistry schemeRegistry)
Creates the connection manager. By default, it creates a thread safe connection manager.- Parameters:
params
- The configuration parameters.schemeRegistry
- The scheme registry to use.- Returns:
- The created connection manager.
-
getHostnameVerifier
public java.lang.String getHostnameVerifier()
Returns the class name of the hostname verifier to use instead of HTTP Client default behavior. The given class name must implement org.apache.http.conn.ssl.X509HostnameVerifier and have default no-arg constructor.- Returns:
- The class name of the hostname verifier.
-
getHttpClient
public HttpClient getHttpClient()
Returns the wrapped Apache HTTP Client.- Returns:
- The wrapped Apache HTTP Client.
-
getIdleCheckInterval
public long getIdleCheckInterval()
Time in milliseconds between two checks for idle and expired connections. The check happens only if this property is set to a value greater than 0.- Returns:
- A value indicating the idle connection check interval or 0 if a value has not been provided
- See Also:
getIdleTimeout()
-
getIdleTimeout
public long getIdleTimeout()
Returns the time in ms beyond which idle connections are eligible for reaping. The default value is 60000 ms.- Returns:
- The time in millis beyond which idle connections are eligible for reaping.
- See Also:
getIdleCheckInterval()
-
getMaxConnectionsPerHost
public int getMaxConnectionsPerHost()
Returns the maximum number of connections that will be created for any particular host.- Returns:
- The maximum number of connections that will be created for any particular host.
-
getMaxTotalConnections
public int getMaxTotalConnections()
Returns the maximum number of active connections.- Returns:
- The maximum number of active connections.
-
getProxyHost
public java.lang.String getProxyHost()
Returns the host name of the HTTP proxy, if specified.- Returns:
- the host name of the HTTP proxy, if specified.
-
getProxyPort
public int getProxyPort()
Returns the port of the HTTP proxy, if specified, 3128 otherwise.- Returns:
- the port of the HTTP proxy.
-
getRetryHandler
public java.lang.String getRetryHandler()
Returns the class name of the retry handler to use instead of HTTP Client default behavior. The given class name must implement the org.apache.commons.httpclient.HttpMethodRetryHandler interface and have a default constructor.- Returns:
- The class name of the retry handler.
-
getSocketConnectTimeoutMs
public int getSocketConnectTimeoutMs()
Returns the connection timeout. Defaults to 15000.- Overrides:
getSocketConnectTimeoutMs
in classorg.restlet.engine.adapter.HttpClientHelper
- Returns:
- The connection timeout.
-
getSocketTimeout
public int getSocketTimeout()
Returns the socket timeout value. A timeout of zero is interpreted as an infinite timeout. Defaults to 60000.- Returns:
- The read timeout value.
-
getStopIdleTimeout
public int getStopIdleTimeout()
Returns the minimum idle time, in milliseconds, for connections to be closed when stopping the connector.- Returns:
- The minimum idle time, in milliseconds, for connections to be closed when stopping the connector.
-
getTcpNoDelay
public boolean getTcpNoDelay()
Indicates if the protocol will use Nagle's algorithm- Returns:
- True to enable TCP_NODELAY, false to disable.
- See Also:
Socket.setTcpNoDelay(boolean)
-
isFollowRedirects
public boolean isFollowRedirects()
Indicates if the protocol will automatically follow redirects.- Returns:
- True if the protocol will automatically follow redirects.
-
setIdleConnectionReaper
public void setIdleConnectionReaper(org.restlet.ext.httpclient.internal.HttpIdleConnectionReaper connectionReaper)
Sets the idle connections reaper.- Parameters:
connectionReaper
- The idle connections reaper.
-
start
public void start() throws java.lang.Exception
- Overrides:
start
in classorg.restlet.engine.connector.ConnectorHelper<org.restlet.Client>
- Throws:
java.lang.Exception
-
stop
public void stop() throws java.lang.Exception
- Overrides:
stop
in classorg.restlet.engine.connector.ConnectorHelper<org.restlet.Client>
- Throws:
java.lang.Exception
-
-