Class RestClient.Builder
- Enclosing class:
- RestClient
RestClient.- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionallowAddressRanges(String... value) Re-permits, for this client only, addresses that the default SSRF guardrail denies solely because they fall in one of the special-purpose ranges192.0.0.0/24 ,198.18.0.0/15 ,224.0.0.0/4 ,240.0.0.0/4 orff00::/8 (for example a lab or appliance network on198.18.0.0/15 ).allowPrivateUrls(boolean value) Opts every@Remote/@Urlcall made through this client out of the default deny-private SSRF guardrail (seeorg.apache.juneau.http.remote.RemoteUrlPolicy), for local-dev/intranet targets that are intentionally private.bodyConverter(BodyConverter<?>... value) Prepends custom body converters to the default converter list.bodyConverters(BodyConverter<?>... value) Replaces the entire body converter list (including defaults).build()Builds and returns theRestClient.Sets the formatter used for level-driven REST debug logging.debugLoggerName(String value) Sets the logger name used for REST debug records.defaultParser(Parser value) Designates the default parser used when the responseContent-Typeis absent or matches no registered parser.defaultSerializer(Serializer value) Designates the default serializer used for outbound bodies when no registered serializer matches the requested media type.Adds a default header sent with every request.Adds a default header with a lazy value, evaluated at each request.headers(HttpHeader... value) Adds default headers sent with every request.interceptors(RestCallInterceptor... value) Adds one or more lifecycle interceptors called before/after each request.Appends parsers (built into aParserSetat build time if no set was supplied).Sets the parser registry used for inbound bodies.Adds a default query parameter appended to every request URL.Adds default query parameters appended to every request URL.Sets a root URL prefix applied to all relative request URLs (those without://).sendRequestId(boolean value) Controls the built-inX-Request-Idauto-send interceptor (enabled by default).serializer(Serializer... value) Appends serializers (built into aSerializerSetat build time if no set was supplied).serializers(SerializerSet value) Sets the serializer registry used for outbound bodies.transport(HttpTransport value) Sets the HTTP transport to use.
-
Method Details
-
transport
Sets the HTTP transport to use.If not set,
RestClientdiscovers a transport viaServiceLoader. When no sibling transport module is on the classpath, the built-inJavaHttpTransport(backed by the JDK'sHttpClient) is used as the default.- Parameters:
value- The transport. Can benull (a transport is auto-discovered viaServiceLoader).- 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 benull .- Returns:
- This object.
-
allowPrivateUrls
Opts every@Remote/@Urlcall made through this client out of the default deny-private SSRF guardrail (seeorg.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/@RemoteOpallowPrivateUrlsannotation attribute: any one of the three opting in is sufficient. Thehttp/httpsscheme requirement is unaffected.- Parameters:
value-trueto allow private/loopback/link-local/metadata@Remotetargets. Defaultfalse.- 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 ranges192.0.0.0/24 ,198.18.0.0/15 ,224.0.0.0/4 ,240.0.0.0/4 orff00::/8 (for example a lab or appliance network on198.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@Remotecalls, 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 anIllegalArgumentException.- 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
Controls the built-inX-Request-Idauto-send interceptor (enabled by default).When enabled, every request that does not already carry an
X-Request-Idheader (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 tofalseto disable the interceptor entirely: no id is sent or captured, and a laterinterceptors(RestCallInterceptor...)call does not resurrect it. Callers can still set an id per request viaRestRequest.requestId(String).- Parameters:
value-falseto disable the auto-send interceptor. Defaulttrue.- Returns:
- This object.
- Since:
- 10.0.0
-
headers
Adds default headers sent with every request.- Parameters:
value- The headers to add. Must not benull .- Returns:
- This object.
-
header
Adds a default header sent with every request.- Parameters:
name- The header name. Must not benull .value- The header value (eager). May benull .- Returns:
- This object.
-
header
Adds a default header with a lazy value, evaluated at each request.- Parameters:
name- The header name. Must not benull .value- Supplier for the header value. Must not benull .- Returns:
- This object.
-
queryData
Adds default query parameters appended to every request URL.- Parameters:
value- The parts to add. Must not benull .- Returns:
- This object.
-
queryData
Adds a default query parameter appended to every request URL.- Parameters:
name- The parameter name. Must not benull .value- The parameter value (eager). May benull .- Returns:
- This object.
-
interceptors
Adds one or more lifecycle interceptors called before/after each request.- Parameters:
value- The interceptors to add. Must not benull .- 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:
INFO- basic line (RestClientDebugFormatter.formatBasic(RestRequest, RestResponse)).FINE- basic + headers.FINEST- basic + headers + body.
- Parameters:
value- The formatter. Can benull 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 benull 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 benull .- 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 benull .- Returns:
- This object.
-
serializers
Sets the serializer registry used for outbound bodies.- Parameters:
value- The serializer set. May benull .- Returns:
- This object.
-
parsers
Sets the parser registry used for inbound bodies.- Parameters:
value- The parser set. May benull .- Returns:
- This object.
-
serializer
Appends serializers (built into aSerializerSetat build time if no set was supplied).- Parameters:
value- The serializers to append. Must not benull .- Returns:
- This object.
-
parser
Appends parsers (built into aParserSetat build time if no set was supplied).- Parameters:
value- The parsers to append. Must not benull .- 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 benull .- Returns:
- This object.
-
defaultParser
Designates the default parser used when the responseContent-Typeis absent or matches no registered parser.This is the explicit, opt-in way to restore a fallback parser. Without it, a response whose
Content-Typematches no registered parser fails with415 Unsupported Media Type rather than silently parsing as JSON. SetdefaultParser(JsonParser.DEFAULT)to recover the pre-10.0 implicit-JSON behavior.- Parameters:
value- The default parser. May benull .- Returns:
- This object.
-
build
Builds and returns theRestClient.- Returns:
- A new instance. Never
null .
-