Class HttpClientHandler
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Handler
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
SSL host name verification policies.static final class
Encapsulates the details of the proxy if one is required when making outgoing requests. -
Field Summary
Modifier and TypeFieldDescriptionThe TCP connect timeout for new HTTP connections.This option is only taken into account whenOPTION_REUSE_CONNECTIONS
is also set to true.static final Option<HttpClientHandler.HostnameVerifier>
Specifies the SSL host name verification policy.static final Option<KeyManagerFactory>
Specifies the key manager factory that should be used when configuring SSL/TLS connections.static final Option<KeyManager[]>
Specifies the list of key managers that should be used when configuring SSL/TLS connections.The strategy which should be used for loading theHttpClientProvider
.Specifies the maximum number of connections that should be pooled by the HTTP client.Specifies the list of hosts for which requests should not be proxied.Specifies the time to live (expiry time) in milliseconds of connections from the pool.static final Option<HttpClientHandler.ProxyInfo>
Specifies a proxy to use for requests by the HTTP Client.Specifies that the system defined proxy should be used for requests by the HTTP Client.Specifies whether requests should be retried if a failure is detected.Specifies whether HTTP connections should be kept alive and reused for additional requests.The TCP socket keep-alive feature.The TCP socket feature to linger on close if data is present.The TCP socket reuse address feature.The TCP socket timeout when waiting for HTTP responses.List of JSSE ciphers to be enabled on the HttpClient.List of SSL protocols to be enabled on the HttpClient.SSLContext algorithm to be used when making SSL/TLS connections.The TCP socket feature to disable the Nagle algorithm; that algorithm aims to coalesce short segments and improve network efficiency.Specifies the temporary storage that should be used for storing HTTP responses.static final Option<TrustManagerFactory>
Specifies the trust manager factory that should be used when configuring SSL/TLS connections.static final Option<TrustManager[]>
Specifies the list of trust managers that should be used when configuring SSL/TLS connections. -
Constructor Summary
ConstructorDescriptionCreates a new HTTP client using default client options.HttpClientHandler
(Options options) Creates a new HTTP client using the provided client options. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Completes all pending requests and release resources associated with underlying implementation.Sends an HTTP request to a remote server and returns aPromise
representing the asynchronous response.
-
Field Details
-
OPTION_CONNECT_TIMEOUT
The TCP connect timeout for new HTTP connections. The default timeout is 10 seconds. -
OPTION_SO_TIMEOUT
The TCP socket timeout when waiting for HTTP responses. The default timeout is 10 seconds. -
OPTION_SO_KEEP_ALIVE
The TCP socket keep-alive feature. The default is false, to be consistent withStandardSocketOptions.SO_KEEPALIVE
-
OPTION_SO_REUSE_ADDRESS
The TCP socket reuse address feature. There is no default value, to be consistent withStandardSocketOptions.SO_REUSEADDR
as the default value is system dependent. -
OPTION_SO_LINGER
The TCP socket feature to linger on close if data is present. The default is -1, meaning that it is disabled, to be consistent withStandardSocketOptions.SO_LINGER
. -
OPTION_TCP_NO_DELAY
The TCP socket feature to disable the Nagle algorithm; that algorithm aims to coalesce short segments and improve network efficiency. The default isFALSE
, meaning that it is disabled, to be consistent withStandardSocketOptions.TCP_NODELAY
. -
OPTION_REUSE_CONNECTIONS
Specifies whether HTTP connections should be kept alive and reused for additional requests. By default, connections will be reused if possible. -
OPTION_DISABLE_CONNECTION_STATE
This option is only taken into account whenOPTION_REUSE_CONNECTIONS
is also set to true. Setting this to true can help with performance in the case where a client certificate is being used as it will change the Apache HTTP Client default behaviour which is to not allow connection reuse when a client certificate is being used for authentication. Since the client certificate is defined at the client level, all requests to the same target will be sharing the same client certificate so enabling this should not be an issue. This option is not enabled by default to ensure that there is still control over when it is applied. In the context of Apache HTTP Client and stateful requests:There are cases when HTTP connections are created with a particular user identity or within a particular security context and therefore cannot be shared with other users and can be reused by the same user only. Examples of such stateful HTTP connections are NTLM authenticated connections and SSL connections with client certificate authentication.
-
OPTION_RETRY_REQUESTS
Specifies whether requests should be retried if a failure is detected. By default requests will be retried. -
OPTION_KEY_MANAGERS
Specifies the list of key managers that should be used when configuring SSL/TLS connections. By default the system key manager(s) will be used. -
OPTION_KEY_MANAGER_FACTORY
Specifies the key manager factory that should be used when configuring SSL/TLS connections. -
OPTION_LOADER
The strategy which should be used for loading theHttpClientProvider
. By default, the provider will be loaded using aServiceLoader
.- See Also:
-
OPTION_MAX_CONNECTIONS
Specifies the maximum number of connections that should be pooled by the HTTP client. At most 64 connections will be cached by default. -
OPTION_TEMPORARY_STORAGE
Specifies the temporary storage that should be used for storing HTTP responses. By defaultIO.newTemporaryStorage()
is used. -
OPTION_TRUST_MANAGERS
Specifies the list of trust managers that should be used when configuring SSL/TLS connections. By default the system trust manager(s) will be used. -
OPTION_TRUST_MANAGER_FACTORY
Specifies the trust manager factory that should be used when configuring SSL/TLS connections. -
OPTION_PROXY
Specifies a proxy to use for requests by the HTTP Client. -
OPTION_PROXY_SYSTEM
Specifies that the system defined proxy should be used for requests by the HTTP Client. When OPTION_PROXY is defined it takes precedence over this option. By default, no proxies are used. -
OPTION_NON_PROXY_HOSTS
Specifies the list of hosts for which requests should not be proxied. Only used when OPTION_PROXY is also specified. -
OPTION_POOLED_CONNECTION_TTL
Specifies the time to live (expiry time) in milliseconds of connections from the pool. By default they are set to not expire. The underlying Apache API uses a negative value to indicate no expiry. -
OPTION_HOSTNAME_VERIFIER
Specifies the SSL host name verification policy. The default is strict matching. -
OPTION_SSLCONTEXT_ALGORITHM
SSLContext algorithm to be used when making SSL/TLS connections. -
OPTION_SSL_ENABLED_PROTOCOLS
List of SSL protocols to be enabled on the HttpClient. Defaults to TLSv1.3 and TLSv1.2.- See Also:
-
OPTION_SSL_CIPHER_SUITES
List of JSSE ciphers to be enabled on the HttpClient. Defaults to the list of ciphers supported by the Java runtime.- See Also:
-
-
Constructor Details
-
HttpClientHandler
Creates a new HTTP client using default client options. The returned client must be closed when it is no longer needed by the application.- Throws:
HttpApplicationException
- If no client provider could be found.
-
HttpClientHandler
Creates a new HTTP client using the provided client options. The returned client must be closed when it is no longer needed by the application.- Parameters:
options
- The options which will be used to configure the client.- Throws:
HttpApplicationException
- If no client provider could be found, or if the client could not be configured using the provided set of options.NullPointerException
- Ifoptions
wasnull
.
-
-
Method Details
-
close
Completes all pending requests and release resources associated with underlying implementation.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurs
-
handle
Sends an HTTP request to a remote server and returns aPromise
representing the asynchronous response.Returns a
Promise
representing the asynchronousResponse
of the givenrequest
. If any (asynchronous) processing goes wrong, the promise still contains aResponse
(probably from the 4xx or 5xx status code family).A handler that doesn't hand-off the processing to another downstream handler is responsible for creating the response.
The returned
Promise
contains the response returned from the server as-is. This is responsibility of the handler to produce the appropriate error response (404, 500, ...) in case of processing error.Note: As of Promise 2.0 implementation, it is not permitted to throw any runtime exception here. Doing so produce unexpected behaviour (most likely a server-side hang of the processing thread).
-