diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 3f283003f14..ff76e02e04d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -443,8 +443,8 @@ public interface WebTestClient { Builder responseTimeout(Duration timeout); /** - * Shortcut for pre-packaged customizations to WebTestClient builder. - * @param configurer the configurer to apply + * Apply the given {@code Consumer} to this builder instance. + *
This can be useful for applying pre-packaged customizations. */ Builder apply(WebTestClientConfigurer configurer); diff --git a/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java index 19fa80c6a0a..c16d5908435 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java @@ -23,6 +23,33 @@ import org.springframework.core.codec.Encoder; * Extension of {@link CodecConfigurer} for HTTP message reader and writer * options relevant on the client side. * + *
HTTP message readers for the following are registered by default: + *
HTTP message writers registered by default: + *
HTTP message readers for the following are registered by default: + *
HTTP message writers registered by default: + *
To create an instance, see the static methods {@link #withDefaults()},
+ * {@link #builder()}, and {@link #empty()}.
*
* @author Brian Clozel
* @author Arjen Poutsma
@@ -36,13 +36,13 @@ import org.springframework.http.codec.HttpMessageWriter;
public interface ExchangeStrategies {
/**
- * Return the {@link HttpMessageReader}s to be used for request body conversion.
+ * Return {@link HttpMessageReader}s to read and decode the response body with.
* @return the stream of message readers
*/
List For examples with a response body see
- * {@link RequestHeadersSpec#retrieve() retrieve()} and
- * {@link RequestHeadersSpec#exchange() exchange()}.
- * For examples with a request body see
- * {@link RequestBodySpec#body(Publisher, Class) body(Publisher,Class)},
- * {@link RequestBodySpec#syncBody(Object) syncBody(Object)}, and
- * {@link RequestBodySpec#body(BodyInserter) body(BodyInserter)}.
+ * For examples with a response body, see the Javadoc for:
+ * For example given base URL "http://abc.com/v1":
* The base URL can be overridden with an absolute URI:
* 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.
* @param filter the filter to be added to the chain
@@ -279,8 +262,8 @@ public interface WebClient {
Builder filter(ExchangeFilterFunction filter);
/**
- * Manipulate the filters with the given consumer. The
- * list provided to the consumer is "live", so that the consumer can be used to remove
+ * Manipulate the filters with the given consumer. The list provided to
+ * the consumer is "live", so that the consumer can be used to remove
* filters, change ordering, etc.
* @param filtersConsumer a function that consumes the filter list
* @return this builder
@@ -288,34 +271,40 @@ public interface WebClient {
Builder filters(Consumer By default this is set to
+ * {@link org.springframework.http.client.reactive.ReactorClientHttpConnector
+ * ReactorClientHttpConnector}.
+ * @param connector the connector to use
*/
- Builder exchangeFunction(ExchangeFunction exchangeFunction);
+ Builder clientConnector(ClientHttpConnector connector);
/**
* Configure the {@link ExchangeStrategies} to use.
- * By default {@link ExchangeStrategies#withDefaults()} is used.
+ * By default this is obtained from {@link ExchangeStrategies#withDefaults()}.
* @param strategies the strategies to use
- * @see #clientConnector(ClientHttpConnector)
- * @see #exchangeFunction(ExchangeFunction)
*/
Builder exchangeStrategies(ExchangeStrategies strategies);
+ /**
+ * Provide an {@link ExchangeFunction} pre-configured with
+ * {@link ClientHttpConnector} and {@link ExchangeStrategies}.
+ * 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}
*/
Builder clone();
/**
- * Shortcut for pre-packaged customizations to WebTest builder.
+ * Apply the given {@code Consumer} to this builder instance.
+ * This can be useful for applying pre-packaged customizations.
* @param builderConsumer the consumer to apply
*/
Builder apply(Consumer
+ *
+ * For examples with a request body see:
+ *
+ *
*
* @author Rossen Stoyanchev
* @author Arjen Poutsma
@@ -67,57 +71,57 @@ import org.springframework.web.util.UriBuilderFactory;
public interface WebClient {
/**
- * Prepare an HTTP GET request.
+ * Start building an HTTP GET request.
* @return a spec for specifying the target URL
*/
RequestHeadersUriSpec> get();
/**
- * Prepare an HTTP HEAD request.
+ * Start building an HTTP HEAD request.
* @return a spec for specifying the target URL
*/
RequestHeadersUriSpec> head();
/**
- * Prepare an HTTP POST request.
+ * Start building an HTTP POST request.
* @return a spec for specifying the target URL
*/
RequestBodyUriSpec post();
/**
- * Prepare an HTTP PUT request.
+ * Start building an HTTP PUT request.
* @return a spec for specifying the target URL
*/
RequestBodyUriSpec put();
/**
- * Prepare an HTTP PATCH request.
+ * Start building an HTTP PATCH request.
* @return a spec for specifying the target URL
*/
RequestBodyUriSpec patch();
/**
- * Prepare an HTTP DELETE request.
+ * Start building an HTTP DELETE request.
* @return a spec for specifying the target URL
*/
RequestHeadersUriSpec> delete();
/**
- * Prepare an HTTP OPTIONS request.
+ * Start building an HTTP OPTIONS request.
* @return a spec for specifying the target URL
*/
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
*/
RequestBodyUriSpec method(HttpMethod method);
/**
- * Return a builder for a new {@code WebClient} with properties replicated
- * from the current {@code WebClient} instance, but without affecting it.
+ * Return a builder to create a new {@code WebClient} whose settings are
+ * replicated from the current {@code WebClient}.
*/
Builder mutate();
@@ -125,7 +129,7 @@ public interface WebClient {
// 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 #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)}.
* @param baseUrl the base URI for all requests
* @see #builder()
@@ -161,27 +165,25 @@ public interface WebClient {
*
*
- * Mono<Account> result = client.get()
- * .uri("/accounts/{id}", 43)
- * .exchange()
- * .then(response -> response.bodyToMono(Account.class));
+ * Mono<Account> result = client.get().uri("/accounts/{id}", 43)
+ * .retrieve()
+ * .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));
+ * .retrieve()
+ * .bodyToFlux(Account.class);
*
* // Result: http://abc.com/v1/accounts?q=12
*
*
*
- * Mono<Account> result = client.get()
- * .uri("http://xyz.com/path")
- * .exchange()
- * .then(response -> response.bodyToMono(Account.class));
+ * Mono<Account> result = client.get().uri("http://xyz.com/path")
+ * .retrieve()
+ * .bodyToMono(Account.class);
*
* // Result: http://xyz.com/path
*
@@ -190,8 +192,8 @@ public interface WebClient {
*
* Flux<Account> result = client.get()
* .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build())
- * .exchange()
- * .then(response -> response.bodyToFlux(Account.class));
+ * .retrieve()
+ * .bodyToFlux(Account.class);
*
* // Result: http://abc.com/v2/accounts?q=12
*
@@ -232,12 +234,9 @@ public interface WebClient {
/**
* Manipulate the default headers with the given consumer. The
- * headers provided to the consumer are "live", so that the consumer can be used to
- * {@linkplain HttpHeaders#set(String, String) overwrite} existing header 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}
- * @return this builder
+ * headers provided to the consumer are "live", so that the consumer
+ * can be used to overwrite or remove existing values.
+ * @param headersConsumer the headers consumer
*/
Builder defaultHeaders(Consumer> filtersConsumer);
/**
- * Provide a pre-configured {@link ExchangeFunction} instance. This is
- * an alternative to and effectively overrides the following:
- *
- *
- * @param exchangeFunction the exchange function to use
- * @see #clientConnector(ClientHttpConnector)
- * @see #exchangeStrategies(ExchangeStrategies)
+ * Configure the {@link ClientHttpConnector} to use. This is useful for
+ * plugging in and/or customizing options of the underlying HTTP client
+ * library (e.g. SSL).
+ *