Enum HttpClientStrategy
- All Implemented Interfaces:
Serializable
,Comparable<HttpClientStrategy>
,java.lang.constant.Constable
Available strategies that can be used to build
appropriate implementation of http client.
Currently, following strategies are available:
ASYNC_HTTP_CLIENT
: use the async-http-client library.OK_HTTP3
: use OkHttp library.NING_ASYNC_HTTP_CLIENT
: use async-http-client from ning library.APACHE_HTTP_CLIENT
: use apache http-client library.AUTO
: use classpath detection and choose the best available strategy (see below).
How the "best" strategy is selected:
Classpath detection is implemented in this order:
- If OkHttp library is detected, this strategy is automatically selected.
- If async-http-client is detected, this strategy is automatically (note that this strategy will be skipped with a jdk < 8, since this library requires Java 8).
- Third test is ning-async-http-client, and it will be selected if library is detected.
- Finally, apache httpcomponent will be selected if available.
- If none of these libraries are available, an exception will be thrown.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionBuild http client using ApacheHttpClient library.Build http client using AsyncHttpClient library.Detect class available on classpath and use appropriate strategy to build http client client implementation: TryOK_HTTP3
. TryASYNC_HTTP_CLIENT
. TryNING_ASYNC_HTTP_CLIENT
. TryAPACHE_HTTP_CLIENT
.Build http client using (Ning) AsyncHttpClient library.Build http client using OkHttp library. -
Method Summary
Modifier and TypeMethodDescriptionbuild
(HttpClientConfiguration configuration, EmbeddedServer<? extends AbstractConfiguration> server) Return the http client implementation.build
(EmbeddedServer<? extends AbstractConfiguration> server) Return the http client implementation.abstract boolean
support()
Check if the strategy can be used as it is supported by the runtime environment.static HttpClientStrategy
Returns the enum constant of this type with the specified name.static HttpClientStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
OK_HTTP3
Build http client using OkHttp library. -
ASYNC_HTTP_CLIENT
Build http client using AsyncHttpClient library.This strategy requires Java 8.
-
NING_ASYNC_HTTP_CLIENT
Build http client using (Ning) AsyncHttpClient library. -
APACHE_HTTP_CLIENT
Build http client using ApacheHttpClient library. -
AUTO
Detect class available on classpath and use appropriate strategy to build http client client implementation:- Try
OK_HTTP3
. - Try
ASYNC_HTTP_CLIENT
. - Try
NING_ASYNC_HTTP_CLIENT
. - Try
APACHE_HTTP_CLIENT
.
- Try
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
build
Return the http client implementation.- Parameters:
server
- Embedded server.- Returns:
- Http client.
- Throws:
UnsupportedOperationException
- If the runtime environment does not allow the strategy (such as: the library has not been imported).
-
build
public HttpClient build(HttpClientConfiguration configuration, EmbeddedServer<? extends AbstractConfiguration> server) Return the http client implementation.- Parameters:
configuration
- HTTP Client configuration.server
- Embedded server.- Returns:
- Http client.
- Throws:
UnsupportedOperationException
- If the runtime environment does not allow the strategy (such as: the library has not been imported).
-
support
public abstract boolean support()Check if the strategy can be used as it is supported by the runtime environment.- Returns:
true
if the strategy can be instantiated,false
otherwise.
-