Custom HTTP client¶
The SDK uses Java 21 java.net.http.HttpClient.
var http = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(5))
.followRedirects(HttpClient.Redirect.NEVER)
.version(HttpClient.Version.HTTP_2)
.build();
var client = OkatanaClient.builder()
.baseUrl(url)
.apiKey(token)
.httpClient(http)
.build();
Inject a client when the application needs a custom executor, proxy, TLS context, cookie policy, or standardized transport configuration.
Redirect requirement¶
A supplied HttpClient must use HttpClient.Redirect.NEVER. The SDK rejects a redirecting client during construction. This rule prevents an Okatana bearer credential from being carried through an unexpected redirect path.
The SDK-created client already uses Redirect.NEVER.
Ownership¶
The caller owns an injected HttpClient. The SDK does not close it because HttpClient is designed for reuse. Use one long-lived client instead of creating a new client for each API operation.
What the SDK still controls¶
Even with a custom client, the SDK still controls:
- the Okatana
Authorizationheader; - the
Accept: application/jsonheader; - JSON request content type;
- per-request timeout;
- URL containment checks;
- retry decisions;
- response parsing and exception mapping.