Class ClientBuilder

java.lang.Object
io.vrap.rmf.base.client.ClientBuilder
All Implemented Interfaces:
Builder<ApiHttpClient>

public class ClientBuilder extends Object implements Builder<ApiHttpClient>

The ClientBuilder is used to configure and create an ApiHttpClient. As the ApiHttpClient uses a stack of middlewares the Builder comes with methods to configure and attach new middlewares. Also it ensures that some default used middlewares are instantiated at the correct location in the middleware stack.

The default middlewares and services are added as Supplier to be able to override the ones provided by e.g.: defaultClient(URI)

  • Field Details

  • Method Details

    • of

      public static ClientBuilder of()

      Creates a default client builder

      Returns:
      ClientBuilder instance
    • of

      public static ClientBuilder of(ExecutorService httpClientExecutorService)
    • of

      public static ClientBuilder of(VrapHttpClient httpClient)

      Creates a client builder with a specific or preconfigured VrapHttpClient instance. Uses defaults for the HandlerStack

      Parameters:
      httpClient - the HTTP client to be used
      Returns:
      ClientBuilder instance
    • of

      public static ClientBuilder of(ApiHttpClient httpClient)

      Creates a client builder with a specific or preconfigured ApiHttpClient instance. Uses defaults for the HandlerStack

      Parameters:
      httpClient - the HTTP client to be used
      Returns:
      ClientBuilder instance
    • of

      public static ClientBuilder of(HandlerStack stack)

      Creates a client builder with a specifig HandlerStack

      Parameters:
      stack - the HandlerStack to be used
      Returns:
      ClientBuilder instance
    • withoutAuthCircuitBreaker

      public ClientBuilder withoutAuthCircuitBreaker()
      deactivates the circuit breaker for authentication
      Returns:
      ClientBuilder instance
    • withAuthCircuitBreaker

      public ClientBuilder withAuthCircuitBreaker()
      activates the circuit breaker for authentication. Upon erroneous authentication e.g. the authentication middleware will open the circuit breaker and retry regularly.
      Returns:
      ClientBuilder instance
    • withAuthRetries

      public ClientBuilder withAuthRetries(int authRetries)
      Parameters:
      authRetries - number of retries for authentication before giving up.
      Returns:
      ClientBuilder instance
    • withHandlerStack

      public ClientBuilder withHandlerStack(HandlerStack stack)
      Parameters:
      stack - HandlerStack to be used for the HTTP requests
      Returns:
      ClientBuilder instance
    • withHttpClient

      public ClientBuilder withHttpClient(VrapHttpClient httpClient)
      Parameters:
      httpClient - VrapHttpClient to be used for the HTTP requests
      Returns:
      ClientBuilder instance
    • withOAuthHttpClient

      public ClientBuilder withOAuthHttpClient(VrapHttpClient httpClient)
      Parameters:
      httpClient - VrapHttpClient to be used for the OAuth requests
      Returns:
      ClientBuilder instance
    • withSerializer

      public ClientBuilder withSerializer(ResponseSerializer serializer)
      Parameters:
      serializer - ResponseSerializer to be used for de-/serialization
      Returns:
      ClientBuilder instance
    • withSerializer

      public ClientBuilder withSerializer(Supplier<ResponseSerializer> serializer)
      Parameters:
      serializer - ResponseSerializer to be used for de-/serialization
      Returns:
      ClientBuilder instance
    • withHttpExceptionFactory

      public ClientBuilder withHttpExceptionFactory(HttpExceptionFactory factory)
      Parameters:
      factory - HttpExceptionFactory to be used for creating Exceptions based on response status code
      Returns:
      ClientBuilder instance
    • withHttpExceptionFactory

      public ClientBuilder withHttpExceptionFactory(Function<ResponseSerializer,HttpExceptionFactory> factory)
      Parameters:
      factory - function to create HttpExceptionFactory to be used for creating Exceptions based on response status code with the configured ResponseSerializer
      Returns:
      ClientBuilder instance
    • withHttpExceptionFactory

      public ClientBuilder withHttpExceptionFactory(Supplier<HttpExceptionFactory> factory)
      configures the Factory for HTTP exception in case.
      Parameters:
      factory - HttpExceptionFactory to be used for creating Exceptions based on response status code
      Returns:
      ClientBuilder instance
    • withOAuthExecutorService

      public ClientBuilder withOAuthExecutorService(Supplier<ExecutorService> executorService)
      configures an ExecutorService to be used for the Middlewares
      Parameters:
      executorService - supplier of the executor service to be used
      Returns:
      ClientBuilder instance
    • withOAuthExecutorService

      public ClientBuilder withOAuthExecutorService(ExecutorService executorService)
      configures an ExecutorService to be used for the Middlewares
      Parameters:
      executorService - executor service to be used
      Returns:
      ClientBuilder instance
    • defaultClient

      public ClientBuilder defaultClient(URI apiBaseUrl)

      Configures a client with the default middlewares and the given baseUrl

      The following middlewares and services are configured:

      Parameters:
      apiBaseUrl - base URI for the API
      Returns:
      ClientBuilder instance
    • defaultClient

      public ClientBuilder defaultClient(String apiBaseUrl)

      Configures a client with the default middlewares and the given baseUrl

      The following middlewares and services are configured:

      Parameters:
      apiBaseUrl - base URI for the API
      Returns:
      ClientBuilder instance
    • defaultClient

      public ClientBuilder defaultClient(String apiBaseUrl, ClientCredentials credentials, String tokenEndpoint)

      Configures a client with the default middlewares and the given baseUrl

      The following middlewares and services are configured:

      Parameters:
      apiBaseUrl - base URI for the API
      credentials - ClientCredentials to be used
      tokenEndpoint - token endpoint URI to be used for authentication
      Returns:
      ClientBuilder instance
    • defaultClient

      public ClientBuilder defaultClient(ClientCredentials credentials, ServiceRegionConfig serviceRegionConfig)

      Configures a client with the default middlewares and the given baseUrl

      The following middlewares and services are configured:

      Parameters:
      credentials - ClientCredentials to be used
      serviceRegionConfig - ServiceRegionConfig to be used
      Returns:
      ClientBuilder instance
    • withClientCredentials

      @Deprecated public ClientBuilder withClientCredentials(ClientCredentials credentials, String tokenEndpoint)
      Parameters:
      credentials - OAuth credentials
      tokenEndpoint - OAuth endpoint
      Returns:
      client builder
    • withClientCredentials

      @Deprecated public ClientBuilder withClientCredentials(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient)
      Parameters:
      credentials - OAuth credentials
      tokenEndpoint - OAuth endpoint
      httpClient - HTTP client to be used
      Returns:
      client builder
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint, Supplier<HandlerStack> httpClientSupplier)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClientSupplier - HandlerStack to use for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint, VrapHttpClient httpClient)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClient - VrapHttpClient to use for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClientSupplier - VrapHttpClient to use for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClient - VrapHttpClient to use for authentication
      Returns:
      ClientBuilder instance
    • withClientCredentialsFlow

      public ClientBuilder withClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer)
      configure the client to use client credentials flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClient - VrapHttpClient to use for authentication
      serializer - ResponseSerializer to be used for token deserialization
      Returns:
      ClientBuilder instance
    • withStaticTokenFlow

      public ClientBuilder withStaticTokenFlow(AuthenticationToken token)
      configure the client to use client credentials flow
      Parameters:
      token - AuthenticationToken to be used requests
      Returns:
      ClientBuilder instance
    • withAnonymousSessionFlow

      public ClientBuilder withAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint)
      configure the client to use anonymous session flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      Returns:
      ClientBuilder instance
    • withAnonymousSessionFlow

      public ClientBuilder withAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier)
      configure the client to use anonymous session flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClientSupplier - HandlerStack to use for authentication
      Returns:
      ClientBuilder instance
    • withAnonymousSessionFlow

      public ClientBuilder withAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient)
      configure the client to use anonymous session flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClient - VrapHttpClient to use for authentication
      Returns:
      ClientBuilder instance
    • withAnonymousSessionFlow

      public ClientBuilder withAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer)
      configure the client to use anonymous session flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for authentication
      httpClient - VrapHttpClient to use for authentication
      serializer - ResponseSerializer to be used for token deserialization
      Returns:
      ClientBuilder instance
    • withAnonymousRefreshFlow

      public ClientBuilder withAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage)
      configure the client to use anonymous & refresh token flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      anonTokenEndpoint - URI to be used for anonymous token authentication
      refreshTokenEndpoint - URI to be used for refresh token authentication
      storage - TokenStorage for the authentication tokens
      Returns:
      ClientBuilder instance
    • withAnonymousRefreshFlow

      public ClientBuilder withAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, Supplier<HandlerStack> httpClientSupplier)
      configure the client to use anonymous & refresh token flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      anonTokenEndpoint - URI to be used for anonymous token authentication
      refreshTokenEndpoint - URI to be used for refresh token authentication
      storage - TokenStorage for the authentication tokens
      httpClientSupplier - HandlerStack to be used for authentication
      Returns:
      ClientBuilder instance
    • withAnonymousRefreshFlow

      public ClientBuilder withAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, VrapHttpClient httpClient)
      configure the client to use anonymous & refresh token flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      anonTokenEndpoint - URI to be used for anonymous token authentication
      refreshTokenEndpoint - URI to be used for refresh token authentication
      storage - TokenStorage for the authentication tokens
      httpClient - VrapHttpClient to be used for authentication
      Returns:
      ClientBuilder instance
    • withAnonymousRefreshFlow

      public ClientBuilder withAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, VrapHttpClient httpClient, ResponseSerializer serializer)
      configure the client to use anonymous & refresh token flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      anonTokenEndpoint - URI to be used for anonymous token authentication
      refreshTokenEndpoint - URI to be used for refresh token authentication
      storage - TokenStorage for the authentication tokens
      httpClient - VrapHttpClient to be used for authentication
      serializer - ResponseSerializer to be used for token deserialization
      Returns:
      ClientBuilder instance
    • withGlobalCustomerPasswordFlow

      public ClientBuilder withGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint)
      configure the client to use password flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for password flow authentication
      email - customer email
      password - customer password
      Returns:
      ClientBuilder instance
    • withGlobalCustomerPasswordFlow

      public ClientBuilder withGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier)
      configure the client to use password flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for password flow authentication
      email - customer email
      password - customer password
      httpClientSupplier - HandlerStack to use for authentication
      Returns:
      ClientBuilder instance
    • withGlobalCustomerPasswordFlow

      public ClientBuilder withGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, VrapHttpClient httpClient)
      configure the client to use password flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for password flow authentication
      email - customer email
      password - customer password
      httpClient - VrapHttpClient to use for authentication
      Returns:
      ClientBuilder instance
    • withGlobalCustomerPasswordFlow

      public ClientBuilder withGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer)
      configure the client to use password flow
      Parameters:
      credentials - ClientCredentials to be used for authentication
      tokenEndpoint - URI to be used for password flow authentication
      email - customer email
      password - customer password
      httpClient - VrapHttpClient to use for authentication
      serializer - ResponseSerializer to be used for token deserialization
      Returns:
      ClientBuilder instance
    • addAcceptGZipMiddleware

      public ClientBuilder addAcceptGZipMiddleware()
      add middleware to inject an Accept: gzip header
      Returns:
      ClientBuilder instance
    • withErrorMiddleware

      public ClientBuilder withErrorMiddleware(Supplier<ErrorMiddleware> errorMiddleware)
      add middleware to create Exceptions for responses with error status code
      Parameters:
      errorMiddleware - ErrorMiddleware to be used
      Returns:
      ClientBuilder instance
    • withErrorMiddleware

      public ClientBuilder withErrorMiddleware()
      add middleware to create Exceptions for responses with error status code
      Returns:
      ClientBuilder instance
    • withErrorMiddleware

      public ClientBuilder withErrorMiddleware(ErrorMiddleware errorMiddleware)
      add middleware to create Exceptions for responses with error status code
      Parameters:
      errorMiddleware - ErrorMiddleware to be used
      Returns:
      ClientBuilder instance
    • withErrorMiddleware

      public ClientBuilder withErrorMiddleware(ErrorMiddleware.ExceptionMode exceptionMode)
      add middleware to create Exceptions for responses with error status code
      Parameters:
      exceptionMode - either use CompletionExceptions or unwrap the Exception. See ErrorMiddleware.ExceptionMode
      Returns:
      ClientBuilder instance
    • withTelemetryMiddleware

      public ClientBuilder withTelemetryMiddleware(Supplier<TelemetryMiddleware> telemetryMiddleware)
      add middleware to collect and report telemetry data
      Parameters:
      telemetryMiddleware - TelemetryMiddleware to be used
      Returns:
      ClientBuilder instance
    • withTelemetryMiddleware

      public ClientBuilder withTelemetryMiddleware(TelemetryMiddleware telemetryMiddleware)
      add middleware to collect and report telemetry data
      Parameters:
      telemetryMiddleware - TelemetryMiddleware to be used
      Returns:
      ClientBuilder instance
    • addNotFoundExceptionMiddleware

      public ClientBuilder addNotFoundExceptionMiddleware()
      add Middleware to convert a NotFoundException to a response with a null body value
      Returns:
      ClientBuilder instance
    • addNotFoundExceptionMiddleware

      public ClientBuilder addNotFoundExceptionMiddleware(Set<ApiHttpMethod> methods)
      add Middleware to convert a NotFoundException to a response with a null body value
      Parameters:
      methods - HTTP methods to convert on NotFoundException
      Returns:
      ClientBuilder instance
    • addNotFoundExceptionMiddleware

      public ClientBuilder addNotFoundExceptionMiddleware(Predicate<ApiHttpRequest> requestPredicate)
      add Middleware to convert a NotFoundException to a response with a null body value
      Parameters:
      requestPredicate - predicate to match for converting NotFoundException
      Returns:
      ClientBuilder instance
    • addNotFoundExceptionMiddleware

      public ClientBuilder addNotFoundExceptionMiddleware(NotFoundExceptionMiddleware exceptionMiddleware)
      add Middleware to convert a NotFoundException to a response with a null body value
      Parameters:
      exceptionMiddleware - middleware to be used
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(Supplier<RetryRequestMiddleware> retryMiddleware)
      Deprecated.
      add middleware to retry failed requests
      Parameters:
      retryMiddleware - RetryRequestMiddleware to be used
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(RetryRequestMiddleware retryMiddleware)
      Deprecated.
      add middleware to retry failed requests
      Parameters:
      retryMiddleware - RetryRequestMiddleware to be used
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(int maxRetries)
      Deprecated.
      add middleware to retry failed requests. By default, status code 500 & 503 will be retried. Between each retry an incremental backoff strategy is applied
      Parameters:
      maxRetries - number of retries before giving uo
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(int maxRetries, List<Integer> statusCodes)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, List<Integer> statusCodes)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ScheduledExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, List<Integer> statusCodes)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ScheduledExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ScheduledExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ScheduledExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      executorService - ScheduledExecutorService to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      scheduler - Scheduler to be used for the retry handler
      maxRetries - number of retries before giving uo
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, List<Integer> statusCodes)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      scheduler - Scheduler to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      scheduler - Scheduler to be used for the retry handler
      maxRetries - number of retries before giving uo
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      scheduler - Scheduler to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      statusCodes - HTTP status codes to retry a failed request e.g. 500 & 503
      failures - Throwables to be retried
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withRetryMiddleware

      @Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn)
      Deprecated.
      add middleware to retry failed requests. Between each retry an incremental backoff strategy is applied
      Parameters:
      scheduler - Scheduler to be used for the retry handler
      maxRetries - number of retries before giving uo
      delay - the initial delay for a retry
      maxDelay - the maximum delay between each retry
      fn - additional configuration for the RetryPolicy to be applied
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(Supplier<QueueRequestMiddleware> queueMiddleware)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      queueMiddleware - QueueRequestMiddleware to be used
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(QueueRequestMiddleware queueMiddleware)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      queueMiddleware - QueueRequestMiddleware to be used
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(int maxRequests, Duration maxWaitTime)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      maxRequests - maximum number of concurrent requests
      maxWaitTime - maximum time to wait before giving up
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRequests, Duration maxWaitTime)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      scheduler - Scheduler to be used for handling the queue
      maxRequests - maximum number of concurrent requests
      maxWaitTime - maximum time to wait before giving up
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(ScheduledExecutorService executorService, int maxRequests, Duration maxWaitTime)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      executorService - ScheduledExecutorService to be used for handling the queue
      maxRequests - maximum number of concurrent requests
      maxWaitTime - maximum time to wait before giving up
      Returns:
      ClientBuilder instance
    • withQueueMiddleware

      @Deprecated public ClientBuilder withQueueMiddleware(ExecutorService executorService, int maxRequests, Duration maxWaitTime)
      Deprecated.
      add middleware to limit the concurrent requests to be executed
      Parameters:
      executorService - ExecutorService to be used for handling the queue
      maxRequests - maximum number of concurrent requests
      maxWaitTime - maximum time to wait before giving up
      Returns:
      ClientBuilder instance
    • withPolicies

      public ClientBuilder withPolicies(PolicyBuilder policyBuilder)
      add middleware for safe handling of failed requests
      Parameters:
      policyBuilder - the policy builder
      Returns:
      ClientBuilder instance
    • withPolicies

      add middleware for safe handling of failed requests
      Parameters:
      fn - the policy builder function
      Returns:
      ClientBuilder instance
    • withPolicyMiddleware

      public ClientBuilder withPolicyMiddleware(PolicyMiddleware policyMiddleware)
      add middleware for safe handling of failed requests
      Parameters:
      policyMiddleware - PolicyMiddleware to be used
      Returns:
      ClientBuilder
    • withPolicyMiddleware

      public ClientBuilder withPolicyMiddleware(Supplier<PolicyMiddleware> policyMiddleware)
      add middleware for safe handling of failed requests
      Parameters:
      policyMiddleware - PolicyMiddleware to be used
      Returns:
      ClientBuilder
    • withOAuthMiddleware

      public ClientBuilder withOAuthMiddleware(Supplier<OAuthMiddleware> oAuthMiddleware)
      add authenticator middleware
      Parameters:
      oAuthMiddleware - OAuthMiddleware to be used for authentication
      Returns:
      ClientBuilder instance
    • withOAuthMiddleware

      public ClientBuilder withOAuthMiddleware(OAuthMiddleware oAuthMiddleware)
      add authenticator middleware
      Parameters:
      oAuthMiddleware - OAuthMiddleware to be used for authentication
      Returns:
      ClientBuilder instance
    • withTokenSupplier

      public ClientBuilder withTokenSupplier(Supplier<TokenSupplier> tokenSupplier)
      use supplier for authentication tokens
      Parameters:
      tokenSupplier - TokenSupplier for retrieving authentication tokens
      Returns:
      ClientBuilder instance
    • withTokenSupplier

      public ClientBuilder withTokenSupplier(TokenSupplier tokenSupplier)
      use supplier for authentication tokens
      Parameters:
      tokenSupplier - TokenSupplier for retrieving authentication tokens
      Returns:
      ClientBuilder instance
    • withInternalLoggerMiddleware

      public ClientBuilder withInternalLoggerMiddleware(InternalLoggerMiddleware internalLoggerMiddleware)
      Parameters:
      internalLoggerMiddleware - InternalLoggerMiddleware used for logging requests and responses
      Returns:
      ClientBuilder instance
    • withInternalLoggerFactory

      public ClientBuilder withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory)
      Parameters:
      internalLoggerFactory - InternalLoggerFactory creates the logger for request & responses
      Returns:
      ClientBuilder instance
    • withInternalLoggerFactory

      public ClientBuilder withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory, org.slf4j.event.Level responseLogEvent, org.slf4j.event.Level deprecationLogEvent)
      Parameters:
      internalLoggerFactory - InternalLoggerFactory creates the logger for request & responses
      responseLogEvent - Level for logging responses.
      deprecationLogEvent - Level for logging ApiHttpHeaders.X_DEPRECATION_NOTICE
      Returns:
      ClientBuilder instance
    • withInternalLoggerFactory

      public ClientBuilder withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory, org.slf4j.event.Level responseLogEvent, org.slf4j.event.Level deprecationLogEvent, org.slf4j.event.Level defaultExceptionLogEvent, Map<Class<? extends Throwable>,org.slf4j.event.Level> exceptionLogEvents)
      Parameters:
      internalLoggerFactory - InternalLoggerFactory creates the logger for request & responses
      responseLogEvent - Level for logging responses.
      deprecationLogEvent - Level for logging ApiHttpHeaders.X_DEPRECATION_NOTICE
      defaultExceptionLogEvent - Level for logging errors
      exceptionLogEvents - Level for logging by exception class
      Returns:
      ClientBuilder instance
    • withInternalLoggerFactory

      public ClientBuilder withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory, org.slf4j.event.Level responseLogEvent, org.slf4j.event.Level deprecationLogEvent, org.slf4j.event.Level defaultExceptionLogEvent, Map<Class<? extends Throwable>,org.slf4j.event.Level> exceptionLogEvents, ResponseLogFormatter responseLogFormatter, ErrorLogFormatter errorLogFormatter)
      Parameters:
      internalLoggerFactory - InternalLoggerFactory creates the logger for request & responses
      responseLogEvent - Level for logging responses.
      deprecationLogEvent - Level for logging ApiHttpHeaders.X_DEPRECATION_NOTICE
      defaultExceptionLogEvent - Level for logging errors
      exceptionLogEvents - Level for logging by exception class
      responseLogFormatter - ResponseLogFormatter response log formatter
      Returns:
      ClientBuilder instance
    • withApiBaseUrl

      public ClientBuilder withApiBaseUrl(String apiBaseUrl)
      Parameters:
      apiBaseUrl - base URI for calling the API
      Returns:
      ClientBuilder instance
    • withApiBaseUrl

      public ClientBuilder withApiBaseUrl(URI apiBaseUrl)
      Parameters:
      apiBaseUrl - base URI for calling the API
      Returns:
      ClientBuilder instance
    • withUserAgentSupplier

      public ClientBuilder withUserAgentSupplier(Supplier<String> userAgentSupplier)
      Parameters:
      userAgentSupplier - user agent to be sent with the requests
      Returns:
      ClientBuilder instance
    • addCorrelationIdProvider

      public ClientBuilder addCorrelationIdProvider(@Nullable CorrelationIdProvider correlationIdProvider, boolean replace)
      Parameters:
      correlationIdProvider - provider to create correlation IDs for each request
      replace - replace any existing correlation id provider
      Returns:
      ClientBuilder instance
    • addCorrelationIdProvider

      public ClientBuilder addCorrelationIdProvider(@Nullable CorrelationIdProvider correlationIdProvider)
      Parameters:
      correlationIdProvider - provider to create correlation IDs for each request
      Returns:
      ClientBuilder instance
    • withMiddlewares

      public ClientBuilder withMiddlewares(List<Middleware> middlewares)
      sets the middlewares to be configured for the client.
      Parameters:
      middlewares - Middleware instances
      Returns:
      ClientBuilder instance
    • withMiddleware

      public ClientBuilder withMiddleware(Middleware middleware, Middleware... middlewares)
      sets the middlewares to be configured for the client.
      Parameters:
      middleware - Middleware instance
      middlewares - Middleware instances
      Returns:
      ClientBuilder instance
    • addMiddlewares

      public ClientBuilder addMiddlewares(List<Middleware> middlewares)
      adds the middlewares to be configured for the client.
      Parameters:
      middlewares - Middleware instances
      Returns:
      ClientBuilder instance
    • addMiddleware

      public ClientBuilder addMiddleware(Middleware middleware, Middleware... middlewares)
      adds the middlewares to be configured for the client.
      Parameters:
      middleware - Middleware instance
      middlewares - Middleware instances
      Returns:
      ClientBuilder instance
    • build

      public ApiHttpClient build()
      build the ApiHttpClient with the configured values
      Specified by:
      build in interface Builder<ApiHttpClient>
      Returns:
      ApiHttpClient
    • buildDefaultUserAgent

      public static String buildDefaultUserAgent()
      default user agent provider
      Returns:
      user agent string