ServerCodecConfigurer as input in HandlerAdapter
The ServerCodecConfigurer is now passed all the way into the RequestMappingHandlerAdapter which automatically enables the same defaults even without the Java config and provides extra flexibility in passing message codec configuration for the future.
This commit is contained in:
@@ -68,8 +68,14 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
import static org.springframework.core.ResolvableType.forClassWithGenerics;
|
||||
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
|
||||
import static org.springframework.http.MediaType.APPLICATION_XML;
|
||||
import static org.springframework.http.MediaType.IMAGE_PNG;
|
||||
import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link WebFluxConfigurationSupport}.
|
||||
@@ -124,7 +130,7 @@ public class WebFluxConfigurationSupportTests {
|
||||
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
|
||||
List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
|
||||
List<HttpMessageReader<?>> readers = adapter.getMessageCodecConfigurer().getReaders();
|
||||
assertEquals(9, readers.size());
|
||||
|
||||
assertHasMessageReader(readers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
|
||||
@@ -158,7 +164,7 @@ public class WebFluxConfigurationSupportTests {
|
||||
RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
|
||||
List<HttpMessageReader<?>> messageReaders = adapter.getMessageReaders();
|
||||
List<HttpMessageReader<?>> messageReaders = adapter.getMessageCodecConfigurer().getReaders();
|
||||
assertEquals(2, messageReaders.size());
|
||||
|
||||
assertHasMessageReader(messageReaders, forClass(String.class), TEXT_PLAIN);
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -32,8 +31,7 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
||||
import org.springframework.core.codec.ByteArrayDecoder;
|
||||
import org.springframework.core.codec.ByteBufferDecoder;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.codec.DecoderHttpMessageReader;
|
||||
import org.springframework.http.codec.HttpMessageReader;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
@@ -67,20 +65,20 @@ public class ControllerMethodResolverTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
ArgumentResolverConfigurer configurer = new ArgumentResolverConfigurer();
|
||||
configurer.addCustomResolver(new CustomArgumentResolver());
|
||||
configurer.addCustomResolver(new CustomSyncArgumentResolver());
|
||||
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
|
||||
resolvers.addCustomResolver(new CustomArgumentResolver());
|
||||
resolvers.addCustomResolver(new CustomSyncArgumentResolver());
|
||||
|
||||
List<HttpMessageReader<?>> messageReaders = Arrays.asList(
|
||||
new DecoderHttpMessageReader<>(new ByteArrayDecoder()),
|
||||
new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||
ServerCodecConfigurer codecs = new ServerCodecConfigurer();
|
||||
codecs.customCodec().decoder(new ByteArrayDecoder());
|
||||
codecs.customCodec().decoder(new ByteBufferDecoder());
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
applicationContext.registerBean(TestControllerAdvice.class);
|
||||
applicationContext.refresh();
|
||||
|
||||
this.methodResolver = new ControllerMethodResolver(
|
||||
configurer, messageReaders, new ReactiveAdapterRegistry(), applicationContext);
|
||||
resolvers, codecs, new ReactiveAdapterRegistry(), applicationContext);
|
||||
|
||||
Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::handle).method();
|
||||
this.handlerMethod = new HandlerMethod(new TestController(), method);
|
||||
|
||||
Reference in New Issue
Block a user