Consistently use CodecConfigurer for configuration
This commit changes the `ExchangeStrategies` and `HandlerStrategies` interfaces to consistently use the `CodecConfigurer` (and sub-interfaces) for configuring codecs on the server and on the client. Issue: SPR-15682
This commit is contained in:
parent
018cc45483
commit
52148a10b7
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
|||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.http.codec.ClientCodecConfigurer;
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.util.Assert;
|
||||
|
|
@ -47,18 +46,9 @@ class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Builder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ExchangeStrategies.Builder defaultCodecs(
|
||||
Consumer<ClientCodecConfigurer.ClientDefaultCodecs> consumer) {
|
||||
public ExchangeStrategies.Builder codecs(Consumer<ClientCodecConfigurer> consumer) {
|
||||
Assert.notNull(consumer, "'consumer' must not be null");
|
||||
consumer.accept(this.codecConfigurer.defaultCodecs());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExchangeStrategies.Builder customCodecs(
|
||||
Consumer<CodecConfigurer.CustomCodecs> consumer) {
|
||||
Assert.notNull(consumer, "'consumer' must not be null");
|
||||
consumer.accept(this.codecConfigurer.customCodecs());
|
||||
consumer.accept(this.codecConfigurer);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import java.util.List;
|
|||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.http.codec.ClientCodecConfigurer;
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
|
||||
|
|
@ -88,20 +87,11 @@ public interface ExchangeStrategies {
|
|||
interface Builder {
|
||||
|
||||
/**
|
||||
* Customize the list of default client-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the default codecs
|
||||
* Customize the list of client-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the codecs
|
||||
* @return this builder
|
||||
* @see #customCodecs(Consumer)
|
||||
*/
|
||||
Builder defaultCodecs(Consumer<ClientCodecConfigurer.ClientDefaultCodecs> consumer);
|
||||
|
||||
/**
|
||||
* Customize the list of custom client-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the custom codecs
|
||||
* @return this builder
|
||||
* @see #defaultCodecs(Consumer)
|
||||
*/
|
||||
Builder customCodecs(Consumer<CodecConfigurer.CustomCodecs> consumer);
|
||||
Builder codecs(Consumer<ClientCodecConfigurer> consumer);
|
||||
|
||||
/**
|
||||
* Builds the {@link ExchangeStrategies}.
|
||||
|
|
|
|||
|
|
@ -21,17 +21,16 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.i18n.LocaleContextResolver;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
|
||||
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
||||
import org.springframework.web.server.i18n.LocaleContextResolver;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link HandlerStrategies.Builder}.
|
||||
|
|
@ -63,18 +62,9 @@ class DefaultHandlerStrategiesBuilder implements HandlerStrategies.Builder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HandlerStrategies.Builder defaultCodecs(
|
||||
Consumer<ServerCodecConfigurer.ServerDefaultCodecs> consumer) {
|
||||
public HandlerStrategies.Builder codecs(Consumer<ServerCodecConfigurer> consumer) {
|
||||
Assert.notNull(consumer, "'consumer' must not be null");
|
||||
consumer.accept(this.codecConfigurer.defaultCodecs());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerStrategies.Builder customCodecs(
|
||||
Consumer<CodecConfigurer.CustomCodecs> consumer) {
|
||||
Assert.notNull(consumer, "'consumer' must not be null");
|
||||
consumer.accept(this.codecConfigurer.customCodecs());
|
||||
consumer.accept(this.codecConfigurer);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,14 +19,13 @@ package org.springframework.web.reactive.function.server;
|
|||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.http.codec.CodecConfigurer;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.i18n.LocaleContextResolver;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.i18n.LocaleContextResolver;
|
||||
|
||||
/**
|
||||
* Defines the strategies to be used for processing {@link HandlerFunction}s. An instance of
|
||||
|
|
@ -118,20 +117,11 @@ public interface HandlerStrategies {
|
|||
interface Builder {
|
||||
|
||||
/**
|
||||
* Customize the list of default server-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the default codecs
|
||||
* Customize the list of server-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the codecs
|
||||
* @return this builder
|
||||
* @see #customCodecs(Consumer)
|
||||
*/
|
||||
Builder defaultCodecs(Consumer<ServerCodecConfigurer.ServerDefaultCodecs> consumer);
|
||||
|
||||
/**
|
||||
* Customize the list of custom server-side HTTP message readers and writers.
|
||||
* @param consumer the consumer to customize the custom codecs
|
||||
* @return this builder
|
||||
* @see #defaultCodecs(Consumer)
|
||||
*/
|
||||
Builder customCodecs(Consumer<CodecConfigurer.CustomCodecs> consumer);
|
||||
Builder codecs(Consumer<ServerCodecConfigurer> consumer);
|
||||
|
||||
/**
|
||||
* Add the given view resolver to this builder.
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ import org.springframework.web.reactive.function.BodyInserter;
|
|||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
|
|
@ -203,10 +204,6 @@ public class DefaultEntityResponseBuilderTests {
|
|||
return Collections.<ViewResolver>emptyList();
|
||||
}
|
||||
};
|
||||
HandlerStrategies strategies = HandlerStrategies.empty()
|
||||
.customCodecs(configurer -> configurer.writer(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes())))
|
||||
.build();
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith(response -> {
|
||||
StepVerifier.create(response.entity())
|
||||
|
|
|
|||
Loading…
Reference in New Issue