Class ApacheHttpClient5Accessor

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

@Beta public final class ApacheHttpClient5Accessor extends Object
Accessor for HttpClients.
Since:
4.20.0
  • Method Details

    • setHttpClientFactory

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

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

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

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

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

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

      @Nonnull public static org.apache.hc.client5.http.classic.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.hc.client5.http.classic.HttpClient> tryGetHttpClient()
      Returns an HttpClient independent of any destination.
      Returns:
      An HttpClient independent of any destination.
    • getHttpClient

      @Nonnull public static org.apache.hc.client5.http.classic.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.hc.client5.http.classic.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.hc.client5.http.classic.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 ApacheHttpClient5Cache getHttpClientCache()
      Configures the HttpClient5Cache that is used by the #getHttpClient(String) and #getHttpClient(Destination) methods.

      By default, this uses an 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 ApacheHttpClient5Accessor within the application.

    • getHttpClientFactory

      @Nonnull public static ApacheHttpClient5Factory getHttpClientFactory()
      Returns the ApacheHttpClient5Factory that is used when creating instances of HttpClient within the ApacheHttpClient5Accessor.