Top Description Fields Constructors Methods
org.springframework.web.client

pack-priv final Class DefaultRestClientBuilder

extends Object
implements Builder
Class Inheritance
All Implemented Interfaces
org.springframework.web.client.RestClient.Builder
Imports
java.util.ArrayList, .Arrays, .LinkedHashMap, .List, .Map, java.util.function.Consumer, .Predicate, io.micrometer.observation.ObservationRegistry, org.springframework.http.HttpHeaders, .HttpStatusCode, org.springframework.http.client.ClientHttpRequestFactory, .ClientHttpRequestInitializer, .ClientHttpRequestInterceptor, .HttpComponentsClientHttpRequestFactory, .InterceptingClientHttpRequestFactory, .JdkClientHttpRequestFactory, .JettyClientHttpRequestFactory, .SimpleClientHttpRequestFactory, org.springframework.http.client.observation.ClientRequestObservationConvention, org.springframework.http.converter.ByteArrayHttpMessageConverter, .HttpMessageConverter, .ResourceHttpMessageConverter, .StringHttpMessageConverter, org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter, org.springframework.http.converter.json.GsonHttpMessageConverter, .JsonbHttpMessageConverter, .KotlinSerializationJsonHttpMessageConverter, .MappingJackson2HttpMessageConverter, org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter, org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, org.springframework.web.util.DefaultUriBuilderFactory, .UriBuilderFactory, .UriTemplateHandler

Default implementation of RestClient.Builder.
Author
Arjen Poutsma
Since
6.1

Field Summary

Modifier and TypeField and Description
private String
private HttpHeaders
private Consumer<RestClient.RequestHeadersSpec<?>>
private Map<String, ?>
private static final boolean
private static final boolean
private List<ClientHttpRequestInitializer>
private List<ClientHttpRequestInterceptor>
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private static final boolean
private List<HttpMessageConverter<?>>
private ClientRequestObservationConvention
private ObservationRegistry
private ClientHttpRequestFactory
private List<StatusHandler>
private UriBuilderFactory

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public RestClient.Builder
apply(Consumer<RestClient.Builder>
the consumer to apply
builderConsumer
)

Implements org.springframework.web.client.RestClient.Builder.apply.

Apply the given Consumer to this builder instance.

public RestClient.Builder
baseUrl(String baseUrl)

Implements org.springframework.web.client.RestClient.Builder.baseUrl.

Configure a base URL for requests.

public RestClient
public RestClient.Builder
clone()

Overrides java.lang.Object.clone.

Implements org.springframework.web.client.RestClient.Builder.clone.

Clone this RestClient.Builder.

private HttpHeaders
public RestClient.Builder
defaultHeader(String
the header name
header
,
String...
the header values
values
)

Implements org.springframework.web.client.RestClient.Builder.defaultHeader.

Global option to specify a header to be added to every request, if the request does not already contain such a header.

public RestClient.Builder
defaultHeaders(Consumer<HttpHeaders>
the consumer
headersConsumer
)

Implements org.springframework.web.client.RestClient.Builder.defaultHeaders.

Provide a consumer to access to every default header declared so far, with the possibility to add, replace, or remove.

public RestClient.Builder
defaultRequest(Consumer<RestClient.RequestHeadersSpec<?>>
the consumer to use for modifying requests
defaultRequest
)

Implements org.springframework.web.client.RestClient.Builder.defaultRequest.

Provide a consumer to customize every request being built.

public RestClient.Builder
defaultStatusHandler(Predicate<HttpStatusCode>
to match responses with
statusPredicate
,
RestClient.ResponseSpec.ErrorHandler
handler that typically, though not necessarily, throws an exception
errorHandler
)

Implements org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Register a default status handler to apply to every response.

public RestClient.Builder
defaultStatusHandler(ResponseErrorHandler
handler that typically, though not necessarily, throws an exception
errorHandler
)

Implements org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Register a default status handler to apply to every response.

private RestClient.Builder
public RestClient.Builder
defaultUriVariables(Map<String, ?> defaultUriVariables)

Implements org.springframework.web.client.RestClient.Builder.defaultUriVariables.

Configure default URL variable values to use when expanding URI templates with a Map.

private static ClientHttpRequestFactory
private static UriBuilderFactory
private static boolean
hasRestTemplateDefaults(DefaultUriBuilderFactory factory)

Indicate whether this DefaultUriBuilderFactory uses the default RestTemplate settings.

private HttpHeaders
private List<ClientHttpRequestInitializer>
private List<ClientHttpRequestInterceptor>
private List<HttpMessageConverter<?>>
private ClientHttpRequestFactory
private UriBuilderFactory
public RestClient.Builder
messageConverters(Consumer<List<HttpMessageConverter<?>>>
the configurer to apply
configurer
)

Implements org.springframework.web.client.RestClient.Builder.messageConverters.

Configure the message converters for the RestClient to use.

public RestClient.Builder
observationConvention(ClientRequestObservationConvention
the observation convention to use
observationConvention
)

Implements org.springframework.web.client.RestClient.Builder.observationConvention.

Configure the io.micrometer.observation.ObservationConvention to use for collecting metadata for the request observation.

public RestClient.Builder
observationRegistry(ObservationRegistry
the observation registry to use
observationRegistry
)

Implements org.springframework.web.client.RestClient.Builder.observationRegistry.

Configure the io.micrometer.observation.ObservationRegistry to use for recording HTTP client observations.

public RestClient.Builder
public RestClient.Builder
requestInitializer(ClientHttpRequestInitializer
the initializer to be added to the chain
initializer
)

Implements org.springframework.web.client.RestClient.Builder.requestInitializer.

Add the given request initializer to the end of the initializer chain.

public RestClient.Builder
requestInitializers(Consumer<List<ClientHttpRequestInitializer>>
a function that consumes the initializers list
initializersConsumer
)

Implements org.springframework.web.client.RestClient.Builder.requestInitializers.

Manipulate the initializers with the given consumer.

public RestClient.Builder
requestInterceptor(ClientHttpRequestInterceptor
the interceptor to be added to the chain
interceptor
)

Implements org.springframework.web.client.RestClient.Builder.requestInterceptor.

Add the given request interceptor to the end of the interceptor chain.

public RestClient.Builder
requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>>
a function that consumes the interceptors list
interceptorsConsumer
)

Implements org.springframework.web.client.RestClient.Builder.requestInterceptors.

Manipulate the interceptors with the given consumer.

public RestClient.Builder
uriBuilderFactory(UriBuilderFactory
the URI builder factory to use
uriBuilderFactory
)

Implements org.springframework.web.client.RestClient.Builder.uriBuilderFactory.

Provide a pre-configured UriBuilderFactory instance.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseUrlback to summary
private String baseUrl
Annotations
@Nullable
defaultHeadersback to summary
private HttpHeaders defaultHeaders
Annotations
@Nullable
defaultRequestback to summary
private Consumer<RestClient.RequestHeadersSpec<?>> defaultRequest
Annotations
@Nullable
defaultUriVariablesback to summary
private Map<String, ?> defaultUriVariables
Annotations
@Nullable
gsonPresentback to summary
private static final boolean gsonPresent
httpComponentsClientPresentback to summary
private static final boolean httpComponentsClientPresent
initializersback to summary
private List<ClientHttpRequestInitializer> initializers
Annotations
@Nullable
interceptorsback to summary
private List<ClientHttpRequestInterceptor> interceptors
Annotations
@Nullable
jackson2CborPresentback to summary
private static final boolean jackson2CborPresent
jackson2Presentback to summary
private static final boolean jackson2Present
jackson2SmilePresentback to summary
private static final boolean jackson2SmilePresent
jdkClientPresentback to summary
private static final boolean jdkClientPresent
jettyClientPresentback to summary
private static final boolean jettyClientPresent
jsonbPresentback to summary
private static final boolean jsonbPresent
kotlinSerializationJsonPresentback to summary
private static final boolean kotlinSerializationJsonPresent
messageConvertersback to summary
private List<HttpMessageConverter<?>> messageConverters
Annotations
@Nullable
observationConventionback to summary
private ClientRequestObservationConvention observationConvention
Annotations
@Nullable
observationRegistryback to summary
private ObservationRegistry observationRegistry
requestFactoryback to summary
private ClientHttpRequestFactory requestFactory
Annotations
@Nullable
statusHandlersback to summary
private List<StatusHandler> statusHandlers
Annotations
@Nullable
uriBuilderFactoryback to summary
private UriBuilderFactory uriBuilderFactory
Annotations
@Nullable

Constructor Detail

DefaultRestClientBuilderback to summary
public DefaultRestClientBuilder()
DefaultRestClientBuilderback to summary
public DefaultRestClientBuilder(DefaultRestClientBuilder other)
DefaultRestClientBuilderback to summary
public DefaultRestClientBuilder(RestTemplate restTemplate)

Method Detail

applyback to summary
public RestClient.Builder apply(Consumer<RestClient.Builder> builderConsumer)

Implements org.springframework.web.client.RestClient.Builder.apply.

Doc from org.springframework.web.client.RestClient.Builder.apply.

Apply the given Consumer to this builder instance.

This can be useful for applying pre-packaged customizations.

Parameters
builderConsumer:Consumer<RestClient.Builder>

the consumer to apply

Returns:RestClient.Builder

this builder

Annotations
@Override
baseUrlback to summary
public RestClient.Builder baseUrl(String baseUrl)

Implements org.springframework.web.client.RestClient.Builder.baseUrl.

Doc from org.springframework.web.client.RestClient.Builder.baseUrl.

Configure a base URL for requests. Effectively a shortcut for:

String baseUrl = "https://abc.go.com/v1";
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl);
RestClient client = RestClient.builder().uriBuilderFactory(factory).build();

The DefaultUriBuilderFactory is used to prepare the URL for every request with the given base URL, unless the URL request for a given URL is absolute in which case the base URL is ignored.

Note

this method is mutually exclusive with uriBuilderFactory(UriBuilderFactory). If both are used, the baseUrl value provided here will be ignored.

Returns:RestClient.Builder

this builder

Annotations
@Override
buildback to summary
public RestClient build()

Implements org.springframework.web.client.RestClient.Builder.build.

Doc from org.springframework.web.client.RestClient.Builder.build.

Build the RestClient instance.

Annotations
@Override
cloneback to summary
public RestClient.Builder clone()

Overrides java.lang.Object.clone.

Implements org.springframework.web.client.RestClient.Builder.clone.

Doc from org.springframework.web.client.RestClient.Builder.clone.

Clone this RestClient.Builder.

Returns:RestClient.Builder

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
copyDefaultHeadersback to summary
private HttpHeaders copyDefaultHeaders()
Annotations
@Nullable
defaultHeaderback to summary
public RestClient.Builder defaultHeader(String header, String... values)

Implements org.springframework.web.client.RestClient.Builder.defaultHeader.

Doc from org.springframework.web.client.RestClient.Builder.defaultHeader.

Global option to specify a header to be added to every request, if the request does not already contain such a header.

Parameters
header:String

the header name

values:String[]

the header values

Returns:RestClient.Builder

this builder

Annotations
@Override
defaultHeadersback to summary
public RestClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)

Implements org.springframework.web.client.RestClient.Builder.defaultHeaders.

Doc from org.springframework.web.client.RestClient.Builder.defaultHeaders.

Provide a consumer to access to every default header declared so far, with the possibility to add, replace, or remove.

Parameters
headersConsumer:Consumer<HttpHeaders>

the consumer

Returns:RestClient.Builder

this builder

Annotations
@Override
defaultRequestback to summary
public RestClient.Builder defaultRequest(Consumer<RestClient.RequestHeadersSpec<?>> defaultRequest)

Implements org.springframework.web.client.RestClient.Builder.defaultRequest.

Doc from org.springframework.web.client.RestClient.Builder.defaultRequest.

Provide a consumer to customize every request being built.

Parameters
defaultRequest:Consumer<RestClient.RequestHeadersSpec<?>>

the consumer to use for modifying requests

Returns:RestClient.Builder

this builder

Annotations
@Override
defaultStatusHandlerback to summary
public RestClient.Builder defaultStatusHandler(Predicate<HttpStatusCode> statusPredicate, RestClient.ResponseSpec.ErrorHandler errorHandler)

Implements org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Doc from org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Register a default status handler to apply to every response. Such default handlers are applied in the order in which they are registered, and after any others that are registered for a specific response.

Parameters
statusPredicate:Predicate<HttpStatusCode>

to match responses with

errorHandler:RestClient.ResponseSpec.ErrorHandler

handler that typically, though not necessarily, throws an exception

Returns:RestClient.Builder

this builder

Annotations
@Override
defaultStatusHandlerback to summary
public RestClient.Builder defaultStatusHandler(ResponseErrorHandler errorHandler)

Implements org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Doc from org.springframework.web.client.RestClient.Builder.defaultStatusHandler.

Register a default status handler to apply to every response. Such default handlers are applied in the order in which they are registered, and after any others that are registered for a specific response.

Parameters
errorHandler:ResponseErrorHandler

handler that typically, though not necessarily, throws an exception

Returns:RestClient.Builder

this builder

Annotations
@Override
defaultStatusHandlerInternalback to summary
private RestClient.Builder defaultStatusHandlerInternal(StatusHandler statusHandler)
defaultUriVariablesback to summary
public RestClient.Builder defaultUriVariables(Map<String, ?> defaultUriVariables)

Implements org.springframework.web.client.RestClient.Builder.defaultUriVariables.

Doc from org.springframework.web.client.RestClient.Builder.defaultUriVariables.

Configure default URL variable values to use when expanding URI templates with a Map. Effectively a shortcut for:

Map<String, ?> defaultVars = ...;
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
factory.setDefaultVariables(defaultVars);
RestClient client = RestClient.builder().uriBuilderFactory(factory).build();

Note

this method is mutually exclusive with uriBuilderFactory(UriBuilderFactory). If both are used, the defaultUriVariables value provided here will be ignored.

Returns:RestClient.Builder

this builder

Annotations
@Override
getRequestFactoryback to summary
private static ClientHttpRequestFactory getRequestFactory(RestTemplate restTemplate)
getUriBuilderFactoryback to summary
private static UriBuilderFactory getUriBuilderFactory(RestTemplate restTemplate)
Annotations
@Nullable
hasRestTemplateDefaultsback to summary
private static boolean hasRestTemplateDefaults(DefaultUriBuilderFactory factory)

Indicate whether this DefaultUriBuilderFactory uses the default RestTemplate settings.

initHeadersback to summary
private HttpHeaders initHeaders()
initInitializersback to summary
private List<ClientHttpRequestInitializer> initInitializers()
initInterceptorsback to summary
private List<ClientHttpRequestInterceptor> initInterceptors()
initMessageConvertersback to summary
private List<HttpMessageConverter<?>> initMessageConverters()
initRequestFactoryback to summary
private ClientHttpRequestFactory initRequestFactory()
initUriBuilderFactoryback to summary
private UriBuilderFactory initUriBuilderFactory()
messageConvertersback to summary
public RestClient.Builder messageConverters(Consumer<List<HttpMessageConverter<?>>> configurer)

Implements org.springframework.web.client.RestClient.Builder.messageConverters.

Doc from org.springframework.web.client.RestClient.Builder.messageConverters.

Configure the message converters for the RestClient to use.

Parameters
configurer:Consumer<List<HttpMessageConverter<?>>>

the configurer to apply

Returns:RestClient.Builder

this builder

Annotations
@Override
observationConventionback to summary
public RestClient.Builder observationConvention(ClientRequestObservationConvention observationConvention)

Implements org.springframework.web.client.RestClient.Builder.observationConvention.

Doc from org.springframework.web.client.RestClient.Builder.observationConvention.

Configure the io.micrometer.observation.ObservationConvention to use for collecting metadata for the request observation. Will use org.springframework.http.client.observation.DefaultClientRequestObservationConvention if none provided.

Parameters
observationConvention:ClientRequestObservationConvention

the observation convention to use

Returns:RestClient.Builder

this builder

Annotations
@Override
observationRegistryback to summary
public RestClient.Builder observationRegistry(ObservationRegistry observationRegistry)

Implements org.springframework.web.client.RestClient.Builder.observationRegistry.

Doc from org.springframework.web.client.RestClient.Builder.observationRegistry.

Configure the io.micrometer.observation.ObservationRegistry to use for recording HTTP client observations.

Parameters
observationRegistry:ObservationRegistry

the observation registry to use

Returns:RestClient.Builder

this builder

Annotations
@Override
requestFactoryback to summary
public RestClient.Builder requestFactory(ClientHttpRequestFactory requestFactory)

Implements org.springframework.web.client.RestClient.Builder.requestFactory.

Doc from org.springframework.web.client.RestClient.Builder.requestFactory.

Configure the ClientHttpRequestFactory to use. This is useful for plugging in and/or customizing options of the underlying HTTP client library (e.g. SSL).

If no request factory is specified, RestClient uses Apache Http Client, Jetty Http Client if available on the classpath, and defaults to the JDK HttpClient if the java.net.http module is loaded, or to a simple default otherwise.

Parameters
requestFactory:ClientHttpRequestFactory

the request factory to use

Returns:RestClient.Builder

this builder

Annotations
@Override
requestInitializerback to summary
public RestClient.Builder requestInitializer(ClientHttpRequestInitializer initializer)

Implements org.springframework.web.client.RestClient.Builder.requestInitializer.

Doc from org.springframework.web.client.RestClient.Builder.requestInitializer.

Add the given request initializer to the end of the initializer chain.

Parameters
initializer:ClientHttpRequestInitializer

the initializer to be added to the chain

Returns:RestClient.Builder

this builder

Annotations
@Override
requestInitializersback to summary
public RestClient.Builder requestInitializers(Consumer<List<ClientHttpRequestInitializer>> initializersConsumer)

Implements org.springframework.web.client.RestClient.Builder.requestInitializers.

Doc from org.springframework.web.client.RestClient.Builder.requestInitializers.

Manipulate the initializers with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove initializers, change ordering, etc.

Parameters
initializersConsumer:Consumer<List<ClientHttpRequestInitializer>>

a function that consumes the initializers list

Returns:RestClient.Builder

this builder

Annotations
@Override
requestInterceptorback to summary
public RestClient.Builder requestInterceptor(ClientHttpRequestInterceptor interceptor)

Implements org.springframework.web.client.RestClient.Builder.requestInterceptor.

Doc from org.springframework.web.client.RestClient.Builder.requestInterceptor.

Add the given request interceptor to the end of the interceptor chain.

Parameters
interceptor:ClientHttpRequestInterceptor

the interceptor to be added to the chain

Returns:RestClient.Builder

this builder

Annotations
@Override
requestInterceptorsback to summary
public RestClient.Builder requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer)

Implements org.springframework.web.client.RestClient.Builder.requestInterceptors.

Doc from org.springframework.web.client.RestClient.Builder.requestInterceptors.

Manipulate the interceptors with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove interceptors, change ordering, etc.

Parameters
interceptorsConsumer:Consumer<List<ClientHttpRequestInterceptor>>

a function that consumes the interceptors list

Returns:RestClient.Builder

this builder

Annotations
@Override
uriBuilderFactoryback to summary
public RestClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)

Implements org.springframework.web.client.RestClient.Builder.uriBuilderFactory.

Doc from org.springframework.web.client.RestClient.Builder.uriBuilderFactory.

Provide a pre-configured UriBuilderFactory instance. This is an alternative to, and effectively overrides the following shortcut properties:

Parameters
uriBuilderFactory:UriBuilderFactory

the URI builder factory to use

Returns:RestClient.Builder

this builder

Annotations
@Override