Class HttpClientAccessor
HttpClients.-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.http.client.HttpClientReturns anHttpClientindependent of any destination.static org.apache.http.client.HttpClientgetHttpClient(Destination destination) Returns anHttpClientfor the givenDestination.static org.apache.http.client.HttpClientgetHttpClient(HttpDestinationProperties destination) Returns anHttpClientfor the givenDestination.static HttpClientCacheConfigures theHttpClientCachethat is used by the#getHttpClient(String)and#getHttpClient(Destination)methods.static HttpClientFactoryReturns theHttpClientFactorythat is used when creating instances ofHttpClientwithin theHttpClientAccessor.static voidsetHttpClientCache(HttpClientCache httpClientCache) Sets theHttpClientCachethat is used when resolving cached instances ofHttpClientwithin theHttpClientAccessor.static voidsetHttpClientFactory(HttpClientFactory httpClientFactory) Sets theHttpClientFactorythat is used when creating instances ofHttpClientwithin theHttpClientAccessor.static io.vavr.control.Try<org.apache.http.client.HttpClient>Returns anHttpClientindependent of any destination.static io.vavr.control.Try<org.apache.http.client.HttpClient>tryGetHttpClient(Destination destination)
-
Method Details
-
getHttpClientFactory
Returns theHttpClientFactorythat is used when creating instances ofHttpClientwithin theHttpClientAccessor.- Returns:
- The
HttpClientFactory.
-
setHttpClientFactory
Sets theHttpClientFactorythat is used when creating instances ofHttpClientwithin theHttpClientAccessor.CAUTION: This factory is accessed concurrently. Therefore, you have to make sure that you do not introduce any concurrency issues when changing the factory. Furthermore, be aware that setting a custom factory will affect all consumers of the
HttpClientAccessorwithin the application.- Parameters:
httpClientFactory- The globalHttpClientFactoryinstance to be used. Usenullto reset the factory.
-
setHttpClientCache
Sets theHttpClientCachethat is used when resolving cached instances ofHttpClientwithin theHttpClientAccessor.CAUTION: This cache is accessed concurrently. Therefore, you have to make sure that you do not introduce any concurrency issues when changing the cache. Furthermore, be aware that setting a custom cache will affect all consumers of the
HttpClientAccessorwithin the application.- Parameters:
httpClientCache- The globalHttpClientCacheinstance to be used. Usenullto reset the cache.
-
getHttpClient
@Nonnull public static org.apache.http.client.HttpClient getHttpClient() throws HttpClientInstantiationExceptionReturns anHttpClientindependent of any destination.- Returns:
- An
HttpClientindependent of any destination. - Throws:
HttpClientInstantiationException- If there is an issue creating theHttpClient.
-
tryGetHttpClient
@Nonnull public static io.vavr.control.Try<org.apache.http.client.HttpClient> tryGetHttpClient()Returns anHttpClientindependent of any destination.- Returns:
- An
HttpClientindependent of any destination.
-
getHttpClient
@Nonnull public static org.apache.http.client.HttpClient getHttpClient(@Nonnull HttpDestinationProperties destination) throws DestinationAccessException, HttpClientInstantiationException Returns anHttpClientfor the givenDestination. The instance may be cached.- Parameters:
destination- The destination to get theHttpClientfor.- Returns:
- An
HttpClientfor the givenDestination. The instance may be cached. - Throws:
DestinationAccessException- If there is an issue accessing theDestination.HttpClientInstantiationException- If there is an issue creating theHttpClient.
-
getHttpClient
@Nonnull public static org.apache.http.client.HttpClient getHttpClient(@Nonnull Destination destination) throws DestinationAccessException, HttpClientInstantiationException Returns anHttpClientfor the givenDestination. The instance may be cached.- Parameters:
destination- The destination to get theHttpClientfor.- Returns:
- An
HttpClientfor the givenDestination. The instance may be cached. - Throws:
DestinationAccessException- If there is an issue accessing theDestination.HttpClientInstantiationException- If there is an issue creating theHttpClient.
-
tryGetHttpClient
@Nonnull public static io.vavr.control.Try<org.apache.http.client.HttpClient> tryGetHttpClient(@Nonnull Destination destination) - Parameters:
destination- The destination to get theHttpClientfor.- Returns:
- A
Tryof anHttpClientfor the givenDestination. The instance may be cached.
-
getHttpClientCache
Configures theHttpClientCachethat is used by the#getHttpClient(String)and#getHttpClient(Destination)methods.By default, this uses the
DefaultHttpClientCacheimplementation, which caches theHttpClientfor 1 hour.CAUTION: This factory is accessed concurrently. Therefore, you have to make sure that you do not introduce any concurrency issues when changing the factory. Furthermore, be aware that setting a custom factory will affect all consumers of the
HttpClientAccessorwithin the application.
-