org.restlet.ext.httpclient
Class HttpClientHelper

java.lang.Object
  extended by org.restlet.engine.Helper
      extended by org.restlet.engine.RestletHelper<T>
          extended by org.restlet.engine.ConnectorHelper<Client>
              extended by org.restlet.engine.ClientHelper
                  extended by org.restlet.engine.adapter.HttpClientHelper
                      extended by org.restlet.ext.httpclient.HttpClientHelper

public class HttpClientHelper
extends 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:

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.
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 10000 Returns the time in ms beyond which idle connections are eligible for reaping. The default value is 10000 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.
stopIdleTimeout int 1000 The minimum idle time, in milliseconds, for connections to be closed when stopping the connector.
socketTimeout int 0 Sets the socket timeout to a specified timeout, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
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
tcpNoDelay boolean false Indicate if Nagle's TCP_NODELAY algorithm should be used.
sslContextFactory String org.restlet.ext.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.
For the default SSL parameters see the Javadocs of the DefaultSslContextFactory class.

Author:
Jerome Louvel
See Also:
Apache HTTP Client tutorial, Networking Features

Constructor Summary
HttpClientHelper(Client client)
          Constructor.
 
Method Summary
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.
protected  void configure(SchemeRegistry schemeRegistry)
          Configures the scheme registry.
 ClientCall create(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.
 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.
 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.
 String getRetryHandler()
          Returns the class name of the retry handler to use instead of HTTP Client default behavior.
 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 algorithm
 boolean 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.ClientHelper
getSocketConnectTimeoutMs
 
Methods inherited from class org.restlet.engine.ConnectorHelper
getConnectorService, getContext, getProtocols, update
 
Methods inherited from class org.restlet.engine.RestletHelper
getAttributes, getHelped, getHelpedParameters, getLogger, getMetadataService, setHelped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpClientHelper

public HttpClientHelper(Client client)
Constructor.

Parameters:
client - The client to help.
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 ClientCall create(Request request)
Creates a low-level HTTP client call from a high-level uniform call.

Specified by:
create in class 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.

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 10000 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 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 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.

getSocketTimeout

public int getSocketTimeout()
Returns the socket timeout value. A timeout of zero is interpreted as an infinite timeout.

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 Exception
Overrides:
start in class ConnectorHelper<Client>
Throws:
Exception

stop

public void stop()
          throws Exception
Overrides:
stop in class ConnectorHelper<Client>
Throws:
Exception


Copyright © 2005-2014 Restlet.