Class ClientBuilder
- All Implemented Interfaces:
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionadd middleware to inject an Accept: gzip headeraddCorrelationIdProvider(CorrelationIdProvider correlationIdProvider) addCorrelationIdProvider(CorrelationIdProvider correlationIdProvider, boolean replace) addMiddleware(Middleware middleware, Middleware... middlewares) adds the middlewares to be configured for the client.addMiddlewares(List<Middleware> middlewares) adds the middlewares to be configured for the client.add Middleware to convert aNotFoundExceptionto a response with a null body valueaddNotFoundExceptionMiddleware(NotFoundExceptionMiddleware exceptionMiddleware) add Middleware to convert aNotFoundExceptionto a response with a null body valueaddNotFoundExceptionMiddleware(Predicate<ApiHttpRequest> requestPredicate) add Middleware to convert aNotFoundExceptionto a response with a null body valueaddNotFoundExceptionMiddleware(Set<ApiHttpMethod> methods) add Middleware to convert aNotFoundExceptionto a response with a null body valuebuild()build theApiHttpClientwith the configured valuesstatic Stringdefault user agent providerdefaultClient(ClientCredentials credentials, ServiceRegionConfig serviceRegionConfig) Configures a client with the default middlewares and the given baseUrldefaultClient(String apiBaseUrl) Configures a client with the default middlewares and the given baseUrldefaultClient(String apiBaseUrl, ClientCredentials credentials, String tokenEndpoint) Configures a client with the default middlewares and the given baseUrldefaultClient(URI apiBaseUrl) Configures a client with the default middlewares and the given baseUrlstatic ClientBuilderof()Creates a default client builderstatic ClientBuilderof(ApiHttpClient httpClient) Creates a client builder with a specific or preconfiguredApiHttpClientinstance.static ClientBuilderof(HandlerStack stack) Creates a client builder with a specifigHandlerStackstatic ClientBuilderof(VrapHttpClient httpClient) Creates a client builder with a specific or preconfiguredVrapHttpClientinstance.static ClientBuilderof(ExecutorService httpClientExecutorService) withAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage) configure the client to use anonymous & refresh token flowwithAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, VrapHttpClient httpClient) configure the client to use anonymous & refresh token flowwithAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, VrapHttpClient httpClient, ResponseSerializer serializer) configure the client to use anonymous & refresh token flowwithAnonymousRefreshFlow(ClientCredentials credentials, String anonTokenEndpoint, String refreshTokenEndpoint, TokenStorage storage, Supplier<HandlerStack> httpClientSupplier) configure the client to use anonymous & refresh token flowwithAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint) configure the client to use anonymous session flowwithAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient) configure the client to use anonymous session flowwithAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer) configure the client to use anonymous session flowwithAnonymousSessionFlow(ClientCredentials credentials, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier) configure the client to use anonymous session flowwithApiBaseUrl(String apiBaseUrl) withApiBaseUrl(URI apiBaseUrl) activates the circuit breaker for authentication.withAuthRetries(int authRetries) withClientCredentials(ClientCredentials credentials, String tokenEndpoint) Deprecated.withClientCredentials(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient) Deprecated.withClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint, VrapHttpClient httpClient) configure the client to use client credentials flowwithClientCredentialsFlow(ClientCredentials credentials, URI tokenEndpoint, Supplier<HandlerStack> httpClientSupplier) configure the client to use client credentials flowadd middleware to create Exceptions for responses with error status codewithErrorMiddleware(ErrorMiddleware errorMiddleware) add middleware to create Exceptions for responses with error status codewithErrorMiddleware(ErrorMiddleware.ExceptionMode exceptionMode) add middleware to create Exceptions for responses with error status codewithErrorMiddleware(Supplier<ErrorMiddleware> errorMiddleware) add middleware to create Exceptions for responses with error status codewithGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint) configure the client to use password flowwithGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, VrapHttpClient httpClient) configure the client to use password flowwithGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, VrapHttpClient httpClient, ResponseSerializer serializer) configure the client to use password flowwithGlobalCustomerPasswordFlow(ClientCredentials credentials, String email, String password, String tokenEndpoint, Supplier<HandlerStack> httpClientSupplier) configure the client to use password flowwithHandlerStack(HandlerStack stack) withHttpClient(VrapHttpClient httpClient) configures the Factory for HTTP exception in case.withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory) withInternalLoggerFactory(InternalLoggerFactory internalLoggerFactory, org.slf4j.event.Level responseLogEvent, org.slf4j.event.Level deprecationLogEvent) 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) 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) withInternalLoggerMiddleware(InternalLoggerMiddleware internalLoggerMiddleware) withMiddleware(Middleware middleware, Middleware... middlewares) sets the middlewares to be configured for the client.withMiddlewares(List<Middleware> middlewares) sets the middlewares to be configured for the client.withOAuthExecutorService(ExecutorService executorService) configures an ExecutorService to be used for the MiddlewareswithOAuthExecutorService(Supplier<ExecutorService> executorService) configures an ExecutorService to be used for the MiddlewareswithOAuthHttpClient(VrapHttpClient httpClient) withOAuthMiddleware(OAuthMiddleware oAuthMiddleware) add authenticator middlewarewithOAuthMiddleware(Supplier<OAuthMiddleware> oAuthMiddleware) add authenticator middlewaredeactivates the circuit breaker for authenticationwithPolicies(PolicyBuilder policyBuilder) add middleware for safe handling of failed requestsadd middleware for safe handling of failed requestswithPolicyMiddleware(PolicyMiddleware policyMiddleware) add middleware for safe handling of failed requestswithPolicyMiddleware(Supplier<PolicyMiddleware> policyMiddleware) add middleware for safe handling of failed requestswithQueueMiddleware(int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadwithQueueMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadwithQueueMiddleware(QueueRequestMiddleware queueMiddleware) Deprecated.usewithPolicies(Function)insteadwithQueueMiddleware(ExecutorService executorService, int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadwithQueueMiddleware(ScheduledExecutorService executorService, int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadwithQueueMiddleware(Supplier<QueueRequestMiddleware> queueMiddleware) Deprecated.usewithPolicies(Function)insteadwithRequestPolicies(RequestPolicyBuilder requestPolicyBuilder) add middleware for safe handling of failed requestswithRetryMiddleware(int maxRetries) Deprecated.usewithPolicies(Function)} insteadwithRetryMiddleware(int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)} insteadwithRetryMiddleware(int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(RetryRequestMiddleware retryMiddleware) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ExecutorService executorService, int maxRetries) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ExecutorService executorService, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ExecutorService executorService, int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ExecutorService executorService, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ScheduledExecutorService executorService, int maxRetries) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, long delay, long maxDelay, List<Integer> statusCodes, List<Class<? extends Throwable>> failures, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, List<Integer> statusCodes, List<Class<? extends Throwable>> failures) Deprecated.usewithPolicies(Function)insteadwithRetryMiddleware(Supplier<RetryRequestMiddleware> retryMiddleware) Deprecated.usewithPolicies(Function)insteadwithSerializer(ResponseSerializer serializer) withSerializer(Supplier<ResponseSerializer> serializer) configure the client to use client credentials flowwithTelemetryMiddleware(TelemetryMiddleware telemetryMiddleware) add middleware to collect and report telemetry datawithTelemetryMiddleware(Supplier<TelemetryMiddleware> telemetryMiddleware) add middleware to collect and report telemetry datawithTokenSupplier(TokenSupplier tokenSupplier) use supplier for authentication tokenswithTokenSupplier(Supplier<TokenSupplier> tokenSupplier) use supplier for authentication tokenswithUserAgentSupplier(Supplier<String> userAgentSupplier)
-
Field Details
-
COMMERCETOOLS
- See Also:
-
-
Method Details
-
of
Creates a default client builder
- Returns:
- ClientBuilder instance
-
of
-
of
Creates a client builder with a specific or preconfigured
VrapHttpClientinstance. Uses defaults for theHandlerStack- Parameters:
httpClient- the HTTP client to be used- Returns:
- ClientBuilder instance
-
of
Creates a client builder with a specific or preconfigured
ApiHttpClientinstance. Uses defaults for theHandlerStack- Parameters:
httpClient- the HTTP client to be used- Returns:
- ClientBuilder instance
-
of
Creates a client builder with a specifig
HandlerStack- Parameters:
stack- the HandlerStack to be used- Returns:
- ClientBuilder instance
-
withoutAuthCircuitBreaker
deactivates the circuit breaker for authentication- Returns:
- ClientBuilder instance
-
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
- Parameters:
authRetries- number of retries for authentication before giving up.- Returns:
- ClientBuilder instance
-
withHandlerStack
- Parameters:
stack-HandlerStackto be used for the HTTP requests- Returns:
- ClientBuilder instance
-
withHttpClient
- Parameters:
httpClient-VrapHttpClientto be used for the HTTP requests- Returns:
- ClientBuilder instance
-
withOAuthHttpClient
- Parameters:
httpClient-VrapHttpClientto be used for the OAuth requests- Returns:
- ClientBuilder instance
-
withSerializer
- Parameters:
serializer-ResponseSerializerto be used for de-/serialization- Returns:
- ClientBuilder instance
-
withSerializer
- Parameters:
serializer-ResponseSerializerto be used for de-/serialization- Returns:
- ClientBuilder instance
-
withHttpExceptionFactory
- Parameters:
factory-HttpExceptionFactoryto 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 createHttpExceptionFactoryto be used for creating Exceptions based on response status code with the configuredResponseSerializer- Returns:
- ClientBuilder instance
-
withHttpExceptionFactory
configures the Factory for HTTP exception in case.- Parameters:
factory-HttpExceptionFactoryto be used for creating Exceptions based on response status code- Returns:
- ClientBuilder instance
-
withOAuthExecutorService
configures an ExecutorService to be used for the Middlewares- Parameters:
executorService- supplier of the executor service to be used- Returns:
- ClientBuilder instance
-
withOAuthExecutorService
configures an ExecutorService to be used for the Middlewares- Parameters:
executorService- executor service to be used- Returns:
- ClientBuilder instance
-
defaultClient
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
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 APIcredentials-ClientCredentialsto be usedtokenEndpoint- 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-ClientCredentialsto be usedserviceRegionConfig-ServiceRegionConfigto be used- Returns:
- ClientBuilder instance
-
withClientCredentials
@Deprecated public ClientBuilder withClientCredentials(ClientCredentials credentials, String tokenEndpoint) Deprecated.- Parameters:
credentials- OAuth credentialstokenEndpoint- OAuth endpoint- Returns:
- client builder
-
withClientCredentials
@Deprecated public ClientBuilder withClientCredentials(ClientCredentials credentials, String tokenEndpoint, VrapHttpClient httpClient) Deprecated.- Parameters:
credentials- OAuth credentialstokenEndpoint- OAuth endpointhttpClient- HTTP client to be used- Returns:
- client builder
-
withClientCredentialsFlow
configure the client to use client credentials flow- Parameters:
credentials-ClientCredentialsto be used for authenticationtokenEndpoint- 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClientSupplier-HandlerStackto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClient-VrapHttpClientto use for authentication- Returns:
- ClientBuilder instance
-
withClientCredentialsFlow
configure the client to use client credentials flow- Parameters:
credentials-ClientCredentialsto be used for authenticationtokenEndpoint- 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClientSupplier-VrapHttpClientto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClient-VrapHttpClientto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClient-VrapHttpClientto use for authenticationserializer-ResponseSerializerto be used for token deserialization- Returns:
- ClientBuilder instance
-
withStaticTokenFlow
configure the client to use client credentials flow- Parameters:
token-AuthenticationTokento be used requests- Returns:
- ClientBuilder instance
-
withAnonymousSessionFlow
configure the client to use anonymous session flow- Parameters:
credentials-ClientCredentialsto be used for authenticationtokenEndpoint- 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClientSupplier-HandlerStackto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClient-VrapHttpClientto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for authenticationhttpClient-VrapHttpClientto use for authenticationserializer-ResponseSerializerto 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-ClientCredentialsto be used for authenticationanonTokenEndpoint- URI to be used for anonymous token authenticationrefreshTokenEndpoint- URI to be used for refresh token authenticationstorage-TokenStoragefor 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-ClientCredentialsto be used for authenticationanonTokenEndpoint- URI to be used for anonymous token authenticationrefreshTokenEndpoint- URI to be used for refresh token authenticationstorage-TokenStoragefor the authentication tokenshttpClientSupplier-HandlerStackto 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-ClientCredentialsto be used for authenticationanonTokenEndpoint- URI to be used for anonymous token authenticationrefreshTokenEndpoint- URI to be used for refresh token authenticationstorage-TokenStoragefor the authentication tokenshttpClient-VrapHttpClientto 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-ClientCredentialsto be used for authenticationanonTokenEndpoint- URI to be used for anonymous token authenticationrefreshTokenEndpoint- URI to be used for refresh token authenticationstorage-TokenStoragefor the authentication tokenshttpClient-VrapHttpClientto be used for authenticationserializer-ResponseSerializerto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for password flow authenticationemail- customer emailpassword- 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for password flow authenticationemail- customer emailpassword- customer passwordhttpClientSupplier-HandlerStackto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for password flow authenticationemail- customer emailpassword- customer passwordhttpClient-VrapHttpClientto 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-ClientCredentialsto be used for authenticationtokenEndpoint- URI to be used for password flow authenticationemail- customer emailpassword- customer passwordhttpClient-VrapHttpClientto use for authenticationserializer-ResponseSerializerto be used for token deserialization- Returns:
- ClientBuilder instance
-
addAcceptGZipMiddleware
add middleware to inject an Accept: gzip header- Returns:
- ClientBuilder instance
-
withErrorMiddleware
add middleware to create Exceptions for responses with error status code- Parameters:
errorMiddleware-ErrorMiddlewareto be used- Returns:
- ClientBuilder instance
-
withErrorMiddleware
add middleware to create Exceptions for responses with error status code- Returns:
- ClientBuilder instance
-
withErrorMiddleware
add middleware to create Exceptions for responses with error status code- Parameters:
errorMiddleware-ErrorMiddlewareto be used- Returns:
- ClientBuilder instance
-
withErrorMiddleware
add middleware to create Exceptions for responses with error status code- Parameters:
exceptionMode- either use CompletionExceptions or unwrap the Exception. SeeErrorMiddleware.ExceptionMode- Returns:
- ClientBuilder instance
-
withTelemetryMiddleware
add middleware to collect and report telemetry data- Parameters:
telemetryMiddleware-TelemetryMiddlewareto be used- Returns:
- ClientBuilder instance
-
withTelemetryMiddleware
add middleware to collect and report telemetry data- Parameters:
telemetryMiddleware-TelemetryMiddlewareto be used- Returns:
- ClientBuilder instance
-
addNotFoundExceptionMiddleware
add Middleware to convert aNotFoundExceptionto a response with a null body value- Returns:
- ClientBuilder instance
-
addNotFoundExceptionMiddleware
add Middleware to convert aNotFoundExceptionto a response with a null body value- Parameters:
methods- HTTP methods to convert onNotFoundException- Returns:
- ClientBuilder instance
-
addNotFoundExceptionMiddleware
add Middleware to convert aNotFoundExceptionto a response with a null body value- Parameters:
requestPredicate- predicate to match for convertingNotFoundException- Returns:
- ClientBuilder instance
-
addNotFoundExceptionMiddleware
public ClientBuilder addNotFoundExceptionMiddleware(NotFoundExceptionMiddleware exceptionMiddleware) add Middleware to convert aNotFoundExceptionto 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.usewithPolicies(Function)insteadadd middleware to retry failed requests- Parameters:
retryMiddleware-RetryRequestMiddlewareto be used- Returns:
- ClientBuilder instance
-
withRetryMiddleware
Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests- Parameters:
retryMiddleware-RetryRequestMiddlewareto be used- Returns:
- ClientBuilder instance
-
withRetryMiddleware
Deprecated.usewithPolicies(Function)} insteadadd 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.usewithPolicies(Function)} insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
maxRetries- number of retries before giving uostatusCodes- 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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
maxRetries- number of retries before giving uostatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
maxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retrystatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-Throwables to be retriedfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
maxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retryfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uo- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- 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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retrystatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-Throwables to be retriedfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retryfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ScheduledExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uo- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, List<Integer> statusCodes) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ScheduledExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- 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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ScheduledExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ScheduledExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retrystatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-Throwables to be retriedfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(ScheduledExecutorService executorService, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
executorService-ScheduledExecutorServiceto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retryfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
scheduler-Schedulerto be used for the retry handlermaxRetries- 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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
scheduler-Schedulerto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- 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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
scheduler-Schedulerto be used for the retry handlermaxRetries- number of retries before giving uostatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-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.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
scheduler-Schedulerto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retrystatusCodes- HTTP status codes to retry a failed request e.g. 500 & 503failures-Throwables to be retriedfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withRetryMiddleware
@Deprecated public ClientBuilder withRetryMiddleware(dev.failsafe.spi.Scheduler scheduler, int maxRetries, long delay, long maxDelay, FailsafeRetryPolicyBuilderOptions fn) Deprecated.usewithPolicies(Function)insteadadd middleware to retry failed requests. Between each retry an incremental backoff strategy is applied- Parameters:
scheduler-Schedulerto be used for the retry handlermaxRetries- number of retries before giving uodelay- the initial delay for a retrymaxDelay- the maximum delay between each retryfn- additional configuration for theRetryPolicyto be applied- Returns:
- ClientBuilder instance
-
withQueueMiddleware
@Deprecated public ClientBuilder withQueueMiddleware(Supplier<QueueRequestMiddleware> queueMiddleware) Deprecated.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
queueMiddleware-QueueRequestMiddlewareto be used- Returns:
- ClientBuilder instance
-
withQueueMiddleware
Deprecated.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
queueMiddleware-QueueRequestMiddlewareto be used- Returns:
- ClientBuilder instance
-
withQueueMiddleware
Deprecated.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
maxRequests- maximum number of concurrent requestsmaxWaitTime- 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.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
scheduler-Schedulerto be used for handling the queuemaxRequests- maximum number of concurrent requestsmaxWaitTime- maximum time to wait before giving up- Returns:
- ClientBuilder instance
-
withQueueMiddleware
@Deprecated public ClientBuilder withQueueMiddleware(ScheduledExecutorService executorService, int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
executorService-ScheduledExecutorServiceto be used for handling the queuemaxRequests- maximum number of concurrent requestsmaxWaitTime- maximum time to wait before giving up- Returns:
- ClientBuilder instance
-
withQueueMiddleware
@Deprecated public ClientBuilder withQueueMiddleware(ExecutorService executorService, int maxRequests, Duration maxWaitTime) Deprecated.usewithPolicies(Function)insteadadd middleware to limit the concurrent requests to be executed- Parameters:
executorService-ExecutorServiceto be used for handling the queuemaxRequests- maximum number of concurrent requestsmaxWaitTime- maximum time to wait before giving up- Returns:
- ClientBuilder instance
-
withPolicies
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
-
withRequestPolicies
add middleware for safe handling of failed requests- Parameters:
requestPolicyBuilder- the policy builder- Returns:
- ClientBuilder instance
-
withRequestPolicies
-
withPolicyMiddleware
add middleware for safe handling of failed requests- Parameters:
policyMiddleware-PolicyMiddlewareto be used- Returns:
- ClientBuilder
-
withPolicyMiddleware
add middleware for safe handling of failed requests- Parameters:
policyMiddleware-PolicyMiddlewareto be used- Returns:
- ClientBuilder
-
withOAuthMiddleware
add authenticator middleware- Parameters:
oAuthMiddleware-OAuthMiddlewareto be used for authentication- Returns:
- ClientBuilder instance
-
withOAuthMiddleware
add authenticator middleware- Parameters:
oAuthMiddleware-OAuthMiddlewareto be used for authentication- Returns:
- ClientBuilder instance
-
withTokenSupplier
use supplier for authentication tokens- Parameters:
tokenSupplier-TokenSupplierfor retrieving authentication tokens- Returns:
- ClientBuilder instance
-
withTokenSupplier
use supplier for authentication tokens- Parameters:
tokenSupplier-TokenSupplierfor retrieving authentication tokens- Returns:
- ClientBuilder instance
-
withInternalLoggerMiddleware
public ClientBuilder withInternalLoggerMiddleware(InternalLoggerMiddleware internalLoggerMiddleware) - Parameters:
internalLoggerMiddleware-InternalLoggerMiddlewareused for logging requests and responses- Returns:
- ClientBuilder instance
-
withInternalLoggerFactory
- Parameters:
internalLoggerFactory-InternalLoggerFactorycreates 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-InternalLoggerFactorycreates the logger for request & responsesresponseLogEvent-Levelfor logging responses.deprecationLogEvent-Levelfor loggingApiHttpHeaders.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-InternalLoggerFactorycreates the logger for request & responsesresponseLogEvent-Levelfor logging responses.deprecationLogEvent-Levelfor loggingApiHttpHeaders.X_DEPRECATION_NOTICEdefaultExceptionLogEvent-Levelfor logging errorsexceptionLogEvents-Levelfor 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-InternalLoggerFactorycreates the logger for request & responsesresponseLogEvent-Levelfor logging responses.deprecationLogEvent-Levelfor loggingApiHttpHeaders.X_DEPRECATION_NOTICEdefaultExceptionLogEvent-Levelfor logging errorsexceptionLogEvents-Levelfor logging by exception classresponseLogFormatter-ResponseLogFormatterresponse log formatter- Returns:
- ClientBuilder instance
-
withApiBaseUrl
- Parameters:
apiBaseUrl- base URI for calling the API- Returns:
- ClientBuilder instance
-
withApiBaseUrl
- Parameters:
apiBaseUrl- base URI for calling the API- Returns:
- ClientBuilder instance
-
withUserAgentSupplier
- 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 requestreplace- 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
sets the middlewares to be configured for the client.- Parameters:
middlewares-Middlewareinstances- Returns:
- ClientBuilder instance
-
withMiddleware
sets the middlewares to be configured for the client.- Parameters:
middleware-Middlewareinstancemiddlewares-Middlewareinstances- Returns:
- ClientBuilder instance
-
addMiddlewares
adds the middlewares to be configured for the client.- Parameters:
middlewares-Middlewareinstances- Returns:
- ClientBuilder instance
-
addMiddleware
adds the middlewares to be configured for the client.- Parameters:
middleware-Middlewareinstancemiddlewares-Middlewareinstances- Returns:
- ClientBuilder instance
-
build
build theApiHttpClientwith the configured values- Specified by:
buildin interfaceBuilder<ApiHttpClient>- Returns:
ApiHttpClient
-
buildDefaultUserAgent
default user agent provider- Returns:
- user agent string
-
withClientCredentialsFlow(ClientCredentials, String)instead