Class HttpClientHelper


  • public class HttpClientHelper
    extends org.restlet.engine.adapter.HttpClientHelper
    HTTP client connector using the Jetty project. 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
    addressResolutionTimeout long 15000 The timeout in milliseconds for the DNS resolution of host addresses
    bindAddress String null The address to bind socket channels to. You must set both this and bindPort
    bindPort int null The address to bind socket channels to. You must set both this and bindAddress
    connectTimeout long 15000 The max time in milliseconds a connection can take to connect to destinations
    dispatchIo boolean true Whether to dispatch I/O operations from the selector thread to a different thread
    followRedirects boolean true Whether to follow HTTP redirects
    idleTimeout long 60000 The max time in milliseconds a connection can be idle (that is, without traffic of bytes in either direction)
    maxConnectionsPerDestination int 10 Sets the max number of connections to open to each destination
    maxRedirects int 8 The max number of HTTP redirects that are followed
    maxRequestsQueuedPerDestination int 1024 Sets the max number of requests that may be queued to a destination
    requestBufferSize int 4096 The size in bytes of the buffer used to write requests
    responseBufferSize int 16384 The size in bytes of the buffer used to read responses
    stopTimeout long 60000 Stop timeout in milliseconds; the maximum time allowed for the service to shutdown
    strictEventOrdering boolean false Whether request events must be strictly ordered
    tcpNoDelay boolean true Whether TCP_NODELAY is enabled
    userAgentField String null The "User-Agent" HTTP header string; when null, uses the Jetty default
    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, Tal Liron
    See Also:
    Jetty home page
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpClientHelper​(org.restlet.Client client)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.restlet.engine.adapter.ClientCall create​(org.restlet.Request request)
      Creates a low-level HTTP client call from a high-level uniform call.
      long getAddressResolutionTimeout()
      The timeout in milliseconds for the DNS resolution of host addresses.
      java.net.SocketAddress getBindAddress()
      The address to bind socket channels to.
      long getConnectTimeout()
      The max time in milliseconds a connection can take to connect to destinations.
      java.net.CookieStore getCookieStore()
      The cookie store.
      java.util.concurrent.Executor getExecutor()
      The executor.
      org.eclipse.jetty.client.HttpClient getHttpClient()
      Returns the wrapped Jetty HTTP client.
      long getIdleTimeout()
      The max time in milliseconds a connection can be idle (that is, without traffic of bytes in either direction).
      int getMaxConnectionsPerDestination()
      Sets the max number of connections to open to each destination.
      int getMaxRedirects()
      The max number of HTTP redirects that are followed.
      int getMaxRequestsQueuedPerDestination()
      Sets the max number of requests that may be queued to a destination.
      int getRequestBufferSize()
      The size in bytes of the buffer used to write requests.
      int getResponseBufferSize()
      The size in bytes of the buffer used to read responses.
      org.eclipse.jetty.util.thread.Scheduler getScheduler()
      The scheduler.
      long getStopTimeout()
      Stop timeout in milliseconds.
      java.lang.String getUserAgentField()
      The "User-Agent" HTTP header string.
      boolean isDispatchIO()
      Whether to dispatch I/O operations from the selector thread to a different thread.
      boolean isFollowRedirects()
      Whether to follow HTTP redirects.
      boolean isStrictEventOrdering()
      Whether request events must be strictly ordered.
      boolean isTcpNoDelay()
      Whether TCP_NODELAY is enabled.
      void start()  
      void stop()  
      • Methods inherited from class org.restlet.engine.adapter.HttpClientHelper

        getAdapter, getSocketConnectTimeoutMs, handle, setAdapter
      • Methods inherited from class org.restlet.engine.connector.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​(org.restlet.Client client)
        Constructor.
        Parameters:
        client - The client to help.
    • Method Detail

      • 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 class org.restlet.engine.adapter.HttpClientHelper
        Parameters:
        request - The high-level request.
        Returns:
        A low-level HTTP client call.
      • getAddressResolutionTimeout

        public long getAddressResolutionTimeout()
        The timeout in milliseconds for the DNS resolution of host addresses. Defaults to 15000.
        Returns:
        The address resolution timeout.
      • getBindAddress

        public java.net.SocketAddress getBindAddress()
        The address to bind socket channels to. Default to null.
        Returns:
        The bind address or null.
      • getConnectTimeout

        public long getConnectTimeout()
        The max time in milliseconds a connection can take to connect to destinations. Defaults to 15000.
        Returns:
        The connect timeout.
      • getCookieStore

        public java.net.CookieStore getCookieStore()
        The cookie store. Defaults to null. When null, creates a new instance of InMemoryCookieStore.
        Returns:
        The cookie store.
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
        The executor. Defaults to null. When null, creates a new instance of QueuedThreadPool.
        Returns:
        The executor.
      • getHttpClient

        public org.eclipse.jetty.client.HttpClient getHttpClient()
        Returns the wrapped Jetty HTTP client.
        Returns:
        The wrapped Jetty HTTP client.
      • getIdleTimeout

        public long getIdleTimeout()
        The max time in milliseconds a connection can be idle (that is, without traffic of bytes in either direction). Defaults to 60000.
        Returns:
        The idle timeout.
      • getMaxConnectionsPerDestination

        public int getMaxConnectionsPerDestination()
        Sets the max number of connections to open to each destination. Defaults to 10.

        RFC 2616 suggests that 2 connections should be opened per each destination, but browsers commonly open 6. If this client is used for load testing, it is common to have only one destination (the server to load test), and it is recommended to set this value to a high value (at least as much as the threads present in the executor).

        Returns:
        The maximum connections per destination.
      • getMaxRedirects

        public int getMaxRedirects()
        The max number of HTTP redirects that are followed. Defaults to 8.
        Returns:
        The maximum redirects.
      • getMaxRequestsQueuedPerDestination

        public int getMaxRequestsQueuedPerDestination()
        Sets the max number of requests that may be queued to a destination. Defaults to 1024.

        If this client performs a high rate of requests to a destination, and all the connections managed by that destination are busy with other requests, then new requests will be queued up in the destination. This parameter controls how many requests can be queued before starting to reject them. If this client is used for load testing, it is common to have this parameter set to a high value, although this may impact latency (requests sit in the queue for a long time before being sent).

        Returns:
        The maximum requests queues per destination.
      • getRequestBufferSize

        public int getRequestBufferSize()
        The size in bytes of the buffer used to write requests. Defaults to 4096.
        Returns:
        The request buffer size.
      • getResponseBufferSize

        public int getResponseBufferSize()
        The size in bytes of the buffer used to read responses. Defaults to 16384.
        Returns:
        The response buffer size.
      • getScheduler

        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
        The scheduler. Defaults to null. When null, creates a new instance of ScheduledExecutorScheduler.
        Returns:
        The scheduler.
      • getStopTimeout

        public long getStopTimeout()
        Stop timeout in milliseconds. Defaults to 60000.

        The maximum time allowed for the service to shutdown.

        Returns:
        The stop timeout.
      • getUserAgentField

        public java.lang.String getUserAgentField()
        The "User-Agent" HTTP header string. When null, uses the Jetty default. Defaults to null.
        Returns:
        The user agent field or null.
      • isDispatchIO

        public boolean isDispatchIO()
        Whether to dispatch I/O operations from the selector thread to a different thread. Defaults to true.

        This implementation never blocks on I/O operation, but invokes application callbacks that may take time to execute or block on other I/O. If application callbacks are known to take time or block on I/O, then this should be set to true. If application callbacks are known to be quick and never block on I/O, then this may be set to false.

        Returns:
        Whether to dispatch I/O.
      • isFollowRedirects

        public boolean isFollowRedirects()
        Whether to follow HTTP redirects. Defaults to true.
        Returns:
        Whether to follow redirects.
      • isStrictEventOrdering

        public boolean isStrictEventOrdering()
        Whether request events must be strictly ordered. Defaults to false.

        Client listeners may send a second request. If the second request is for the same destination, there is an inherent race condition for the use of the connection: the first request may still be associated with the connection, so the second request cannot use that connection and is forced to open another one.

        From the point of view of connection usage, the connection is reusable just before the "complete" event, so it would be possible to reuse that connection from complete listeners; but in this case the second request's events will fire before the "complete" events of the first request.

        This setting enforces strict event ordering so that a "begin" event of a second request can never fire before the "complete" event of a first request, but at the expense of an increased usage of connections.

        When not enforced, a "begin" event of a second request may happen before the "complete" event of a first request and allow for better usage of connections.

        Returns:
        Whether request events must be strictly ordered.
      • isTcpNoDelay

        public boolean isTcpNoDelay()
        Whether TCP_NODELAY is enabled. Defaults to true.
        Returns:
        Whether TCP_NODELAY is enabled.
      • start

        public void start()
                   throws java.lang.Exception
        Overrides:
        start in class org.restlet.engine.connector.ConnectorHelper<org.restlet.Client>
        Throws:
        java.lang.Exception
      • stop

        public void stop()
                  throws java.lang.Exception
        Overrides:
        stop in class org.restlet.engine.connector.ConnectorHelper<org.restlet.Client>
        Throws:
        java.lang.Exception