From 25554d0b219ce5c15b9610b54c84b41d6dfadf03 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 2 Dec 2019 10:29:24 +0100 Subject: [PATCH] Revert "Allow ExchangeStrategies customizations in WebClient" This reverts commit 43e047c523fefa1fc876208efd6946ceb2e472a3. --- .../server/DefaultWebTestClientBuilder.java | 15 +------ .../web/reactive/server/WebTestClient.java | 30 ++------------ .../http/codec/ClientCodecConfigurer.java | 7 +--- .../http/codec/CodecConfigurer.java | 6 --- .../codec/support/BaseCodecConfigurer.java | 39 ++---------------- .../http/codec/support/BaseDefaultCodecs.java | 15 ------- .../support/ClientDefaultCodecsImpl.java | 32 +-------------- .../support/DefaultClientCodecConfigurer.java | 18 +-------- .../support/DefaultServerCodecConfigurer.java | 17 +------- .../support/ServerDefaultCodecsImpl.java | 10 ----- .../codec/support/CodecConfigurerTests.java | 8 ---- .../DefaultExchangeStrategiesBuilder.java | 28 ++++--------- .../client/DefaultWebClientBuilder.java | 38 ++---------------- .../function/client/ExchangeStrategies.java | 12 ------ .../reactive/function/client/WebClient.java | 28 +------------ .../client/ExchangeStrategiesTests.java | 11 ----- src/docs/asciidoc/web/webflux-webclient.adoc | 40 +++---------------- 17 files changed, 32 insertions(+), 322 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java index 4d5aeca17e..f314b4455d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -137,24 +137,11 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { } @Override - @Deprecated public WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies) { this.webClientBuilder.exchangeStrategies(strategies); return this; } - @Override - public WebTestClient.Builder exchangeStrategies(ExchangeStrategies.Builder strategies) { - this.webClientBuilder.exchangeStrategies(strategies); - return this; - } - - @Override - public WebTestClient.Builder exchangeStrategies(Consumer configurer) { - this.webClientBuilder.exchangeStrategies(configurer); - return this; - } - @Override public WebTestClient.Builder responseTimeout(Duration timeout) { this.responseTimeout = timeout; 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 254d0337fd..cc2e8ab96f 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 @@ -77,7 +77,6 @@ import org.springframework.web.util.UriBuilderFactory; * and Spring Kotlin extensions to perform integration tests on an embedded WebFlux server. * * @author Rossen Stoyanchev - * @author Brian Clozel * @since 5.0 * @see StatusAssertions * @see HeaderAssertions @@ -437,34 +436,11 @@ public interface WebTestClient { /** * Configure the {@link ExchangeStrategies} to use. - *

This is useful for changing the default settings, yet still allowing - * further customizations via {@link #exchangeStrategies(Consumer)}. - * By default {@link ExchangeStrategies#withDefaults()} is used. + *

By default {@link ExchangeStrategies#withDefaults()} is used. * @param strategies the strategies to use - * @deprecated as of 5.1 in favor of {@link #exchangeStrategies(ExchangeStrategies.Builder)} */ - @Deprecated Builder exchangeStrategies(ExchangeStrategies strategies); - /** - * Configure the {@link ExchangeStrategies.Builder} to use. - *

This is useful for changing the default settings, yet still allowing - * further customizations via {@link #exchangeStrategies(Consumer)}. - * By default {@link ExchangeStrategies#builder()} is used. - * @param strategies the strategies to use - * @since 5.1.12 - */ - Builder exchangeStrategies(ExchangeStrategies.Builder strategies); - - /** - * Customize the {@link ExchangeStrategies}. - *

Allows further customization on {@link ExchangeStrategies}, - * mutating them if they were {@link #exchangeStrategies(ExchangeStrategies) set}, - * or starting from {@link ExchangeStrategies#withDefaults() defaults}. - * @since 5.1.12 - */ - Builder exchangeStrategies(Consumer configurer); - /** * Max amount of time to wait for responses. *

By default 5 seconds. @@ -901,7 +877,7 @@ public interface WebTestClient { * @since 5.1 * @see #xpath(String, Map, Object...) */ - default XpathAssertions xpath(String expression, Object... args) { + default XpathAssertions xpath(String expression, Object... args){ return xpath(expression, null, args); } @@ -915,7 +891,7 @@ public interface WebTestClient { * @param args arguments to parameterize the expression * @since 5.1 */ - XpathAssertions xpath(String expression, @Nullable Map namespaces, Object... args); + XpathAssertions xpath(String expression, @Nullable Map namespaces, Object... args); /** * Assert the response body content with the given {@link Consumer}. 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 028d85af38..db31e97218 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,11 +63,6 @@ public interface ClientCodecConfigurer extends CodecConfigurer { @Override ClientDefaultCodecs defaultCodecs(); - /** - * Clone this {@link ClientCodecConfigurer}. - */ - @Override - ClientCodecConfigurer clone(); /** * Static factory method for a {@code ClientCodecConfigurer}. diff --git a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java index bd573d08ba..3d4c625b5d 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java @@ -87,12 +87,6 @@ public interface CodecConfigurer { */ List> getWriters(); - /** - * Clone this {@link CodecConfigurer}. - * @since 5.1.12 - */ - CodecConfigurer clone(); - /** * Customize or replace the HTTP message readers and writers registered by diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java index f67821f98b..e86ac954f9 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseCodecConfigurer.java @@ -34,14 +34,13 @@ import org.springframework.util.Assert; * client and server specific variants. * * @author Rossen Stoyanchev - * @author Brian Clozel * @since 5.0 */ class BaseCodecConfigurer implements CodecConfigurer { - protected final BaseDefaultCodecs defaultCodecs; + private final BaseDefaultCodecs defaultCodecs; - protected final DefaultCustomCodecs customCodecs; + private final DefaultCustomCodecs customCodecs = new DefaultCustomCodecs(); /** @@ -51,16 +50,6 @@ class BaseCodecConfigurer implements CodecConfigurer { BaseCodecConfigurer(BaseDefaultCodecs defaultCodecs) { Assert.notNull(defaultCodecs, "'defaultCodecs' is required"); this.defaultCodecs = defaultCodecs; - this.customCodecs = new DefaultCustomCodecs(); - } - - /** - * Constructor with another {@link BaseCodecConfigurer} to copy - * the configuration from. - */ - BaseCodecConfigurer(BaseCodecConfigurer other) { - this.defaultCodecs = other.cloneDefaultCodecs(); - this.customCodecs = new DefaultCustomCodecs(other.customCodecs); } @@ -98,17 +87,6 @@ class BaseCodecConfigurer implements CodecConfigurer { return getWritersInternal(false); } - - @Override - public CodecConfigurer clone() { - return new BaseCodecConfigurer(this); - } - - protected BaseDefaultCodecs cloneDefaultCodecs() { - return new BaseDefaultCodecs(this.defaultCodecs); - } - - /** * Internal method that returns the configured writers. * @param forMultipart whether to returns writers for general use ("false"), @@ -132,7 +110,7 @@ class BaseCodecConfigurer implements CodecConfigurer { /** * Default implementation of {@code CustomCodecs}. */ - protected static final class DefaultCustomCodecs implements CustomCodecs { + private static final class DefaultCustomCodecs implements CustomCodecs { private final List> typedReaders = new ArrayList<>(); @@ -143,16 +121,6 @@ class BaseCodecConfigurer implements CodecConfigurer { private final List> objectWriters = new ArrayList<>(); - DefaultCustomCodecs() { - } - - DefaultCustomCodecs(DefaultCustomCodecs other) { - other.typedReaders.addAll(this.typedReaders); - other.typedWriters.addAll(this.typedWriters); - other.objectReaders.addAll(this.objectReaders); - other.objectWriters.addAll(this.objectWriters); - } - @Override public void decoder(Decoder decoder) { reader(new DecoderHttpMessageReader<>(decoder)); @@ -175,6 +143,7 @@ class BaseCodecConfigurer implements CodecConfigurer { (canWriteObject ? this.objectWriters : this.typedWriters).add(writer); } + // Package private accessors... List> getTypedReaders() { diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java index 5cf59998af..f3034ad935 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java @@ -105,21 +105,6 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs { private boolean registerDefaults = true; - BaseDefaultCodecs() { - } - - protected BaseDefaultCodecs(BaseDefaultCodecs other) { - this.jackson2JsonDecoder = other.jackson2JsonDecoder; - this.jackson2JsonEncoder = other.jackson2JsonEncoder; - this.protobufDecoder = other.protobufDecoder; - this.protobufEncoder = other.protobufEncoder; - this.jaxb2Decoder = other.jaxb2Decoder; - this.jaxb2Encoder = other.jaxb2Encoder; - this.maxInMemorySize = other.maxInMemorySize; - this.enableLoggingRequestDetails = other.enableLoggingRequestDetails; - this.registerDefaults = other.registerDefaults; - } - @Override public void jackson2JsonDecoder(Decoder decoder) { this.jackson2JsonDecoder = decoder; diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java b/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java index e764cb9696..9f578b7320 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,17 +49,6 @@ class ClientDefaultCodecsImpl extends BaseDefaultCodecs implements ClientCodecCo private Supplier>> partWritersSupplier; - ClientDefaultCodecsImpl() { - } - - ClientDefaultCodecsImpl(ClientDefaultCodecsImpl other) { - super(other); - this.multipartCodecs = new DefaultMultipartCodecs(other.multipartCodecs); - this.sseDecoder = other.sseDecoder; - this.partWritersSupplier = other.partWritersSupplier; - } - - /** * Set a supplier for part writers to use when * {@link #multipartCodecs()} are not explicitly configured. @@ -84,14 +73,6 @@ class ClientDefaultCodecsImpl extends BaseDefaultCodecs implements ClientCodecCo this.sseDecoder = decoder; } - @Override - public ClientDefaultCodecsImpl clone() { - ClientDefaultCodecsImpl codecs = new ClientDefaultCodecsImpl(); - codecs.multipartCodecs = this.multipartCodecs; - codecs.sseDecoder = this.sseDecoder; - codecs.partWritersSupplier = this.partWritersSupplier; - return codecs; - } @Override protected void extendObjectReaders(List> objectReaders) { @@ -135,17 +116,6 @@ class ClientDefaultCodecsImpl extends BaseDefaultCodecs implements ClientCodecCo private final List> writers = new ArrayList<>(); - - DefaultMultipartCodecs() { - } - - DefaultMultipartCodecs(@Nullable DefaultMultipartCodecs other) { - if (other != null) { - this.writers.addAll(other.writers); - } - } - - @Override public ClientCodecConfigurer.MultipartCodecs encoder(Encoder encoder) { writer(new EncoderHttpMessageWriter<>(encoder)); diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/DefaultClientCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/support/DefaultClientCodecConfigurer.java index 737282eecd..9875ded1b9 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/DefaultClientCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/DefaultClientCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,30 +26,14 @@ import org.springframework.http.codec.ClientCodecConfigurer; */ public class DefaultClientCodecConfigurer extends BaseCodecConfigurer implements ClientCodecConfigurer { - public DefaultClientCodecConfigurer() { super(new ClientDefaultCodecsImpl()); ((ClientDefaultCodecsImpl) defaultCodecs()).setPartWritersSupplier(() -> getWritersInternal(true)); } - private DefaultClientCodecConfigurer(DefaultClientCodecConfigurer other) { - super(other); - } - - @Override public ClientDefaultCodecs defaultCodecs() { return (ClientDefaultCodecs) super.defaultCodecs(); } - @Override - public DefaultClientCodecConfigurer clone() { - return new DefaultClientCodecConfigurer(this); - } - - @Override - protected BaseDefaultCodecs cloneDefaultCodecs() { - return new ClientDefaultCodecsImpl((ClientDefaultCodecsImpl) defaultCodecs()); - } - } diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/DefaultServerCodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/support/DefaultServerCodecConfigurer.java index 661d45d666..2623d5a7f7 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/DefaultServerCodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/DefaultServerCodecConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,28 +26,13 @@ import org.springframework.http.codec.ServerCodecConfigurer; */ public class DefaultServerCodecConfigurer extends BaseCodecConfigurer implements ServerCodecConfigurer { - public DefaultServerCodecConfigurer() { super(new ServerDefaultCodecsImpl()); } - private DefaultServerCodecConfigurer(BaseCodecConfigurer other) { - super(other); - } - - @Override public ServerDefaultCodecs defaultCodecs() { return (ServerDefaultCodecs) super.defaultCodecs(); } - @Override - public DefaultServerCodecConfigurer clone() { - return new DefaultServerCodecConfigurer(this); - } - - @Override - protected BaseDefaultCodecs cloneDefaultCodecs() { - return new ServerDefaultCodecsImpl((ServerDefaultCodecsImpl) defaultCodecs()); - } } diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java b/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java index 1d997c3777..37e924cd7e 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java @@ -46,16 +46,6 @@ class ServerDefaultCodecsImpl extends BaseDefaultCodecs implements ServerCodecCo private Encoder sseEncoder; - ServerDefaultCodecsImpl() { - } - - ServerDefaultCodecsImpl(ServerDefaultCodecsImpl other) { - super(other); - this.multipartReader = other.multipartReader; - this.sseEncoder = other.sseEncoder; - } - - @Override public void multipartReader(HttpMessageReader reader) { this.multipartReader = reader; diff --git a/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java b/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java index 93d981c713..48e20a9074 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/support/CodecConfigurerTests.java @@ -267,14 +267,6 @@ public class CodecConfigurerTests { assertEncoderInstance(jaxb2Encoder); } - @Test - public void cloneConfigurer() { - CodecConfigurer clone = this.configurer.clone(); - this.configurer.registerDefaults(false); - assertEquals(0, this.configurer.getReaders().size()); - assertEquals(11, clone.getReaders().size()); - } - private Decoder getNextDecoder(List> readers) { HttpMessageReader reader = readers.get(this.index.getAndIncrement()); assertEquals(DecoderHttpMessageReader.class, reader.getClass()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultExchangeStrategiesBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultExchangeStrategiesBuilder.java index e39d4a5957..aa1523d9ac 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultExchangeStrategiesBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultExchangeStrategiesBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import org.springframework.http.codec.HttpMessageWriter; * Default implementation of {@link ExchangeStrategies.Builder}. * * @author Arjen Poutsma - * @author Brian Clozel * @since 5.0 */ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Builder { @@ -43,18 +42,13 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build } - private final ClientCodecConfigurer codecConfigurer; + private final ClientCodecConfigurer codecConfigurer = ClientCodecConfigurer.create(); public DefaultExchangeStrategiesBuilder() { - this.codecConfigurer = ClientCodecConfigurer.create(); this.codecConfigurer.registerDefaults(false); } - private DefaultExchangeStrategiesBuilder(DefaultExchangeStrategies other) { - this.codecConfigurer = other.codecConfigurer.clone(); - } - public void defaultConfiguration() { this.codecConfigurer.registerDefaults(true); @@ -68,33 +62,27 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build @Override public ExchangeStrategies build() { - return new DefaultExchangeStrategies(this.codecConfigurer); + return new DefaultExchangeStrategies( + this.codecConfigurer.getReaders(), this.codecConfigurer.getWriters()); } private static class DefaultExchangeStrategies implements ExchangeStrategies { - private final ClientCodecConfigurer codecConfigurer; - private final List> readers; private final List> writers; - public DefaultExchangeStrategies(ClientCodecConfigurer codecConfigurer) { - this.codecConfigurer = codecConfigurer; - this.readers = unmodifiableCopy(this.codecConfigurer.getReaders()); - this.writers = unmodifiableCopy(this.codecConfigurer.getWriters()); + + public DefaultExchangeStrategies(List> readers, List> writers) { + this.readers = unmodifiableCopy(readers); + this.writers = unmodifiableCopy(writers); } private static List unmodifiableCopy(List list) { return Collections.unmodifiableList(new ArrayList<>(list)); } - @Deprecated - @Override - public Builder mutate() { - return new DefaultExchangeStrategiesBuilder(this); - } @Override public List> messageReaders() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index 6f9a755a7f..c8796e91f7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -38,7 +38,6 @@ import org.springframework.web.util.UriBuilderFactory; * Default implementation of {@link WebClient.Builder}. * * @author Rossen Stoyanchev - * @author Brian Clozel * @since 5.0 */ final class DefaultWebClientBuilder implements WebClient.Builder { @@ -67,16 +66,14 @@ final class DefaultWebClientBuilder implements WebClient.Builder { @Nullable private ClientHttpConnector connector; - @Nullable - private ExchangeStrategies.Builder exchangeStrategies; - - private List> strategiesConfigurers; + private ExchangeStrategies exchangeStrategies; @Nullable private ExchangeFunction exchangeFunction; public DefaultWebClientBuilder() { + this.exchangeStrategies = ExchangeStrategies.withDefaults(); } public DefaultWebClientBuilder(DefaultWebClientBuilder other) { @@ -193,26 +190,12 @@ final class DefaultWebClientBuilder implements WebClient.Builder { } @Override - @Deprecated public WebClient.Builder exchangeStrategies(ExchangeStrategies strategies) { - Assert.notNull(strategies, "ExchangeStrategies must not be null"); - this.exchangeStrategies = strategies.mutate(); - return this; - } - - @Override - public WebClient.Builder exchangeStrategies(ExchangeStrategies.Builder strategies) { Assert.notNull(strategies, "ExchangeStrategies must not be null"); this.exchangeStrategies = strategies; return this; } - @Override - public WebClient.Builder exchangeStrategies(Consumer configurer) { - this.strategiesConfigurers.add(configurer); - return this; - } - @Override public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) { this.exchangeFunction = exchangeFunction; @@ -248,26 +231,13 @@ final class DefaultWebClientBuilder implements WebClient.Builder { return this.exchangeFunction; } else if (this.connector != null) { - return ExchangeFunctions.create(this.connector, initExchangeStrategies()); + return ExchangeFunctions.create(this.connector, this.exchangeStrategies); } else { - return ExchangeFunctions.create(new ReactorClientHttpConnector(), initExchangeStrategies()); + return ExchangeFunctions.create(new ReactorClientHttpConnector(), this.exchangeStrategies); } } - @SuppressWarnings("deprecation") - private ExchangeStrategies initExchangeStrategies() { - if (CollectionUtils.isEmpty(this.strategiesConfigurers)) { - return this.exchangeStrategies != null ? this.exchangeStrategies.build() : ExchangeStrategies.withDefaults(); - } - - ExchangeStrategies.Builder builder = - this.exchangeStrategies != null ? this.exchangeStrategies : ExchangeStrategies.builder(); - - this.strategiesConfigurers.forEach(configurer -> configurer.accept(builder)); - return builder.build(); - } - private UriBuilderFactory initUriBuilderFactory() { if (this.uriBuilderFactory != null) { return this.uriBuilderFactory; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java index dfc2e1e14d..804fbd9a42 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java @@ -47,18 +47,6 @@ public interface ExchangeStrategies { */ List> messageWriters(); - /** - * Return a builder to create a new {@link ExchangeStrategies} instance - * replicated from the current instance. - * @since 5.1.12 - * @deprecated APIs should consume {@link ExchangeStrategies} as final or accept an - * {@link ExchangeStrategies.Builder builder}. - */ - @Deprecated - default Builder mutate() { - throw new UnsupportedOperationException("This ExchangeStrategies implementation does not support mutation."); - } - // Static builder methods diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index 91a45fe064..8dc2a17c01 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -64,7 +64,6 @@ import org.springframework.web.util.UriBuilderFactory; * * @author Rossen Stoyanchev * @author Arjen Poutsma - * @author Brian Clozel * @since 5.0 */ public interface WebClient { @@ -289,35 +288,12 @@ public interface WebClient { Builder clientConnector(ClientHttpConnector connector); /** - * Provide the {@link ExchangeStrategies} to use. - *

This is useful for changing the default settings, yet still allowing - * further customizations via {@link #exchangeStrategies(Consumer)}. - * If not set, defaults are obtained from {@link ExchangeStrategies#withDefaults()}. + * Configure the {@link ExchangeStrategies} to use. + *

By default this is obtained from {@link ExchangeStrategies#withDefaults()}. * @param strategies the strategies to use - * @deprecated as of 5.1, in favor of {@link #exchangeStrategies(ExchangeStrategies.Builder)} */ - @Deprecated Builder exchangeStrategies(ExchangeStrategies strategies); - /** - * Provide the {@link ExchangeStrategies.Builder} to use. - *

This is useful for changing the default settings, yet still allowing - * further customizations via {@link #exchangeStrategies(Consumer)}. - * If not set, defaults are obtained from {@link ExchangeStrategies#builder()}. - * @param strategies the strategies to use - * @since 5.1.12 - */ - Builder exchangeStrategies(ExchangeStrategies.Builder strategies); - - /** - * Customize the {@link ExchangeStrategies}. - *

Allows further customization on {@link ExchangeStrategies}, - * mutating them if they were {@link #exchangeStrategies(ExchangeStrategies) set}, - * or starting from {@link ExchangeStrategies#withDefaults() defaults}. - * @since 5.1.12 - */ - Builder exchangeStrategies(Consumer configurer); - /** * Provide an {@link ExchangeFunction} pre-configured with * {@link ClientHttpConnector} and {@link ExchangeStrategies}. diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeStrategiesTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeStrategiesTests.java index 09f7cb24ef..b08662c8fb 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeStrategiesTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/ExchangeStrategiesTests.java @@ -39,15 +39,4 @@ public class ExchangeStrategiesTests { assertFalse(strategies.messageWriters().isEmpty()); } - @Test - @SuppressWarnings("deprecation") - public void mutate() { - ExchangeStrategies strategies = ExchangeStrategies.empty().build(); - assertTrue(strategies.messageReaders().isEmpty()); - assertTrue(strategies.messageWriters().isEmpty()); - ExchangeStrategies mutated = strategies.mutate().codecs(codecs -> codecs.registerDefaults(true)).build(); - assertFalse(mutated.messageReaders().isEmpty()); - assertFalse(mutated.messageWriters().isEmpty()); - } - } diff --git a/src/docs/asciidoc/web/webflux-webclient.adoc b/src/docs/asciidoc/web/webflux-webclient.adoc index 7f6523fa3b..20980df9dd 100644 --- a/src/docs/asciidoc/web/webflux-webclient.adoc +++ b/src/docs/asciidoc/web/webflux-webclient.adoc @@ -42,14 +42,14 @@ The following example configures < customizeCodecs = builder -> { - builder.codecs(configurer -> { - //... - }); - }; + ExchangeStrategies strategies = ExchangeStrategies.builder() + .codecs(configurer -> { + // ... + }) + .build(); WebClient client = WebClient.builder() - .exchangeStrategies(customizeCodecs) + .exchangeStrategies(strategies) .build(); ---- ==== @@ -73,35 +73,7 @@ modified copy without affecting the original instance, as the following example ---- ==== -[[webflux-client-builder-maxinmemorysize]] -=== MaxInMemorySize -Spring WebFlux configures by default a maximum size for buffering data in-memory when decoding -HTTP responses with the `WebClient`. This avoids application memory issues if the received -response is much larger than expected. - -You can configure a default value that might not be enough for your use case, and your application -can hit that limit with the following: - ----- -org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer ----- - -You can configure this limit on all default codecs with the following code sample: - -==== -[source,java,intent=0] -[subs="verbatim,quotes"] ----- - WebClient webClient = WebClient.builder() - .exchangeStrategies(configurer -> - configurer.codecs(codecs -> - codecs.defaultCodecs().maxInMemorySize(2 * 1024 * 1024) - ) - ) - .build(); ----- -==== [[webflux-client-builder-reactor]] === Reactor Netty