Class HttpClientHelper


public class HttpClientHelper extends 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
cookieSupported boolean false Whether to support HTTP cookie, storing and automatically sending them back
connectBlocking boolean false Indicates whether the connect operation is blocking. See HttpClient.isConnectBlocking().
connectTimeout long 15000 The max time in milliseconds a connection can take to connect to destinations
destinationIdleTimeout long 0 the time in milliseconds after which idle destinations are removed
followRedirects boolean true Whether to follow HTTP redirects
httpComplianceMode String RFC7230 Indicate the HTTP compliance mode among the following options: "RFC7230", "RFC2616", "LEGACY", "RFC7230_LEGACY". See HttpCompliance.
httpClientTransportMode String HTTP1_1 Indicate the HTTP client transport mode among the following options: "HTTP1_1", "HTTP2", "HTTP3", "DYNAMIC". See HttpClientTransport.
idleTimeout long 30000 The max time in milliseconds a connection can be idle (that is, without traffic of bytes in either direction)
maxConnectionsPerDestination int 64 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
maxResponseHeaderSize int -1 The max size in bytes of the response headers. -1 is unlimited.
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.
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
strictEventOrdering boolean false Whether request events must be strictly ordered
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
http3PemWorkDir string No default value Directory where are exported trusted certificates, required for HTTP3 support. There is no default value to let you configure a secured enough directory.
For the default SSL parameters see the Javadocs of the DefaultSslContextFactory class.
Author:
Jerome Louvel, Tal Liron
  • Constructor Details

    • HttpClientHelper

      public HttpClientHelper(Client client)
      Constructor. Properties can still be set before the wrapped Jetty HTTP client is effectively created and configured via the createHttpClient() method.
      Parameters:
      client - The client connector to help.
  • Method Details

    • 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.
    • createHttpClient

      protected org.eclipse.jetty.client.HttpClient createHttpClient()
      Creates a Jetty HTTP client.
      Returns:
      A new HTTP client.
    • getAddressResolutionTimeout

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

      public org.eclipse.jetty.client.AuthenticationStore getAuthenticationStore()
      Returns the wrapped Jetty authentication store.
      Returns:
      The wrapped Jetty authentication store.
    • setAuthenticationStore

      public void setAuthenticationStore(org.eclipse.jetty.client.AuthenticationStore authenticationStore)
      Sets the wrapped Jetty authentication store.
      Parameters:
      authenticationStore - The wrapped Jetty authentication store.
    • getBindAddress

      public 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 org.eclipse.jetty.http.HttpCookieStore getCookieStore()
      Returns the wrapped Jetty cookie store.
      Returns:
      The wrapped Jetty cookie store.
    • setCookieStore

      public void setCookieStore(org.eclipse.jetty.http.HttpCookieStore cookieStore)
      Sets the wrapped Jetty cookie store.
      Parameters:
      cookieStore - The wrapped Jetty cookie store.
    • getDestinationIdleTimeout

      public long getDestinationIdleTimeout()
      The timeout in milliseconds for idle destinations to be removed. Defaults to 0.
      Returns:
      The address resolution timeout.
    • getExecutor

      public Executor getExecutor()
      Returns the executor. By default, returns an instance of QueuedThreadPool.
      Returns:
      Returns the executor.
    • setExecutor

      public void setExecutor(Executor executor)
      Sets the executor.
      Parameters:
      executor - The executor.
    • getHttpClient

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

      public String getHttpComplianceMode()
      Returns the HTTP compliance mode among the following options: "RFC7230", "RFC2616", "LEGACY", "RFC7230_LEGACY". See HttpCompliance. Default to "RFC7230".
      Returns:
      The HTTP compliance mode.
    • getHttpClientTransportMode

      public String getHttpClientTransportMode()
      Returns the HTTP client transport mode among the following options: "HTTP1_1", "HTTP2", "HTTP3", "DYNAMIC. See HttpClientTransport. Default to "HTTP1_1".
      Returns:
      The HTTP client transport mode.
    • getHttp3PemWorkDir

      public String getHttp3PemWorkDir()
      Directory where are extracted the supported certificates.
      Returns:
      Directory where are extracted the supported certificates.
    • 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 30000.
      Returns:
      The idle timeout.
    • getMaxConnectionsPerDestination

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

      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.
    • getMaxResponseHeadersSize

      public int getMaxResponseHeadersSize()
      Returns the max size in bytes of the response headers. Default is -1 that is unlimited.
      Returns:
      the max size in bytes of the response headers.
    • 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.
    • 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.
    • getUserAgentField

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

      public boolean isConnectBlocking()
      Indicates whether the connect operation is blocking. See HttpClient.isConnectBlocking().
      Returns:
      True if the connect operation is blocking.
    • isCookieSupported

      public boolean isCookieSupported()
      Whether to support cookies, storing and automatically sending them back. Defaults to false.
      Returns:
      Whether to support cookies.
    • 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.
    • start

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

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