Modifier and Type | Method and Description |
---|---|
WebClient.Builder |
apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
Shortcut for pre-packaged customizations to WebTest builder.
|
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 cookieName,
java.lang.String... cookieValues)
Add the given header to all requests that haven't added it.
|
WebClient.Builder |
defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Manipulate the default cookies with the given consumer.
|
WebClient.Builder |
defaultHeader(java.lang.String headerName,
java.lang.String... headerValues)
Add the given header to all requests that have not added it.
|
WebClient.Builder |
defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
Manipulate the default headers with the given consumer.
|
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)
Provide a pre-configured
ExchangeFunction instance. |
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.
|
WebClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance. |
WebClient.Builder baseUrl(java.lang.String baseUrl)
For example given base URL "http://abc.com/v1":
Mono<Account> result = client.get() .uri("/accounts/{id}", 43) .exchange() .then(response -> response.bodyToMono(Account.class)); // Result: http://abc.com/v1/accounts/43 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class)); // Result: http://abc.com/v1/accounts?q=12
The base URL can be overridden with an absolute URI:
Mono<Account> result = client.get() .uri("http://xyz.com/path") .exchange() .then(response -> response.bodyToMono(Account.class)); // Result: http://xyz.com/path
Or partially overridden with a UriBuilder
:
Flux<Account> result = client.get() .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) .exchange() .then(response -> response.bodyToFlux(Account.class)); // Result: http://abc.com/v2/accounts?q=12
WebClient.Builder defaultUriVariables(java.util.Map<java.lang.String,?> defaultUriVariables)
Map
.defaultUriVariables
- the default values to usebaseUrl(String)
,
uriBuilderFactory(UriBuilderFactory)
WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
UriBuilderFactory
instance. This is
an alternative to and effectively overrides the following:
uriBuilderFactory
- the URI builder factory to usebaseUrl(String)
,
defaultUriVariables(Map)
WebClient.Builder defaultHeader(java.lang.String headerName, java.lang.String... headerValues)
headerName
- the header nameheaderValues
- the header valuesWebClient.Builder defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
HttpHeaders
methods.headersConsumer
- a function that consumes the HttpHeaders
WebClient.Builder defaultCookie(java.lang.String cookieName, java.lang.String... cookieValues)
cookieName
- the cookie namecookieValues
- the cookie valuesWebClient.Builder defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
MultiValueMap
methods.cookiesConsumer
- a function that consumes the cookies mapWebClient.Builder clientConnector(ClientHttpConnector connector)
ClientHttpConnector
to use.
By default an instance of
ReactorClientHttpConnector
is created if this is not set. However a
shared instance may be passed instead, e.g. for use with multiple
WebClient
's targeting different base URIs.
connector
- the connector to useexchangeStrategies(ExchangeStrategies)
,
exchangeFunction(ExchangeFunction)
WebClient.Builder filter(ExchangeFilterFunction filter)
filter
- the filter to be added to the chainWebClient.Builder filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
filtersConsumer
- a function that consumes the filter listWebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
ExchangeStrategies
to use.
By default ExchangeStrategies.withDefaults()
is used.
strategies
- the strategies to useclientConnector(ClientHttpConnector)
,
exchangeFunction(ExchangeFunction)
WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
ExchangeFunction
instance. This is
an alternative to and effectively overrides the following:
exchangeFunction
- the exchange function to useclientConnector(ClientHttpConnector)
,
exchangeStrategies(ExchangeStrategies)
WebClient.Builder clone()
WebClient.Builder
WebClient.Builder apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
builderConsumer
- the consumer to apply