Class ApiClientBuilder
ApiClient instances for Unity Catalog operations.
Example usage:
Map<String, String> configMap = ...;
ApiClient client = ApiClientBuilder.create()
.uri("http://localhost:8080")
.tokenProvider(TokenProvider.create(configMap))
.retryPolicy(JitterDelayRetryPolicy.builder().maxAttempts(5).build())
.addAppVersion("MyApp", "1.0.0")
.build();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddAppVersion(String name, String version) Sets application version metadata as name-version pairs.addRequestInterceptor(Consumer<HttpRequest.Builder> interceptor) Adds a custom request interceptor to modify HTTP requests before they are sent.build()Builds and returns a configuredApiClientinstance.static ApiClientBuildercreate()Creates a new instance ofApiClientBuilder.retryPolicy(RetryPolicy retryPolicy) Sets a custom request retry policy for handling transient failures.tokenProvider(TokenProvider tokenProvider) Sets the token provider for authentication.Sets the Unity Catalog server URI from a string.Sets the Unity Catalog server URI.
-
Method Details
-
create
Creates a new instance ofApiClientBuilder.- Returns:
- a new
ApiClientBuilderinstance
-
uri
Sets the Unity Catalog server URI.The base path
/api/2.1/unity-catalogwill be automatically appended.- Parameters:
uri- the Unity Catalog server URI, must not be null- Returns:
- this builder instance for method chaining
-
uri
Sets the Unity Catalog server URI from a string.- Parameters:
uri- the Unity Catalog server URI, must not be null- Returns:
- this builder instance for method chaining
- See Also:
-
tokenProvider
Sets the token provider for authentication.The token will be included in the Authorization header as a Bearer token.
- Parameters:
tokenProvider- the token provider implementation, must not be null- Returns:
- this builder instance for method chaining
- See Also:
-
addAppVersion
Sets application version metadata as name-version pairs.Arguments must be provided in alternating name-version order with an even count, e.g.,
"MyApp1", "0.1.0".- Parameters:
name- the application name.version- the application version.- Returns:
- this builder instance for method chaining
- Throws:
IllegalArgumentException- if any argument is null or empty.
-
retryPolicy
Sets a custom request retry policy for handling transient failures.Defaults to
JitterDelayRetryPolicyif not specified.- Parameters:
retryPolicy- the retry policy implementation, must not be null- Returns:
- this builder instance for method chaining
- See Also:
-
addRequestInterceptor
Adds a custom request interceptor to modify HTTP requests before they are sent.Request interceptors can be used to add custom headers, modify request properties, or perform logging. Multiple interceptors can be added and will be executed in the order they were registered.
Example usage:
ApiClientBuilder builder = ApiClientBuilder.create() .uri("http://localhost:8080") .tokenProvider(TokenProvider.create(configMap)) .addRequestInterceptor(builder -> builder.header("X-Custom-Header", "custom-value"));Warning: If you call
setRequestInterceptordirectly on the builtApiClient, it will replace all built-in interceptors from this builder, including the User-Agent and Authorization headers, which may cause authentication to fail. Always useaddRequestInterceptor(Consumer)instead to preserve the built-in interceptors.- Parameters:
interceptor- a consumer that accepts anHttpRequest.Builderto modify the request, must not be null- Returns:
- this builder instance for method chaining
-
build
Builds and returns a configuredApiClientinstance.- Returns:
- a configured
ApiClientinstance - Throws:
NullPointerException- ifuriortokenProvideris null
-