Class HttpClientAccessor

java.lang.Object
com.sap.cloud.sdk.cloudplatform.connectivity.HttpClientAccessor

public final class HttpClientAccessor extends Object
Accessor for HttpClients.
  • Method Details

    • getHttpClientFactory

      @Nonnull public static HttpClientFactory getHttpClientFactory()
      Returns the HttpClientFactory that is used when creating instances of HttpClient within the HttpClientAccessor.
      Returns:
      The HttpClientFactory.
    • setHttpClientFactory

      public static void setHttpClientFactory(@Nullable HttpClientFactory httpClientFactory)
      Sets the HttpClientFactory that is used when creating instances of HttpClient within the HttpClientAccessor.

      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 HttpClientAccessor within the application.

      Parameters:
      httpClientFactory - The global HttpClientFactory instance to be used. Use null to reset the factory.
    • setHttpClientCache

      public static void setHttpClientCache(@Nullable HttpClientCache httpClientCache)
      Sets the HttpClientCache that is used when resolving cached instances of HttpClient within the HttpClientAccessor.

      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 HttpClientAccessor within the application.

      Parameters:
      httpClientCache - The global HttpClientCache instance to be used. Use null to reset the cache.
    • getHttpClient

      @Nonnull public static org.apache.http.client.HttpClient getHttpClient() throws HttpClientInstantiationException
      Returns an HttpClient independent of any destination.
      Returns:
      An HttpClient independent of any destination.
      Throws:
      HttpClientInstantiationException - If there is an issue creating the HttpClient.
    • tryGetHttpClient

      @Nonnull public static io.vavr.control.Try<org.apache.http.client.HttpClient> tryGetHttpClient()
      Returns an HttpClient independent of any destination.
      Returns:
      An HttpClient independent of any destination.
    • getHttpClient

      @Nonnull public static org.apache.http.client.HttpClient getHttpClient(@Nonnull HttpDestinationProperties destination) throws DestinationAccessException, HttpClientInstantiationException
      Returns an HttpClient for the given Destination. The instance may be cached.
      Parameters:
      destination - The destination to get the HttpClient for.
      Returns:
      An HttpClient for the given Destination. The instance may be cached.
      Throws:
      DestinationAccessException - If there is an issue accessing the Destination.
      HttpClientInstantiationException - If there is an issue creating the HttpClient.
    • getHttpClient

      @Nonnull public static org.apache.http.client.HttpClient getHttpClient(@Nonnull Destination destination) throws DestinationAccessException, HttpClientInstantiationException
      Returns an HttpClient for the given Destination. The instance may be cached.
      Parameters:
      destination - The destination to get the HttpClient for.
      Returns:
      An HttpClient for the given Destination. The instance may be cached.
      Throws:
      DestinationAccessException - If there is an issue accessing the Destination.
      HttpClientInstantiationException - If there is an issue creating the HttpClient.
    • tryGetHttpClient

      @Nonnull public static io.vavr.control.Try<org.apache.http.client.HttpClient> tryGetHttpClient(@Nonnull Destination destination)
      Returns a Try of an HttpClient for the given Destination. The instance may be cached.
      Parameters:
      destination - The destination to get the HttpClient for.
      Returns:
      A Try of an HttpClient for the given Destination. The instance may be cached.
    • getHttpClientCache

      @Nonnull public static HttpClientCache getHttpClientCache()
      Configures the HttpClientCache that is used by the #getHttpClient(String) and #getHttpClient(Destination) methods.

      By default, this uses the DefaultHttpClientCache implementation, which caches the HttpClient for 5 minutes.

      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 HttpClientAccessor within the application.