Class HttpClientHelper
- java.lang.Object
-
- org.restlet.engine.Helper
-
- org.restlet.engine.RestletHelper<T>
-
- org.restlet.engine.connector.ConnectorHelper<Client>
-
- org.restlet.engine.connector.ClientHelper
-
- org.restlet.engine.adapter.HttpClientHelper
-
- org.restlet.ext.jetty.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:
For the default SSL parameters see the Javadocs of theParameter 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 SslContextFactoryqualified class name as a parameter, or an instance as an attribute for a more complete and flexible SSL context settingDefaultSslContextFactoryclass.- See Also:
- Jetty home page
-
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.jetty.client.HttpClienthttpClientThe wrapped Jetty HTTP client.
-
Constructor Summary
Constructors Constructor Description HttpClientHelper(Client client)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClientCallcreate(Request request)Creates a low-level HTTP client call from a high-level uniform call.private org.eclipse.jetty.client.HttpClientcreateHttpClient()Creates a Jetty HTTP client.longgetAddressResolutionTimeout()The timeout in milliseconds for the DNS resolution of host addresses.java.net.SocketAddressgetBindAddress()The address to bind socket channels to.longgetConnectTimeout()The max time in milliseconds a connection can take to connect to destinations.java.net.CookieStoregetCookieStore()The cookie store.java.util.concurrent.ExecutorgetExecutor()The executor.org.eclipse.jetty.client.HttpClientgetHttpClient()Returns the wrapped Jetty HTTP client.longgetIdleTimeout()The max time in milliseconds a connection can be idle (that is, without traffic of bytes in either direction).intgetMaxConnectionsPerDestination()Sets the max number of connections to open to each destination.intgetMaxRedirects()The max number of HTTP redirects that are followed.intgetMaxRequestsQueuedPerDestination()Sets the max number of requests that may be queued to a destination.intgetRequestBufferSize()The size in bytes of the buffer used to write requests.intgetResponseBufferSize()The size in bytes of the buffer used to read responses.org.eclipse.jetty.util.thread.SchedulergetScheduler()The scheduler.longgetStopTimeout()Stop timeout in milliseconds.java.lang.StringgetUserAgentField()The "User-Agent" HTTP header string.booleanisDispatchIO()Whether to dispatch I/O operations from the selector thread to a different thread.booleanisFollowRedirects()Whether to follow HTTP redirects.booleanisStrictEventOrdering()Whether request events must be strictly ordered.booleanisTcpNoDelay()Whether TCP_NODELAY is enabled.voidstart()Start callback.voidstop()Stop callback.-
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
-
-
-
-
Constructor Detail
-
HttpClientHelper
public HttpClientHelper(Client client)
Constructor.- Parameters:
client- The client to help.
-
-
Method Detail
-
create
public ClientCall create(Request request)
Creates a low-level HTTP client call from a high-level uniform call.- Specified by:
createin classHttpClientHelper- Parameters:
request- The high-level request.- Returns:
- A low-level HTTP client call.
-
createHttpClient
private 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.
-
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 ofInMemoryCookieStore.- Returns:
- The cookie store.
-
getExecutor
public java.util.concurrent.Executor getExecutor()
The executor. Defaults to null. When null, creates a new instance ofQueuedThreadPool.- 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 ofScheduledExecutorScheduler.- 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.ExceptionDescription copied from class:RestletHelperStart callback.- Overrides:
startin classConnectorHelper<Client>- Throws:
java.lang.Exception
-
stop
public void stop() throws java.lang.ExceptionDescription copied from class:RestletHelperStop callback.- Overrides:
stopin classConnectorHelper<Client>- Throws:
java.lang.Exception
-
-