Expose ServerCodecConfigurer as a bean
With this commit, ServerCodecConfigurer is now exposed as a bean in order to be provided to DefaultServerWebExchange via WebHttpHandlerBuilder and HttpWebHandlerAdapter. This allows DefaultServerWebExchange to get configured codecs for reading form or multipart requests. Issue: SPR-14546
This commit is contained in:
@@ -81,8 +81,6 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
|
||||
private PathMatchConfigurer pathMatchConfigurer;
|
||||
|
||||
private ServerCodecConfigurer messageCodecsConfigurer;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
|
||||
@@ -242,7 +240,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
@Bean
|
||||
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
|
||||
RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter();
|
||||
adapter.setMessageCodecConfigurer(getMessageCodecsConfigurer());
|
||||
adapter.setMessageCodecConfigurer(serverCodecConfigurer());
|
||||
adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
|
||||
adapter.setReactiveAdapterRegistry(webFluxAdapterRegistry());
|
||||
|
||||
@@ -267,16 +265,15 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method to access the configurer for HTTP message readers and writers.
|
||||
* Return the configurer for HTTP message readers and writers.
|
||||
* <p>Use {@link #configureHttpMessageCodecs(ServerCodecConfigurer)} to
|
||||
* configure the readers and writers.
|
||||
*/
|
||||
protected final ServerCodecConfigurer getMessageCodecsConfigurer() {
|
||||
if (this.messageCodecsConfigurer == null) {
|
||||
this.messageCodecsConfigurer = ServerCodecConfigurer.create();
|
||||
configureHttpMessageCodecs(this.getMessageCodecsConfigurer());
|
||||
}
|
||||
return this.messageCodecsConfigurer;
|
||||
@Bean
|
||||
public ServerCodecConfigurer serverCodecConfigurer() {
|
||||
ServerCodecConfigurer serverCodecConfigurer = ServerCodecConfigurer.create();
|
||||
configureHttpMessageCodecs(serverCodecConfigurer);
|
||||
return serverCodecConfigurer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,13 +369,13 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware {
|
||||
|
||||
@Bean
|
||||
public ResponseEntityResultHandler responseEntityResultHandler() {
|
||||
return new ResponseEntityResultHandler(getMessageCodecsConfigurer().getWriters(),
|
||||
return new ResponseEntityResultHandler(serverCodecConfigurer().getWriters(),
|
||||
webFluxContentTypeResolver(), webFluxAdapterRegistry());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResponseBodyResultHandler responseBodyResultHandler() {
|
||||
return new ResponseBodyResultHandler(getMessageCodecsConfigurer().getWriters(),
|
||||
return new ResponseBodyResultHandler(serverCodecConfigurer().getWriters(),
|
||||
webFluxContentTypeResolver(), webFluxAdapterRegistry());
|
||||
}
|
||||
|
||||
|
||||
@@ -125,13 +125,13 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
|
||||
new HandlerStrategies() {
|
||||
@Override
|
||||
public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
|
||||
return () -> getMessageCodecsConfigurer().getReaders().stream()
|
||||
return () -> serverCodecConfigurer().getReaders().stream()
|
||||
.map(reader -> (HttpMessageReader<?>) reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<Stream<HttpMessageWriter<?>>> messageWriters() {
|
||||
return () -> getMessageCodecsConfigurer().getWriters().stream()
|
||||
return () -> serverCodecConfigurer().getWriters().stream()
|
||||
.map(writer -> (HttpMessageWriter<?>) writer);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
|
||||
@@ -81,7 +82,7 @@ public class SessionAttributeMethodArgumentResolverTests {
|
||||
WebSessionManager sessionManager = new MockWebSessionManager(this.session);
|
||||
|
||||
ServerHttpRequest request = MockServerHttpRequest.get("/").build();
|
||||
this.exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse(), sessionManager);
|
||||
this.exchange = new DefaultServerWebExchange(request, new MockServerHttpResponse(), sessionManager, ServerCodecConfigurer.create());
|
||||
|
||||
this.handleMethod = ReflectionUtils.findMethod(getClass(), "handleWithSessionAttribute", (Class<?>[]) null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user