final class DefaultWebClientBuilder extends java.lang.Object implements WebClient.Builder
WebClient.Builder
.Modifier and Type | Field and Description |
---|---|
private java.lang.String |
baseUrl |
private ClientHttpConnector |
connector |
private MultiValueMap<java.lang.String,java.lang.String> |
defaultCookies |
private HttpHeaders |
defaultHeaders |
private java.util.function.Consumer<WebClient.RequestHeadersSpec<?>> |
defaultRequest |
private java.util.Map<java.lang.String,?> |
defaultUriVariables |
private ExchangeFunction |
exchangeFunction |
private ExchangeStrategies |
exchangeStrategies |
private java.util.List<ExchangeFilterFunction> |
filters |
private UriBuilderFactory |
uriBuilderFactory |
Constructor and Description |
---|
DefaultWebClientBuilder() |
DefaultWebClientBuilder(DefaultWebClientBuilder other) |
Modifier and Type | Method and Description |
---|---|
WebClient.Builder |
apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
Apply the given
Consumer to this builder instance. |
WebClient.Builder |
baseUrl(java.lang.String baseUrl)
Configure a base URL for requests performed through the client.
|
WebClient |
build()
Builder the
WebClient instance. |
WebClient.Builder |
clientConnector(ClientHttpConnector connector)
Configure the
ClientHttpConnector to use. |
WebClient.Builder |
clone()
Clone this
WebClient.Builder . |
WebClient.Builder |
defaultCookie(java.lang.String cookie,
java.lang.String... values)
Global option to specify a cookie to be added to every request,
if the request does not already contain such a cookie.
|
WebClient.Builder |
defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Provides access to every
WebClient.Builder.defaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultHeader(java.lang.String header,
java.lang.String... values)
Global option to specify a header to be added to every request,
if the request does not already contain such a header.
|
WebClient.Builder |
defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
Provides access to every
WebClient.Builder.defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultRequest(java.util.function.Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
Provide a consumer to modify every request being built just before the
call to
exchange() . |
WebClient.Builder |
defaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Configure default URI variable values that will be used when expanding
URI templates using a
Map . |
WebClient.Builder |
exchangeFunction(ExchangeFunction exchangeFunction)
|
WebClient.Builder |
exchangeStrategies(ExchangeStrategies strategies)
Configure the
ExchangeStrategies to use. |
WebClient.Builder |
filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.
|
WebClient.Builder |
filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer.
|
private MultiValueMap<java.lang.String,java.lang.String> |
initCookies() |
private ExchangeFunction |
initExchangeFunction() |
private java.util.List<ExchangeFilterFunction> |
initFilters() |
private HttpHeaders |
initHeaders() |
private UriBuilderFactory |
initUriBuilderFactory() |
private static HttpHeaders |
unmodifiableCopy(HttpHeaders headers) |
private static <K,V> MultiValueMap<K,V> |
unmodifiableCopy(MultiValueMap<K,V> map) |
WebClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance. |
@Nullable private java.lang.String baseUrl
@Nullable private java.util.Map<java.lang.String,?> defaultUriVariables
@Nullable private UriBuilderFactory uriBuilderFactory
@Nullable private HttpHeaders defaultHeaders
@Nullable private MultiValueMap<java.lang.String,java.lang.String> defaultCookies
@Nullable private java.util.function.Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest
@Nullable private java.util.List<ExchangeFilterFunction> filters
@Nullable private ClientHttpConnector connector
private ExchangeStrategies exchangeStrategies
@Nullable private ExchangeFunction exchangeFunction
public DefaultWebClientBuilder()
public DefaultWebClientBuilder(DefaultWebClientBuilder other)
public WebClient.Builder baseUrl(java.lang.String baseUrl)
WebClient.Builder
For example given base URL "https://abc.go.com/v1":
Mono<Account> result = client.get().uri("/accounts/{id}", 43) .retrieve() .bodyToMono(Account.class); // Result: https://abc.go.com/v1/accounts/43 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .retrieve() .bodyToFlux(Account.class); // Result: https://abc.go.com/v1/accounts?q=12
The base URL can be overridden with an absolute URI:
Mono<Account> result = client.get().uri("https://xyz.com/path") .retrieve() .bodyToMono(Account.class); // Result: https://xyz.com/path
Or partially overridden with a UriBuilder
:
Flux<Account> result = client.get() .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) .retrieve() .bodyToFlux(Account.class); // Result: https://abc.go.com/v2/accounts?q=12
baseUrl
in interface WebClient.Builder
WebClient.Builder.defaultUriVariables(Map)
,
WebClient.Builder.uriBuilderFactory(UriBuilderFactory)
public WebClient.Builder defaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
WebClient.Builder
Map
.defaultUriVariables
in interface WebClient.Builder
defaultUriVariables
- the default values to useWebClient.Builder.baseUrl(String)
,
WebClient.Builder.uriBuilderFactory(UriBuilderFactory)
public WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
WebClient.Builder
UriBuilderFactory
instance. This is
an alternative to and effectively overrides the following:
uriBuilderFactory
in interface WebClient.Builder
uriBuilderFactory
- the URI builder factory to useWebClient.Builder.baseUrl(String)
,
WebClient.Builder.defaultUriVariables(Map)
public WebClient.Builder defaultHeader(java.lang.String header, java.lang.String... values)
WebClient.Builder
defaultHeader
in interface WebClient.Builder
header
- the header namevalues
- the header valuespublic WebClient.Builder defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
WebClient.Builder
WebClient.Builder.defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove.defaultHeaders
in interface WebClient.Builder
headersConsumer
- the consumerprivate HttpHeaders initHeaders()
public WebClient.Builder defaultCookie(java.lang.String cookie, java.lang.String... values)
WebClient.Builder
defaultCookie
in interface WebClient.Builder
cookie
- the cookie namevalues
- the cookie valuespublic WebClient.Builder defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
WebClient.Builder
WebClient.Builder.defaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove.defaultCookies
in interface WebClient.Builder
cookiesConsumer
- a function that consumes the cookies mapprivate MultiValueMap<java.lang.String,java.lang.String> initCookies()
public WebClient.Builder defaultRequest(java.util.function.Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
WebClient.Builder
exchange()
.defaultRequest
in interface WebClient.Builder
defaultRequest
- the consumer to use for modifying requestspublic WebClient.Builder filter(ExchangeFilterFunction filter)
WebClient.Builder
filter
in interface WebClient.Builder
filter
- the filter to be added to the chainpublic WebClient.Builder filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
WebClient.Builder
filters
in interface WebClient.Builder
filtersConsumer
- a function that consumes the filter listprivate java.util.List<ExchangeFilterFunction> initFilters()
public WebClient.Builder clientConnector(ClientHttpConnector connector)
WebClient.Builder
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
.
clientConnector
in interface WebClient.Builder
connector
- the connector to usepublic WebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
WebClient.Builder
ExchangeStrategies
to use.
By default this is obtained from ExchangeStrategies.withDefaults()
.
exchangeStrategies
in interface WebClient.Builder
strategies
- the strategies to usepublic WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
WebClient.Builder
ExchangeFunction
pre-configured with
ClientHttpConnector
and ExchangeStrategies
.
This is an alternative to, and effectively overrides
WebClient.Builder.clientConnector(org.springframework.http.client.reactive.ClientHttpConnector)
, and WebClient.Builder.exchangeStrategies(org.springframework.web.reactive.function.client.ExchangeStrategies)
.
exchangeFunction
in interface WebClient.Builder
exchangeFunction
- the exchange function to usepublic WebClient.Builder apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
WebClient.Builder
Consumer
to this builder instance.
This can be useful for applying pre-packaged customizations.
apply
in interface WebClient.Builder
builderConsumer
- the consumer to applypublic WebClient.Builder clone()
WebClient.Builder
WebClient.Builder
.clone
in interface WebClient.Builder
clone
in class java.lang.Object
public WebClient build()
WebClient.Builder
WebClient
instance.build
in interface WebClient.Builder
private ExchangeFunction initExchangeFunction()
private UriBuilderFactory initUriBuilderFactory()
private static HttpHeaders unmodifiableCopy(HttpHeaders headers)
private static <K,V> MultiValueMap<K,V> unmodifiableCopy(MultiValueMap<K,V> map)