Class CryptoServiceClient.Builder

java.lang.Object
co.cryptoservice.sdk.CryptoServiceClient.Builder
Enclosing class:
CryptoServiceClient

public static final class CryptoServiceClient.Builder extends Object
Builds a CryptoServiceClient. Not thread-safe; the client it builds is.
  • Method Details

    • baseUrl

      public CryptoServiceClient.Builder baseUrl(String baseUrl)
      The server's base URL, for example http://127.0.0.1:3101: http or https, with a host, and no user info, query or fragment; a path prefix is kept and a trailing slash dropped.
      Parameters:
      baseUrl - the base URL
      Returns:
      this builder
    • apiKey

      public CryptoServiceClient.Builder apiKey(String apiKey)
      An API key, sent as x-api-key; null sends none.
      Parameters:
      apiKey - the key, or null
      Returns:
      this builder
    • token

      public CryptoServiceClient.Builder token(String token)
      A JWT, sent as Authorization: Bearer <token>; null sends none.
      Parameters:
      token - the token, or null
      Returns:
      this builder
    • timeout

      public CryptoServiceClient.Builder timeout(Duration timeout)
      The timeout of each attempt (connect and response headers); 30 seconds when not set.
      Parameters:
      timeout - a positive duration
      Returns:
      this builder
    • deadline

      public CryptoServiceClient.Builder deadline(Duration deadline)
      The limit on a whole call, retries and waits included; none when not set. When it passes, the call fails with a TransportError whose timedOut() is true.
      Parameters:
      deadline - a positive duration, or null for none
      Returns:
      this builder
    • retry

      Retries of transient failures; RetryOptions.NONE (the default) sends every call once.
      Parameters:
      retry - the retry options
      Returns:
      this builder
    • traceparent

      public CryptoServiceClient.Builder traceparent(String traceparent)
      A fixed W3C traceparent sent with every request; null sends none.
      Parameters:
      traceparent - a version-traceid-parentid-flags value, or null
      Returns:
      this builder
      Throws:
      IllegalArgumentException - when the value is not a traceparent
    • autoTraceparent

      public CryptoServiceClient.Builder autoTraceparent(boolean enabled)
      Sends a freshly generated W3C traceparent with every request (true), or none (false).
      Parameters:
      enabled - whether to generate one per request
      Returns:
      this builder
    • responseListener

      public CryptoServiceClient.Builder responseListener(ResponseListener listener)
      Observes every response's status and headers; null for none.
      Parameters:
      listener - the listener, or null
      Returns:
      this builder
    • httpClient

      public CryptoServiceClient.Builder httpClient(HttpClient httpClient)
      An HttpClient to send through instead of the client's own, for tests or a custom proxy or executor. It must not follow redirects. Its TLS settings are the caller's responsibility, and CryptoServiceClient.close() leaves it open.
      Parameters:
      httpClient - the HTTP client, or null for the client's own
      Returns:
      this builder
    • build

      public CryptoServiceClient build()
      Builds the client.
      Returns:
      the client, thread-safe
      Throws:
      IllegalArgumentException - when the base URL is missing or malformed, a duration is not positive, a credential is not a valid header value, or the injected HTTP client follows redirects
    • toString

      public String toString()
      Names the settings; the credentials are redacted.
      Overrides:
      toString in class Object
      Returns:
      a description safe to log