Class HttpClientHandlerHeaplet
- java.lang.Object
-
- org.forgerock.openig.heap.GenericHeaplet
-
- org.forgerock.openig.handler.HttpClientHandlerHeaplet
-
- All Implemented Interfaces:
Heaplet
- Direct Known Subclasses:
ClientHandlerHeaplet
,ReverseProxyHandlerHeaplet
public abstract class HttpClientHandlerHeaplet extends GenericHeaplet
Abstract Heaplet to create HTTP clients with different behaviors. In this implementation, requests are dispatched through a CHFHttpClient
. All types created from thisHeaplet
with support the following configuration items:"config": { "protocolVersion": "HTTP/2", "connections": 64, "disableReuseConnection": true, "stateTrackingEnabled": true, "soTimeout": "10 seconds", "connectionTimeout": "10 seconds", "connectionTimeToLive": "30 seconds", "numberOfWorkers": 6, "proxyOptions": "myProxyOptions", "temporaryStorage": {reference to or inline declaration of a TemporaryStorage}, "asyncBehavior": "streaming" or "non_streaming", "tls": { "type": "ClientTlsOptions", "config": { "sslContextAlgorithm": "TLS", "keyManager": [ "RefToKeyManager", ... ], "trustManager": [ "RefToTrustManager", ... ], "sslEnabledProtocols": [ "SSLv2", ... ], "sslCipherSuites": [ "TLS_DH_anon_WITH_AES_256_CBC_SHA256", ... ], "alpn": { "enabled": true } } } "retries": { "enabled": true, "executor" "ScheduledExecutorService", "count": "5", "delay": "10 seconds", "condition": "${response.status.code == 502}" }, "circuitBreaker": { "enabled": true, "maxFailures": 10, "openDuration": "1 minute", "openHandler": "myHandlerReference", "slidingCounter": { "size": 100 } } }
The connectionTimeout optional attribute specifies a connection timeout (the given amount of time to wait until the connection is established). It defaults to 10 seconds. *
The connectionTimeToLive optional attribute specifies a connection time-to-live (the amount of time before a reusable pooled connection expires). It defaults to never expiring. An example of where changing this from the default so connections from the pool expire would be whereClientHandler
connections to an application go through a load-balancer and the load-balancer's IP address has changed due to resource changes so new connections should end up at the new IP based on underlying DNS updates.The numberOfWorkers optional attribute specifies the number of threads dedicated to process outgoing requests. It defaults to the number of CPUs available to the JVM. This attribute is only used if an asynchronous Http client engine is used (that is the default).
The asyncBehavior optional attribute specifies how the HTTP client should behave with regard to asynchronous responses.
- streaming: response is processed as soon as all headers have been received (entity content is downloaded in a background thread). May lead to thread starvation issue, but is mandatory for SSE and very large file support
- non_streaming: response is processed when the entity content is entirely available, latency is higher but thread starvation will not happen. Does not support SSE or very large files (more than 2GB).
The retries optional attribute, if supported by the
Heaplet
and enabled, will retry the failed request a number of times, each separated by a delay. It is disabled by default, unless the retries attribute is provided, and its enabled setting not set to false (defaults to true).The circuitBreaker optional attribute, will add a
CircuitBreakerFilter
in front of the HTTP client. When circuitBreaker and retries are both set, theCircuitBreakerFilter
fronts theRetryFilter
, which means you should account for retries when defining the maxFailures. For example: if each request is retried 3 times, then on connection failure 3 request retry attempts will only count for 1 failure.The protocolVersion optional attribute specifies the protocol to use when sending the requests. It defaults to 'HTTP/1.1'. The other possible value is 'HTTP/2'.
The http2PriorKnowledge optional attribute specifies the strategy to use when sending HTTP/2 requests. If false (default value), then when issuing non-TLS requests using the HTTP/2 protocol, the client will first send an HTTP/1.1 requesting an upgrade to HTTP/2, that may be accepted or not by the server. If true, then when issuing non-TLS requests using the HTTP/2 protocol, the client will send directly an HTTP/2 request, requiring some prior knowledge that the server effectively supports HTTP/2.
- See Also:
Duration
,KeyManagerHeaplet
,TrustManagerHeaplet
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_ASYNC_BEHAVIOR
Constant for the configuration asyncBehavior.static String
CONFIG_ENABLE_CONNECTION_STATE
Constant for the configuration stateTrackingEnabled.static String
CONFIG_HTTP2_PRIOR_KNOWLEDGE
Constant for the configuration http2PriorKnowledge.static String
CONFIG_NUMBER_OF_WORKERS
Constant for the configuration numberOfWorkers.static String
CONFIG_PROTOCOL_VERSION
Constant for the configuration protocolVersion.
-
Constructor Summary
Constructors Constructor Description HttpClientHandlerHeaplet()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Optional<Filter>
circuitBreakerFilter(JsonValue config)
protected boolean
configurationSupported(org.forgerock.openig.http.spi.HttpClientLoader loader, JsonValue value)
Is the provided configuration supported by theHttpClientLoader
.Object
create()
Called to request the heaplet create an object.void
destroy()
Called to indicate that the object created by the heaplet is going to be dereferenced.protected abstract List<Filter>
filters(org.forgerock.openig.http.spi.HttpClientLoader loader, Options options)
Returns a list ofFilter
that will be executed on every request before theHttpClientHandler
.protected Optional<Filter>
retryFilter(JsonValue config, org.forgerock.monitoring.api.instrument.MeterRegistry meterRegistry)
Returns aRetryFilter
if the provided configuration enabled its usage, or empty if not.-
Methods inherited from class org.forgerock.openig.heap.GenericHeaplet
create, endpointRegistry, evaluatedWithHeapProperties, expression, getConfig, getHeap, getSecretService, getType, meterRegistryHolder, start
-
-
-
-
Field Detail
-
CONFIG_ASYNC_BEHAVIOR
public static final String CONFIG_ASYNC_BEHAVIOR
Constant for the configuration asyncBehavior.- See Also:
- Constant Field Values
-
CONFIG_NUMBER_OF_WORKERS
public static final String CONFIG_NUMBER_OF_WORKERS
Constant for the configuration numberOfWorkers.- See Also:
- Constant Field Values
-
CONFIG_PROTOCOL_VERSION
public static final String CONFIG_PROTOCOL_VERSION
Constant for the configuration protocolVersion.- See Also:
- Constant Field Values
-
CONFIG_HTTP2_PRIOR_KNOWLEDGE
public static final String CONFIG_HTTP2_PRIOR_KNOWLEDGE
Constant for the configuration http2PriorKnowledge.- See Also:
- Constant Field Values
-
CONFIG_ENABLE_CONNECTION_STATE
public static final String CONFIG_ENABLE_CONNECTION_STATE
Constant for the configuration stateTrackingEnabled.- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public final Object create() throws HeapException
Description copied from class:GenericHeaplet
Called to request the heaplet create an object. Called byHeaplet.create(Name, JsonValue, Heap)
after initializing the protected field members. Implementations should parse configuration but not acquire resources, start threads, or log any initialization messages. These tasks should be performed by theGenericHeaplet.start()
method.- Specified by:
create
in classGenericHeaplet
- Returns:
- The created object.
- Throws:
HeapException
- if an exception occurred during creation of the heap object or any of its dependencies.
-
configurationSupported
protected final boolean configurationSupported(org.forgerock.openig.http.spi.HttpClientLoader loader, JsonValue value)
Is the provided configuration supported by theHttpClientLoader
.- Parameters:
loader
- theHttpClientLoader
.value
- the configuration to know if it is supported or not.- Returns:
- true if the provided configuration is supported by this
HttpClientLoader
, false otherwise.
-
retryFilter
protected final Optional<Filter> retryFilter(JsonValue config, org.forgerock.monitoring.api.instrument.MeterRegistry meterRegistry) throws HeapException
Returns aRetryFilter
if the provided configuration enabled its usage, or empty if not.- Parameters:
config
- the whole configuration.meterRegistry
- TheMeterRegistry
to use.- Returns:
- a
RetryFilter
if the provided configuration enabled its usage, or empty if not. - Throws:
HeapException
- if any error occurs during the setup of theRetryFilter
.
-
circuitBreakerFilter
protected final Optional<Filter> circuitBreakerFilter(JsonValue config) throws HeapException
- Throws:
HeapException
-
destroy
public void destroy()
Description copied from interface:Heaplet
Called to indicate that the object created by the heaplet is going to be dereferenced. This gives the heaplet an opportunity to free any resources that are being held prior to its dereference.- Specified by:
destroy
in interfaceHeaplet
- Overrides:
destroy
in classGenericHeaplet
-
filters
protected abstract List<Filter> filters(org.forgerock.openig.http.spi.HttpClientLoader loader, Options options) throws HeapException
Returns a list ofFilter
that will be executed on every request before theHttpClientHandler
.- Parameters:
loader
- theHttpClientLoader
associated to that instance.options
- the options that will be used to create theHttpClientHandler
.- Returns:
- A list of
Filter
that will be executed on every request before theHttpClientHandler
. - Throws:
HeapException
- if any error occurs during the setup of the filters.
-
-