Class 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.
    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.
    For the default SSL parameters see the Javadocs of the DefaultSslContextFactory class.
    See Also:
    Apache HTTP Client tutorial, Networking Features
    • Field Detail

      • httpClient

        private volatile org.apache.http.impl.client.DefaultHttpClient httpClient
    • Constructor Detail

      • HttpClientHelper

        public HttpClientHelper​(Client client)
        Constructor.
        Parameters:
        client - The client to help.
    • Method Detail

      • configure

        protected void configure​(org.apache.http.impl.client.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​(org.apache.http.params.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​(org.apache.http.conn.scheme.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 org.apache.http.conn.ClientConnectionManager createClientConnectionManager​(org.apache.http.params.HttpParams params,
                                                                                             org.apache.http.conn.scheme.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 org.apache.http.client.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 class 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​(HttpIdleConnectionReaper connectionReaper)
        Sets the idle connections reaper.
        Parameters:
        connectionReaper - The idle connections reaper.
      • start

        public void start()
                   throws java.lang.Exception
        Description copied from class: RestletHelper
        Start callback.
        Overrides:
        start in class ConnectorHelper<Client>
        Throws:
        java.lang.Exception
      • stop

        public void stop()
                  throws java.lang.Exception
        Description copied from class: RestletHelper
        Stop callback.
        Overrides:
        stop in class ConnectorHelper<Client>
        Throws:
        java.lang.Exception