Class ApacheHttpClient5Accessor
HttpClients.- Since:
- 4.20.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.hc.client5.http.classic.HttpClientReturns anHttpClientindependent of any destination.static org.apache.hc.client5.http.classic.HttpClientgetHttpClient(Destination destination) Returns anHttpClientfor the givenDestination.static org.apache.hc.client5.http.classic.HttpClientgetHttpClient(HttpDestinationProperties destination) Returns anHttpClientfor the givenDestination.static ApacheHttpClient5CacheConfigures theHttpClient5Cachethat is used by the#getHttpClient(String)and#getHttpClient(Destination)methods.static ApacheHttpClient5FactoryReturns theApacheHttpClient5Factorythat is used when creating instances ofHttpClientwithin theApacheHttpClient5Accessor.static voidsetHttpClientCache(ApacheHttpClient5Cache httpClientCache) Sets theApacheHttpClient5Cachethat is used when resolving cached instances ofHttpClientwithin theApacheHttpClient5Accessor.static voidsetHttpClientFactory(ApacheHttpClient5Factory httpClientFactory) Sets theApacheHttpClient5Factorythat is used when creating instances ofHttpClientwithin theApacheHttpClient5Accessor.static io.vavr.control.Try<org.apache.hc.client5.http.classic.HttpClient>Returns anHttpClientindependent of any destination.static io.vavr.control.Try<org.apache.hc.client5.http.classic.HttpClient>tryGetHttpClient(Destination destination)
-
Method Details
-
setHttpClientFactory
Sets theApacheHttpClient5Factorythat is used when creating instances ofHttpClientwithin theApacheHttpClient5Accessor.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
ApacheHttpClient5Accessorwithin the application.- Parameters:
httpClientFactory- The globalApacheHttpClient5Factoryinstance to be used. Usenullto reset the factory.
-
setHttpClientCache
Sets theApacheHttpClient5Cachethat is used when resolving cached instances ofHttpClientwithin theApacheHttpClient5Accessor.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
ApacheHttpClient5Accessorwithin the application.- Parameters:
httpClientCache- The globalApacheHttpClient5Cacheinstance to be used. Usenullto reset the cache.
-
getHttpClient
@Nonnull public static org.apache.hc.client5.http.classic.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.hc.client5.http.classic.HttpClient> tryGetHttpClient()Returns anHttpClientindependent of any destination.- Returns:
- An
HttpClientindependent of any destination.
-
getHttpClient
@Nonnull public static org.apache.hc.client5.http.classic.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.hc.client5.http.classic.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.hc.client5.http.classic.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 theHttpClient5Cachethat is used by the#getHttpClient(String)and#getHttpClient(Destination)methods.By default, this uses an implementation, which caches the
HttpClientfor 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
ApacheHttpClient5Accessorwithin the application. -
getHttpClientFactory
Returns theApacheHttpClient5Factorythat is used when creating instances ofHttpClientwithin theApacheHttpClient5Accessor.
-