Interface WebClientProvider
public interface WebClientProvider
Provider for
Client instances are typically cached allowing reuse of pooled connections if configured on the
WebClients 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 WebClientProviderstatic WebClientProvidercreate(String scheme, ClientHttpConnector connector) get(InetSocketAddress endpoint) Obtain theWebClientconfigured withdefault HTTP headersandConsumererror callback for a givenendpoint.Obtain theHttpHeadersto be used by default.Obtain theerror listenerto be used;Obtain thepathPrefixto be used.static WebClientProvidergetWebClientProvider(ClientConfiguration clientConfiguration) Creates aWebClientProviderfor the given configurationstatic WebClientProviderhttp()withDefaultHeaders(HttpHeaders headers) Create a new instance ofWebClientProviderapplying the given headers by default.withErrorListener(Consumer<Throwable> errorListener) Create a new instance ofWebClientProvidercalling the givenConsumeron error.withPathPrefix(String pathPrefix) Create a new instance ofWebClientProviderwhere HTTP requests are called with the given path prefix.withRequestConfigurer(Consumer<WebClient.RequestHeadersSpec<?>> requestConfigurer) Create a new instance ofWebClientProvidercalling the givenConsumerto 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 theWebClientconfigured withdefault HTTP headersandConsumererror callback for a givenendpoint. -
getDefaultHeaders
HttpHeaders getDefaultHeaders()Obtain theHttpHeadersto be used by default.- Returns:
- never null.
HttpHeaders.EMPTYby default.
-
getErrorListener
Obtain theerror listenerto be used;- Returns:
- never null.
-
getPathPrefix
Obtain thepathPrefixto be used.- Returns:
- the pathPrefix if set.
- Since:
- 4.0
-
withDefaultHeaders
Create a new instance ofWebClientProviderapplying the given headers by default.- Parameters:
headers- must not be null.- Returns:
- new instance of
WebClientProvider.
-
withErrorListener
Create a new instance ofWebClientProvidercalling the givenConsumeron error.- Parameters:
errorListener- must not be null.- Returns:
- new instance of
WebClientProvider.
-
withPathPrefix
Create a new instance ofWebClientProviderwhere 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 ofWebClientProvidercalling the givenConsumerto configure the requests of thisWebClient.- Parameters:
requestConfigurer- request configuration callback- Returns:
- new instance of
WebClientProvider - Since:
- 4.3
-
getWebClientProvider
Creates aWebClientProviderfor the given configuration- Parameters:
clientConfiguration- must not be null- Returns:
- the
WebClientProvider - Since:
- 4.3
-