Interface WebClientProvider
public interface WebClientProvider
Provider for
Client instances are typically cached allowing reuse of pooled connections if configured on the
WebClient
s using a pre-configured scheme
. This class returns WebClient
for a
specific endpoint
and encapsulates common configuration aspects of WebClient
so
that code using WebClient
is not required to apply further configuration to the actual client. Client instances are typically cached allowing reuse of pooled connections if configured on the
ClientHttpConnector
.- Since:
- 3.2
- Author:
- Christoph Strobl, Mark Paluch, Huw Ayling-Miller, Peter-Josef Meisch
-
Method Summary
Modifier and TypeMethodDescriptionstatic WebClientProvider
static WebClientProvider
create
(String scheme, ClientHttpConnector connector) get
(InetSocketAddress endpoint) Obtain theWebClient
configured withdefault HTTP headers
andConsumer
error callback for a givenendpoint
.Obtain theHttpHeaders
to be used by default.Obtain theerror listener
to be used;Obtain thepathPrefix
to be used.static WebClientProvider
getWebClientProvider
(ClientConfiguration clientConfiguration) Creates aWebClientProvider
for the given configurationstatic WebClientProvider
http()
withDefaultHeaders
(HttpHeaders headers) Create a new instance ofWebClientProvider
applying the given headers by default.withErrorListener
(Consumer<Throwable> errorListener) Create a new instance ofWebClientProvider
calling the givenConsumer
on error.withPathPrefix
(String pathPrefix) Create a new instance ofWebClientProvider
where HTTP requests are called with the given path prefix.withRequestConfigurer
(Consumer<WebClient.RequestHeadersSpec<?>> requestConfigurer) Create a new instance ofWebClientProvider
calling the givenConsumer
to configure the requests of thisWebClient
.withWebClientConfigurer
(Function<WebClient, WebClient> webClientConfigurer)
-
Method Details
-
http
- Returns:
- the resulting
WebClientProvider
.
-
create
- Parameters:
scheme
- protocol scheme such as http or https.- Returns:
- the resulting
WebClientProvider
.
-
create
- Parameters:
scheme
- protocol scheme such as http or https.connector
- the HTTP connector to use. Can be null.- Returns:
- the resulting
WebClientProvider
.
-
get
Obtain theWebClient
configured withdefault HTTP headers
andConsumer
error callback for a givenendpoint
. -
getDefaultHeaders
HttpHeaders getDefaultHeaders()Obtain theHttpHeaders
to be used by default.- Returns:
- never null.
HttpHeaders.EMPTY
by default.
-
getErrorListener
Obtain theerror listener
to be used;- Returns:
- never null.
-
getPathPrefix
Obtain thepathPrefix
to be used.- Returns:
- the pathPrefix if set.
- Since:
- 4.0
-
withDefaultHeaders
Create a new instance ofWebClientProvider
applying the given headers by default.- Parameters:
headers
- must not be null.- Returns:
- new instance of
WebClientProvider
.
-
withErrorListener
Create a new instance ofWebClientProvider
calling the givenConsumer
on error.- Parameters:
errorListener
- must not be null.- Returns:
- new instance of
WebClientProvider
.
-
withPathPrefix
Create a new instance ofWebClientProvider
where HTTP requests are called with the given path prefix.- Parameters:
pathPrefix
- Path prefix to add to requests- Returns:
- new instance of
WebClientProvider
- Since:
- 4.0
-
withWebClientConfigurer
- Parameters:
webClientConfigurer
- configuration function- Returns:
- new instance of
WebClientProvider
- Since:
- 4.0
-
withRequestConfigurer
WebClientProvider withRequestConfigurer(Consumer<WebClient.RequestHeadersSpec<?>> requestConfigurer) Create a new instance ofWebClientProvider
calling the givenConsumer
to configure the requests of thisWebClient
.- Parameters:
requestConfigurer
- request configuration callback- Returns:
- new instance of
WebClientProvider
- Since:
- 4.3
-
getWebClientProvider
Creates aWebClientProvider
for the given configuration- Parameters:
clientConfiguration
- must not be null- Returns:
- the
WebClientProvider
- Since:
- 4.3
-