|
|
|
@ -52,13 +52,17 @@ import org.springframework.web.util.UriBuilderFactory; |
|
|
|
* {@link #create(String)} or obtain a {@link WebClient#builder()} to create an |
|
|
|
* {@link #create(String)} or obtain a {@link WebClient#builder()} to create an |
|
|
|
* instance. |
|
|
|
* instance. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>For examples with a response body see |
|
|
|
* <p>For examples with a response body, see the Javadoc for: |
|
|
|
* {@link RequestHeadersSpec#retrieve() retrieve()} and |
|
|
|
* <ul> |
|
|
|
* {@link RequestHeadersSpec#exchange() exchange()}. |
|
|
|
* <li>{@link RequestHeadersSpec#retrieve() retrieve()} |
|
|
|
* For examples with a request body see |
|
|
|
* <li>{@link RequestHeadersSpec#exchange() exchange()} |
|
|
|
* {@link RequestBodySpec#body(Publisher, Class) body(Publisher,Class)}, |
|
|
|
* </ul> |
|
|
|
* {@link RequestBodySpec#syncBody(Object) syncBody(Object)}, and |
|
|
|
* For examples with a request body see: |
|
|
|
* {@link RequestBodySpec#body(BodyInserter) body(BodyInserter)}. |
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>{@link RequestBodySpec#body(Publisher, Class) body(Publisher,Class)} |
|
|
|
|
|
|
|
* <li>{@link RequestBodySpec#syncBody(Object) syncBody(Object)} |
|
|
|
|
|
|
|
* <li>{@link RequestBodySpec#body(BodyInserter) body(BodyInserter)} |
|
|
|
|
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
@ -67,57 +71,57 @@ import org.springframework.web.util.UriBuilderFactory; |
|
|
|
public interface WebClient { |
|
|
|
public interface WebClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP GET request. |
|
|
|
* Start building an HTTP GET request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestHeadersUriSpec<?> get(); |
|
|
|
RequestHeadersUriSpec<?> get(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP HEAD request. |
|
|
|
* Start building an HTTP HEAD request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestHeadersUriSpec<?> head(); |
|
|
|
RequestHeadersUriSpec<?> head(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP POST request. |
|
|
|
* Start building an HTTP POST request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestBodyUriSpec post(); |
|
|
|
RequestBodyUriSpec post(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP PUT request. |
|
|
|
* Start building an HTTP PUT request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestBodyUriSpec put(); |
|
|
|
RequestBodyUriSpec put(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP PATCH request. |
|
|
|
* Start building an HTTP PATCH request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestBodyUriSpec patch(); |
|
|
|
RequestBodyUriSpec patch(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP DELETE request. |
|
|
|
* Start building an HTTP DELETE request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestHeadersUriSpec<?> delete(); |
|
|
|
RequestHeadersUriSpec<?> delete(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare an HTTP OPTIONS request. |
|
|
|
* Start building an HTTP OPTIONS request. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestHeadersUriSpec<?> options(); |
|
|
|
RequestHeadersUriSpec<?> options(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Prepare a request for the specified {@code HttpMethod}. |
|
|
|
* Start building a request for the given {@code HttpMethod}. |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
* @return a spec for specifying the target URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
RequestBodyUriSpec method(HttpMethod method); |
|
|
|
RequestBodyUriSpec method(HttpMethod method); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a builder for a new {@code WebClient} with properties replicated |
|
|
|
* Return a builder to create a new {@code WebClient} whose settings are |
|
|
|
* from the current {@code WebClient} instance, but without affecting it. |
|
|
|
* replicated from the current {@code WebClient}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder mutate(); |
|
|
|
Builder mutate(); |
|
|
|
|
|
|
|
|
|
|
|
@ -125,7 +129,7 @@ public interface WebClient { |
|
|
|
// Static, factory methods
|
|
|
|
// Static, factory methods
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@code WebClient} with a Reactor Netty connector. |
|
|
|
* Create a new {@code WebClient} with Reactor Netty by default. |
|
|
|
* @see #create(String) |
|
|
|
* @see #create(String) |
|
|
|
* @see #builder() |
|
|
|
* @see #builder() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -134,7 +138,7 @@ public interface WebClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A variant of {@link #create()} that accepts a default base URL. For more |
|
|
|
* Variant of {@link #create()} that accepts a default base URL. For more |
|
|
|
* details see {@link Builder#baseUrl(String) Builder.baseUrl(String)}. |
|
|
|
* details see {@link Builder#baseUrl(String) Builder.baseUrl(String)}. |
|
|
|
* @param baseUrl the base URI for all requests |
|
|
|
* @param baseUrl the base URI for all requests |
|
|
|
* @see #builder() |
|
|
|
* @see #builder() |
|
|
|
@ -161,27 +165,25 @@ public interface WebClient { |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>For example given base URL "http://abc.com/v1": |
|
|
|
* <p>For example given base URL "http://abc.com/v1": |
|
|
|
* <p><pre class="code"> |
|
|
|
* <p><pre class="code"> |
|
|
|
* Mono<Account> result = client.get() |
|
|
|
* Mono<Account> result = client.get().uri("/accounts/{id}", 43) |
|
|
|
* .uri("/accounts/{id}", 43) |
|
|
|
* .retrieve() |
|
|
|
* .exchange() |
|
|
|
* .bodyToMono(Account.class); |
|
|
|
* .then(response -> response.bodyToMono(Account.class)); |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* // Result: http://abc.com/v1/accounts/43
|
|
|
|
* // Result: http://abc.com/v1/accounts/43
|
|
|
|
* |
|
|
|
* |
|
|
|
* Flux<Account> result = client.get() |
|
|
|
* Flux<Account> result = client.get() |
|
|
|
* .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) |
|
|
|
* .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) |
|
|
|
* .exchange() |
|
|
|
* .retrieve() |
|
|
|
* .then(response -> response.bodyToFlux(Account.class)); |
|
|
|
* .bodyToFlux(Account.class); |
|
|
|
* |
|
|
|
* |
|
|
|
* // Result: http://abc.com/v1/accounts?q=12
|
|
|
|
* // Result: http://abc.com/v1/accounts?q=12
|
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The base URL can be overridden with an absolute URI: |
|
|
|
* <p>The base URL can be overridden with an absolute URI: |
|
|
|
* <pre class="code"> |
|
|
|
* <pre class="code"> |
|
|
|
* Mono<Account> result = client.get() |
|
|
|
* Mono<Account> result = client.get().uri("http://xyz.com/path") |
|
|
|
* .uri("http://xyz.com/path") |
|
|
|
* .retrieve() |
|
|
|
* .exchange() |
|
|
|
* .bodyToMono(Account.class); |
|
|
|
* .then(response -> response.bodyToMono(Account.class)); |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* // Result: http://xyz.com/path
|
|
|
|
* // Result: http://xyz.com/path
|
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
@ -190,8 +192,8 @@ public interface WebClient { |
|
|
|
* <pre class="code"> |
|
|
|
* <pre class="code"> |
|
|
|
* Flux<Account> result = client.get() |
|
|
|
* Flux<Account> result = client.get() |
|
|
|
* .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) |
|
|
|
* .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) |
|
|
|
* .exchange() |
|
|
|
* .retrieve() |
|
|
|
* .then(response -> response.bodyToFlux(Account.class)); |
|
|
|
* .bodyToFlux(Account.class); |
|
|
|
* |
|
|
|
* |
|
|
|
* // Result: http://abc.com/v2/accounts?q=12
|
|
|
|
* // Result: http://abc.com/v2/accounts?q=12
|
|
|
|
* </pre> |
|
|
|
* </pre> |
|
|
|
@ -232,12 +234,9 @@ public interface WebClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manipulate the default headers with the given consumer. The |
|
|
|
* Manipulate the default headers with the given consumer. The |
|
|
|
* headers provided to the consumer are "live", so that the consumer can be used to |
|
|
|
* headers provided to the consumer are "live", so that the consumer |
|
|
|
* {@linkplain HttpHeaders#set(String, String) overwrite} existing header values, |
|
|
|
* can be used to overwrite or remove existing values. |
|
|
|
* {@linkplain HttpHeaders#remove(Object) remove} values, or use any of the other |
|
|
|
* @param headersConsumer the headers consumer |
|
|
|
* {@link HttpHeaders} methods. |
|
|
|
|
|
|
|
* @param headersConsumer a function that consumes the {@code HttpHeaders} |
|
|
|
|
|
|
|
* @return this builder |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer); |
|
|
|
Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer); |
|
|
|
|
|
|
|
|
|
|
|
@ -250,28 +249,12 @@ public interface WebClient { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manipulate the default cookies with the given consumer. The |
|
|
|
* Manipulate the default cookies with the given consumer. The |
|
|
|
* map provided to the consumer is "live", so that the consumer can be used to |
|
|
|
* cookies provided to the consumer are "live", so that the consumer |
|
|
|
* {@linkplain MultiValueMap#set(Object, Object) overwrite} existing header values, |
|
|
|
* can be used to overwrite or remove existing values. |
|
|
|
* {@linkplain MultiValueMap#remove(Object) remove} values, or use any of the other |
|
|
|
|
|
|
|
* {@link MultiValueMap} methods. |
|
|
|
|
|
|
|
* @param cookiesConsumer a function that consumes the cookies map |
|
|
|
* @param cookiesConsumer a function that consumes the cookies map |
|
|
|
* @return this builder |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer); |
|
|
|
Builder defaultCookies(Consumer<MultiValueMap<String, String>> cookiesConsumer); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Configure the {@link ClientHttpConnector} to use. |
|
|
|
|
|
|
|
* <p>By default an instance of |
|
|
|
|
|
|
|
* {@link org.springframework.http.client.reactive.ReactorClientHttpConnector |
|
|
|
|
|
|
|
* ReactorClientHttpConnector} is created if this is not set. However a |
|
|
|
|
|
|
|
* shared instance may be passed instead, e.g. for use with multiple |
|
|
|
|
|
|
|
* {@code WebClient}'s targeting different base URIs. |
|
|
|
|
|
|
|
* @param connector the connector to use |
|
|
|
|
|
|
|
* @see #exchangeStrategies(ExchangeStrategies) |
|
|
|
|
|
|
|
* @see #exchangeFunction(ExchangeFunction) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Builder clientConnector(ClientHttpConnector connector); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add the given filter to the filter chain. |
|
|
|
* Add the given filter to the filter chain. |
|
|
|
* @param filter the filter to be added to the chain |
|
|
|
* @param filter the filter to be added to the chain |
|
|
|
@ -279,8 +262,8 @@ public interface WebClient { |
|
|
|
Builder filter(ExchangeFilterFunction filter); |
|
|
|
Builder filter(ExchangeFilterFunction filter); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manipulate the filters with the given consumer. The |
|
|
|
* Manipulate the filters with the given consumer. The list provided to |
|
|
|
* list provided to the consumer is "live", so that the consumer can be used to remove |
|
|
|
* the consumer is "live", so that the consumer can be used to remove |
|
|
|
* filters, change ordering, etc. |
|
|
|
* filters, change ordering, etc. |
|
|
|
* @param filtersConsumer a function that consumes the filter list |
|
|
|
* @param filtersConsumer a function that consumes the filter list |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
@ -288,34 +271,40 @@ public interface WebClient { |
|
|
|
Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer); |
|
|
|
Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Provide a pre-configured {@link ExchangeFunction} instance. This is |
|
|
|
* Configure the {@link ClientHttpConnector} to use. This is useful for |
|
|
|
* an alternative to and effectively overrides the following: |
|
|
|
* plugging in and/or customizing options of the underlying HTTP client |
|
|
|
* <ul> |
|
|
|
* library (e.g. SSL). |
|
|
|
* <li>{@link #clientConnector(ClientHttpConnector)} |
|
|
|
* <p>By default this is set to |
|
|
|
* <li>{@link #exchangeStrategies(ExchangeStrategies)}. |
|
|
|
* {@link org.springframework.http.client.reactive.ReactorClientHttpConnector |
|
|
|
* </ul> |
|
|
|
* ReactorClientHttpConnector}. |
|
|
|
* @param exchangeFunction the exchange function to use |
|
|
|
* @param connector the connector to use |
|
|
|
* @see #clientConnector(ClientHttpConnector) |
|
|
|
|
|
|
|
* @see #exchangeStrategies(ExchangeStrategies) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder exchangeFunction(ExchangeFunction exchangeFunction); |
|
|
|
Builder clientConnector(ClientHttpConnector connector); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Configure the {@link ExchangeStrategies} to use. |
|
|
|
* Configure the {@link ExchangeStrategies} to use. |
|
|
|
* <p>By default {@link ExchangeStrategies#withDefaults()} is used. |
|
|
|
* <p>By default this is obtained from {@link ExchangeStrategies#withDefaults()}. |
|
|
|
* @param strategies the strategies to use |
|
|
|
* @param strategies the strategies to use |
|
|
|
* @see #clientConnector(ClientHttpConnector) |
|
|
|
|
|
|
|
* @see #exchangeFunction(ExchangeFunction) |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder exchangeStrategies(ExchangeStrategies strategies); |
|
|
|
Builder exchangeStrategies(ExchangeStrategies strategies); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Provide an {@link ExchangeFunction} pre-configured with |
|
|
|
|
|
|
|
* {@link ClientHttpConnector} and {@link ExchangeStrategies}. |
|
|
|
|
|
|
|
* <p>This is an alternative to, and effectively overrides |
|
|
|
|
|
|
|
* {@link #clientConnector}, and {@link #exchangeStrategies}. |
|
|
|
|
|
|
|
* @param exchangeFunction the exchange function to use |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Builder exchangeFunction(ExchangeFunction exchangeFunction); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Clone this {@code WebClient.Builder} |
|
|
|
* Clone this {@code WebClient.Builder} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder clone(); |
|
|
|
Builder clone(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Shortcut for pre-packaged customizations to WebTest builder. |
|
|
|
* Apply the given {@code Consumer} to this builder instance. |
|
|
|
|
|
|
|
* <p>This can be useful for applying pre-packaged customizations. |
|
|
|
* @param builderConsumer the consumer to apply |
|
|
|
* @param builderConsumer the consumer to apply |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Builder apply(Consumer<Builder> builderConsumer); |
|
|
|
Builder apply(Consumer<Builder> builderConsumer); |
|
|
|
@ -390,11 +379,9 @@ public interface WebClient { |
|
|
|
S cookie(String name, String value); |
|
|
|
S cookie(String name, String value); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manipulate the request's cookies with the given consumer. The |
|
|
|
* Manipulate the default cookies with the given consumer. The |
|
|
|
* map provided to the consumer is "live", so that the consumer can be used to |
|
|
|
* cookies provided to the consumer are "live", so that the consumer |
|
|
|
* {@linkplain MultiValueMap#set(Object, Object) overwrite} existing header values, |
|
|
|
* can be used to overwrite or remove existing values. |
|
|
|
* {@linkplain MultiValueMap#remove(Object) remove} values, or use any of the other |
|
|
|
|
|
|
|
* {@link MultiValueMap} methods. |
|
|
|
|
|
|
|
* @param cookiesConsumer a function that consumes the cookies map |
|
|
|
* @param cookiesConsumer a function that consumes the cookies map |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -425,11 +412,9 @@ public interface WebClient { |
|
|
|
S header(String headerName, String... headerValues); |
|
|
|
S header(String headerName, String... headerValues); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manipulate the request's headers with the given consumer. The |
|
|
|
* Manipulate the default headers with the given consumer. The |
|
|
|
* headers provided to the consumer are "live", so that the consumer can be used to |
|
|
|
* headers provided to the consumer are "live", so that the consumer |
|
|
|
* {@linkplain HttpHeaders#set(String, String) overwrite} existing header values, |
|
|
|
* can be used to overwrite or remove existing values. |
|
|
|
* {@linkplain HttpHeaders#remove(Object) remove} values, or use any of the other |
|
|
|
|
|
|
|
* {@link HttpHeaders} methods. |
|
|
|
|
|
|
|
* @param headersConsumer a function that consumes the {@code HttpHeaders} |
|
|
|
* @param headersConsumer a function that consumes the {@code HttpHeaders} |
|
|
|
* @return this builder |
|
|
|
* @return this builder |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|