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

pack-priv final Class DefaultWebClientBuilder

extends Object
implements Builder
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.function.client.WebClient.Builder
Imports
java.util.ArrayList, .Arrays, .LinkedHashMap, .List, .Map, java.util.function.Consumer, .Function, .Predicate, io.micrometer.observation.ObservationRegistry, reactor.core.publisher.Mono, org.springframework.http.HttpHeaders, .HttpStatusCode, org.springframework.http.client.reactive.ClientHttpConnector, .HttpComponentsClientHttpConnector, .JdkClientHttpConnector, .JettyClientHttpConnector, .ReactorClientHttpConnector, .ReactorNetty2ClientHttpConnector, org.springframework.http.codec.ClientCodecConfigurer, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .CollectionUtils, .LinkedMultiValueMap, .MultiValueMap, org.springframework.web.util.DefaultUriBuilderFactory, .UriBuilderFactory

Default implementation of WebClient.Builder.
Authors
Rossen Stoyanchev, Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
private String
private ClientHttpConnector
private MultiValueMap<String, String>
private HttpHeaders
private Consumer<WebClient.RequestHeadersSpec<?>>
private Map<String, ?>
private ExchangeFunction
private List<ExchangeFilterFunction>
private static final boolean
private static final boolean
private ClientRequestObservationConvention
private ObservationRegistry
private static final boolean
private static final boolean
private Map<Predicate<HttpStatusCode>, Function<ClientResponse, Mono<? extends Throwable>>>
private ExchangeStrategies
private List<Consumer<ExchangeStrategies.Builder>>
private UriBuilderFactory

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.apply.

Apply the given Consumer to this builder instance.

public WebClient.Builder
baseUrl(String baseUrl)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.baseUrl.

Configure a base URL for requests.

public WebClient
public WebClient.Builder
public WebClient.Builder
public WebClient.Builder
codecs(Consumer<ClientCodecConfigurer>
the configurer to apply
configurer
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.codecs.

Configure the codecs for the WebClient in the underlying ExchangeStrategies.

private MultiValueMap<String, String>
private HttpHeaders
public WebClient.Builder
defaultCookie(String
the cookie name
cookie
,
String...
the cookie values
values
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookie.

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

public WebClient.Builder
defaultCookies(Consumer<MultiValueMap<String, String>>
a function that consumes the cookies map
cookiesConsumer
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookies.

Provides access to every defaultCookie(String, String...) declared so far with the possibility to add, replace, or remove.

public WebClient.Builder
defaultHeader(String
the header name
header
,
String...
the header values
values
)

Implements org.springframework.web.reactive.function.client.WebClient.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 WebClient.Builder
defaultHeaders(Consumer<HttpHeaders>
the consumer
headersConsumer
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultHeaders.

Provides access to every defaultHeader(String, String...) declared so far with the possibility to add, replace, or remove.

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultRequest.

Provide a consumer to customize every request being built.

public WebClient.Builder
defaultStatusHandler(Predicate<HttpStatusCode>
to match responses with
statusPredicate
,
Function<ClientResponse, Mono<? extends Throwable>>
to map the response to an error signal
exceptionFunction
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultStatusHandler.

Register a default status handler to apply to every response.

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultUriVariables.

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

public WebClient.Builder
public WebClient.Builder
public WebClient.Builder
public WebClient.Builder
filter(ExchangeFilterFunction
the filter to be added to the chain
filter
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.filter.

Add the given filter to the end of the filter chain.

public WebClient.Builder
filters(Consumer<List<ExchangeFilterFunction>>
a function that consumes the filter list
filtersConsumer
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.filters.

Manipulate the filters with the given consumer.

private ClientHttpConnector
private MultiValueMap<String, String>
private ExchangeStrategies
private List<ExchangeFilterFunction>
private HttpHeaders
private UriBuilderFactory
public WebClient.Builder
observationConvention(ClientRequestObservationConvention
the observation convention to use
observationConvention
)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.observationConvention.

Provide an ObservationConvention to use for collecting metadata for the request observation.

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.observationRegistry.

Provide an ObservationRegistry to use for recording observations for HTTP client calls.

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.uriBuilderFactory.

Provide a pre-configured UriBuilderFactory instance.

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseUrlback to summary
private String baseUrl
Annotations
@Nullable
connectorback to summary
private ClientHttpConnector connector
Annotations
@Nullable
defaultCookiesback to summary
private MultiValueMap<String, String> defaultCookies
Annotations
@Nullable
defaultHeadersback to summary
private HttpHeaders defaultHeaders
Annotations
@Nullable
defaultRequestback to summary
private Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest
Annotations
@Nullable
defaultUriVariablesback to summary
private Map<String, ?> defaultUriVariables
Annotations
@Nullable
exchangeFunctionback to summary
private ExchangeFunction exchangeFunction
Annotations
@Nullable
filtersback to summary
private List<ExchangeFilterFunction> filters
Annotations
@Nullable
httpComponentsClientPresentback to summary
private static final boolean httpComponentsClientPresent
jettyClientPresentback to summary
private static final boolean jettyClientPresent
observationConventionback to summary
private ClientRequestObservationConvention observationConvention
Annotations
@Nullable
observationRegistryback to summary
private ObservationRegistry observationRegistry
reactorNetty2ClientPresentback to summary
private static final boolean reactorNetty2ClientPresent
reactorNettyClientPresentback to summary
private static final boolean reactorNettyClientPresent
statusHandlersback to summary
private Map<Predicate<HttpStatusCode>, Function<ClientResponse, Mono<? extends Throwable>>> statusHandlers
Annotations
@Nullable
strategiesback to summary
private ExchangeStrategies strategies
Annotations
@Nullable
strategiesConfigurersback to summary
private List<Consumer<ExchangeStrategies.Builder>> strategiesConfigurers
Annotations
@Nullable
uriBuilderFactoryback to summary
private UriBuilderFactory uriBuilderFactory
Annotations
@Nullable

Constructor Detail

DefaultWebClientBuilderback to summary
public DefaultWebClientBuilder()
DefaultWebClientBuilderback to summary
public DefaultWebClientBuilder(DefaultWebClientBuilder other)

Method Detail

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.apply.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.apply.

Apply the given Consumer to this builder instance.

This can be useful for applying pre-packaged customizations.

Parameters
builderConsumer:Consumer<WebClient.Builder>

the consumer to apply

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.baseUrl.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.baseUrl.

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

String baseUrl = "https://abc.go.com/v1";
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl);
WebClient client = WebClient.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.

Annotations
@Override
buildback to summary
public WebClient build()

Implements org.springframework.web.reactive.function.client.WebClient.Builder.build.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.build.

Build the WebClient instance.

Annotations
@Override
clientConnectorback to summary
public WebClient.Builder clientConnector(ClientHttpConnector connector)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.clientConnector.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.clientConnector.

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

By default this is set to ReactorClientHttpConnector.

Parameters
connector:ClientHttpConnector

the connector to use

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

Overrides java.lang.Object.clone.

Implements org.springframework.web.reactive.function.client.WebClient.Builder.clone.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.clone.

Clone this WebClient.Builder.

Returns:WebClient.Builder

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
codecsback to summary
public WebClient.Builder codecs(Consumer<ClientCodecConfigurer> configurer)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.codecs.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.codecs.

Configure the codecs for the WebClient in the underlying ExchangeStrategies.

Parameters
configurer:Consumer<ClientCodecConfigurer>

the configurer to apply

Annotations
@Override
copyDefaultCookiesback to summary
private MultiValueMap<String, String> copyDefaultCookies()
Annotations
@Nullable
copyDefaultHeadersback to summary
private HttpHeaders copyDefaultHeaders()
Annotations
@Nullable
defaultCookieback to summary
public WebClient.Builder defaultCookie(String cookie, String... values)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookie.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookie.

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

Parameters
cookie:String

the cookie name

values:String[]

the cookie values

Annotations
@Override
defaultCookiesback to summary
public WebClient.Builder defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookies.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.defaultCookies.

Provides access to every defaultCookie(String, String...) declared so far with the possibility to add, replace, or remove.

Parameters
cookiesConsumer:Consumer<MultiValueMap<String, String>>

a function that consumes the cookies map

Annotations
@Override
defaultHeaderback to summary
public WebClient.Builder defaultHeader(String header, String... values)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultHeader.

Doc from org.springframework.web.reactive.function.client.WebClient.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

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultHeaders.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.defaultHeaders.

Provides access to every defaultHeader(String, String...) declared so far with the possibility to add, replace, or remove.

Parameters
headersConsumer:Consumer<HttpHeaders>

the consumer

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultRequest.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.defaultRequest.

Provide a consumer to customize every request being built.

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

the consumer to use for modifying requests

Annotations
@Override
defaultStatusHandlerback to summary
public WebClient.Builder defaultStatusHandler(Predicate<HttpStatusCode> statusPredicate, Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultStatusHandler.

Doc from org.springframework.web.reactive.function.client.WebClient.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.

The default status handlers are not applied to exchangeTo*() methods, as those variants have direct access to the client response.

Parameters
statusPredicate:Predicate<HttpStatusCode>

to match responses with

exceptionFunction:Function<ClientResponse, Mono<? extends Throwable>>

to map the response to an error signal

Returns:WebClient.Builder

this builder

Annotations
@Override
defaultUriVariablesback to summary
public WebClient.Builder defaultUriVariables(Map<String, ?> defaultUriVariables)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.defaultUriVariables.

Doc from org.springframework.web.reactive.function.client.WebClient.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);
WebClient client = WebClient.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.

Annotations
@Override
exchangeFunctionback to summary
public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.exchangeFunction.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.exchangeFunction.

Provide an ExchangeFunction pre-configured with ClientHttpConnector and ExchangeStrategies.

This is an alternative to, and effectively overrides clientConnector, and exchangeStrategies(ExchangeStrategies).

Parameters
exchangeFunction:ExchangeFunction

the exchange function to use

Annotations
@Override
exchangeStrategiesback to summary
public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.exchangeStrategies.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.exchangeStrategies.

Configure the ExchangeStrategies to use.

For most cases, prefer using codecs(Consumer) which allows customizing the codecs in the ExchangeStrategies rather than replace them. That ensures multiple parties can contribute to codecs configuration.

By default this is set to ExchangeStrategies#withDefaults().

Parameters
strategies:ExchangeStrategies

the strategies to use

Annotations
@Override
exchangeStrategiesback to summary
public WebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.exchangeStrategies.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.exchangeStrategies.

Deprecated

Customize the strategies configured via exchangeStrategies(ExchangeStrategies). This method is designed for use in scenarios where multiple parties wish to update the ExchangeStrategies.

Annotations
@Override
@Deprecated
filterback to summary
public WebClient.Builder filter(ExchangeFilterFunction filter)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.filter.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.filter.

Add the given filter to the end of the filter chain.

Parameters
filter:ExchangeFilterFunction

the filter to be added to the chain

Annotations
@Override
filtersback to summary
public WebClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.filters.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.filters.

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

Parameters
filtersConsumer:Consumer<List<ExchangeFilterFunction>>

a function that consumes the filter list

Returns:WebClient.Builder

this builder

Annotations
@Override
initConnectorback to summary
private ClientHttpConnector initConnector()
initCookiesback to summary
private MultiValueMap<String, String> initCookies()
initExchangeStrategiesback to summary
private ExchangeStrategies initExchangeStrategies()
initFiltersback to summary
private List<ExchangeFilterFunction> initFilters()
initHeadersback to summary
private HttpHeaders initHeaders()
initUriBuilderFactoryback to summary
private UriBuilderFactory initUriBuilderFactory()
observationConventionback to summary
public WebClient.Builder observationConvention(ClientRequestObservationConvention observationConvention)

Implements org.springframework.web.reactive.function.client.WebClient.Builder.observationConvention.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.observationConvention.

Provide an ObservationConvention to use for collecting metadata for the request observation. Will use DefaultClientRequestObservationConvention if none provided.

Parameters
observationConvention:ClientRequestObservationConvention

the observation convention to use

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.observationRegistry.

Doc from org.springframework.web.reactive.function.client.WebClient.Builder.observationRegistry.

Provide an ObservationRegistry to use for recording observations for HTTP client calls.

Parameters
observationRegistry:ObservationRegistry

the observation registry to use

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

Implements org.springframework.web.reactive.function.client.WebClient.Builder.uriBuilderFactory.

Doc from org.springframework.web.reactive.function.client.WebClient.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

Annotations
@Override