Class RestClient.Builder

java.lang.Object
org.apache.juneau.rest.client.RestClient.Builder
Enclosing class:
RestClient

public static final class RestClient.Builder extends Object
Fluent builder for RestClient.
Since:
9.2.1
  • Method Details

    • transport

      Sets the HTTP transport to use.

      If not set, RestClient discovers a transport via ServiceLoader. When no sibling transport module is on the classpath, the built-in JavaHttpTransport (backed by the JDK's HttpClient) is used as the default.

      Parameters:
      value - The transport. Can be null (a transport is auto-discovered via ServiceLoader).
      Returns:
      This object.
    • rootUrl

      Sets a root URL prefix applied to all relative request URLs (those without ://).
      Parameters:
      value - The root URL (e.g. "https://api.example.com/v1"). May be null.
      Returns:
      This object.
    • allowPrivateUrls

      public RestClient.Builder allowPrivateUrls(boolean value)
      Opts every @Remote/@Url call made through this client out of the default deny-private SSRF guardrail (see org.apache.juneau.http.remote.RemoteUrlPolicy), for local-dev/intranet targets that are intentionally private.

      The effective per-call value is the logical OR of this setting, the "RestClient.allowPrivateUrls" system property, and the @Remote/@RemoteOp allowPrivateUrls annotation attribute: any one of the three opting in is sufficient. The http/ https scheme requirement is unaffected.

      Parameters:
      value - true to allow private/loopback/link-local/metadata @Remote targets. Default false.
      Returns:
      This object.
    • allowAddressRanges

      Re-permits, for this client only, addresses that the default SSRF guardrail denies solely because they fall in one of the special-purpose ranges 192.0.0.0/24, 198.18.0.0/15, 224.0.0.0/4, 240.0.0.0/4 or ff00::/8 (for example a lab or appliance network on 198.18.0.0/15).

      This is the per-client counterpart of the "RestClient.allowAddressRanges" system property and has exactly its narrow semantics: every entry (a CIDR range or a single address, parsed as a literal with no DNS lookup) must lie entirely inside one of those five ranges, and it never re-permits loopback, link-local/metadata (169.254.169.254), private, CGNAT or any other denied address. It applies to the literal-host check, the connect-time (DNS-pinned) address selection and every redirect hop of this client's @Remote calls, on every first-party transport.

      The effective allow-list is the union of these ranges and the system property's ranges (both are narrow, so the union is too). Calls accumulate. An invalid entry is reported by build() as an IllegalArgumentException.

      Parameters:
      value - The CIDR ranges or single addresses to allow; each element may also hold several comma- or whitespace-separated entries. null or empty adds nothing.
      Returns:
      This object.
    • sendRequestId

      public RestClient.Builder sendRequestId(boolean value)
      Controls the built-in X-Request-Id auto-send interceptor (enabled by default).

      When enabled, every request that does not already carry an X-Request-Id header (case-insensitive) is stamped with a freshly minted version-7 UUID before it is sent, and the server's echoed id is captured on the response (RestResponse.getRequestId()). Set to false to disable the interceptor entirely: no id is sent or captured, and a later interceptors(RestCallInterceptor...) call does not resurrect it. Callers can still set an id per request via RestRequest.requestId(String).

      Parameters:
      value - false to disable the auto-send interceptor. Default true.
      Returns:
      This object.
      Since:
      10.0.0
    • headers

      Adds default headers sent with every request.
      Parameters:
      value - The headers to add. Must not be null.
      Returns:
      This object.
    • header

      public RestClient.Builder header(String name, String value)
      Adds a default header sent with every request.
      Parameters:
      name - The header name. Must not be null.
      value - The header value (eager). May be null.
      Returns:
      This object.
    • header

      Adds a default header with a lazy value, evaluated at each request.
      Parameters:
      name - The header name. Must not be null.
      value - Supplier for the header value. Must not be null.
      Returns:
      This object.
    • queryData

      Adds default query parameters appended to every request URL.
      Parameters:
      value - The parts to add. Must not be null.
      Returns:
      This object.
    • queryData

      public RestClient.Builder queryData(String name, String value)
      Adds a default query parameter appended to every request URL.
      Parameters:
      name - The parameter name. Must not be null.
      value - The parameter value (eager). May be null.
      Returns:
      This object.
    • interceptors

      Adds one or more lifecycle interceptors called before/after each request.
      Parameters:
      value - The interceptors to add. Must not be null.
      Returns:
      This object.
    • debugFormatter

      Sets the formatter used for level-driven REST debug logging.

      The formatter renders cumulative content based on the resolved debug logger level:

      Parameters:
      value - The formatter. Can be null to restore the default formatter.
      Returns:
      This object.
    • debugLoggerName

      Sets the logger name used for REST debug records.

      If not set, defaults to RestClient.class.getName().

      Parameters:
      value - The logger name. Can be null to use the default logger name.
      Returns:
      This object.
    • bodyConverter

      Prepends custom body converters to the default converter list.

      Custom converters are checked before the defaults when RestRequest.body(Object) is called.

      Parameters:
      value - The converters to prepend. Must not be null.
      Returns:
      This object.
    • bodyConverters

      Replaces the entire body converter list (including defaults).

      Use this when you want full control over body conversion, including disabling the built-in defaults.

      Parameters:
      value - The complete replacement converter list. Must not be null.
      Returns:
      This object.
    • serializers

      Sets the serializer registry used for outbound bodies.
      Parameters:
      value - The serializer set. May be null.
      Returns:
      This object.
    • parsers

      Sets the parser registry used for inbound bodies.
      Parameters:
      value - The parser set. May be null.
      Returns:
      This object.
    • serializer

      Appends serializers (built into a SerializerSet at build time if no set was supplied).
      Parameters:
      value - The serializers to append. Must not be null.
      Returns:
      This object.
    • parser

      public RestClient.Builder parser(Parser... value)
      Appends parsers (built into a ParserSet at build time if no set was supplied).
      Parameters:
      value - The parsers to append. Must not be null.
      Returns:
      This object.
    • defaultSerializer

      Designates the default serializer used for outbound bodies when no registered serializer matches the requested media type.

      This is the explicit, opt-in way to restore a fallback serializer. Without it, a request that cannot be matched to a registered serializer (and any body requiring serialization on a serializer-less client) fails rather than silently defaulting to JSON. Set defaultSerializer(JsonSerializer.DEFAULT) to recover the pre-10.0 implicit-JSON behavior.

      Parameters:
      value - The default serializer. May be null.
      Returns:
      This object.
    • defaultParser

      Designates the default parser used when the response Content-Type is absent or matches no registered parser.

      This is the explicit, opt-in way to restore a fallback parser. Without it, a response whose Content-Type matches no registered parser fails with 415 Unsupported Media Type rather than silently parsing as JSON. Set defaultParser(JsonParser.DEFAULT) to recover the pre-10.0 implicit-JSON behavior.

      Parameters:
      value - The default parser. May be null.
      Returns:
      This object.
    • build

      public RestClient build()
      Builds and returns the RestClient.
      Returns:
      A new instance. Never null.