From 39f8bd663ee944d92ecd8b1e33b5315807419c94 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 5 May 2017 23:19:08 +0200 Subject: [PATCH] Polishing --- .../http/codec/DecoderHttpMessageReader.java | 8 ++----- .../http/codec/EncoderHttpMessageWriter.java | 17 ++++++------- .../http/codec/FormHttpMessageReader.java | 9 ++++--- .../http/codec/FormHttpMessageWriter.java | 4 ++-- .../http/codec/HttpMessageDecoder.java | 1 - .../http/codec/HttpMessageEncoder.java | 2 -- .../http/codec/HttpMessageReader.java | 24 ++++++++----------- .../http/codec/HttpMessageWriter.java | 1 - .../http/codec/xml/JaxbContextContainer.java | 10 ++++---- .../client/HttpMessageConverterExtractor.java | 8 +++---- ...gJackson2XmlHttpMessageConverterTests.java | 6 ++--- .../support/ServerResponseResultHandler.java | 14 ++++++----- .../result/HandlerResultHandlerSupport.java | 11 ++++----- ...AbstractMessageReaderArgumentResolver.java | 14 +++++------ .../AbstractMessageWriterResultHandler.java | 16 ++++--------- .../result/HandlerResultHandlerTests.java | 23 +++++------------- ...stractMessageConverterMethodProcessor.java | 6 ++--- 17 files changed, 69 insertions(+), 105 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java index 159eb503af..00caae30fc 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java @@ -81,17 +81,13 @@ public class DecoderHttpMessageReader implements HttpMessageReader { } @Override - public Flux read(ResolvableType elementType, ReactiveHttpInputMessage message, - Map hints) { - + public Flux read(ResolvableType elementType, ReactiveHttpInputMessage message, Map hints) { MediaType contentType = getContentType(message); return this.decoder.decode(message.getBody(), elementType, contentType, hints); } @Override - public Mono readMono(ResolvableType elementType, ReactiveHttpInputMessage message, - Map hints) { - + public Mono readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map hints) { MediaType contentType = getContentType(message); return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java index 4a1229e899..34b35896e4 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java @@ -28,7 +28,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.server.reactive.ServerHttpRequest; @@ -92,17 +91,15 @@ public class EncoderHttpMessageWriter implements HttpMessageWriter { @Override public Mono write(Publisher inputStream, ResolvableType elementType, - MediaType mediaType, ReactiveHttpOutputMessage message, - Map hints) { + MediaType mediaType, ReactiveHttpOutputMessage message, Map hints) { MediaType contentType = updateContentType(message, mediaType); - DataBufferFactory factory = message.bufferFactory(); - Flux body = this.encoder.encode(inputStream, factory, elementType, contentType, hints); + Flux body = this.encoder.encode( + inputStream, message.bufferFactory(), elementType, contentType, hints); - return isStreamingMediaType(contentType) ? - message.writeAndFlushWith(body.map(Flux::just)) : - message.writeWith(body); + return (isStreamingMediaType(contentType) ? + message.writeAndFlushWith(body.map(Flux::just)) : message.writeWith(body)); } private MediaType updateContentType(ReactiveHttpOutputMessage message, MediaType mediaType) { @@ -120,8 +117,8 @@ public class EncoderHttpMessageWriter implements HttpMessageWriter { } private static boolean useFallback(MediaType main, MediaType fallback) { - return main == null || !main.isConcrete() || - main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null; + return (main == null || !main.isConcrete() || + main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null); } private static MediaType addDefaultCharset(MediaType main, MediaType defaultType) { diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java index c66690b446..dcaf807141 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -53,7 +53,6 @@ public class FormHttpMessageReader implements HttpMessageReaderBy default this is set to "UTF-8". */ public void setDefaultCharset(Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); + Assert.notNull(charset, "Charset must not be null"); this.defaultCharset = charset; } @@ -77,8 +76,8 @@ public class FormHttpMessageReader implements HttpMessageReaderBy default this is set to "UTF-8". */ public void setDefaultCharset(Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); + Assert.notNull(charset, "Charset must not be null"); this.defaultCharset = charset; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageDecoder.java index 43542af563..35beee2a45 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageDecoder.java @@ -35,7 +35,6 @@ public interface HttpMessageDecoder extends Decoder { /** * Get decoding hints based on the server request or annotations on the * target controller method parameter. - * * @param actualType the actual target type to decode to, possibly a reactive * wrapper and sourced from {@link org.springframework.core.MethodParameter}, * i.e. providing access to method parameter annotations. diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java index bb292acda4..7bdffcbc43 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java @@ -26,7 +26,6 @@ import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; - /** * Extension of {@code Encoder} exposing extra methods relevant in the context * of HTTP request or response body encoding. @@ -45,7 +44,6 @@ public interface HttpMessageEncoder extends Encoder { /** * Get decoding hints based on the server request or annotations on the * target controller method parameter. - * * @param actualType the actual source type to encode, possibly a reactive * wrapper and sourced from {@link org.springframework.core.MethodParameter}, * i.e. providing access to method annotations. diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java index 0fbc036deb..c087de0bf0 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java @@ -57,7 +57,6 @@ public interface HttpMessageReader { /** * Read from the input message and encode to a stream of objects. - * * @param elementType the type of objects in the stream which must have been * previously checked via {@link #canRead(ResolvableType, MediaType)} * @param message the message to read from @@ -68,7 +67,6 @@ public interface HttpMessageReader { /** * Read from the input message and encode to a single object. - * * @param elementType the type of objects in the stream which must have been * previously checked via {@link #canRead(ResolvableType, MediaType)} * @param message the message to read from @@ -79,12 +77,11 @@ public interface HttpMessageReader { /** * Server-side only alternative to - * {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)} with - * additional context available. - * - * @param actualType the actual type of the target method parameter; for - * annotated controllers, the {@link MethodParameter} can be accessed via - * {@link ResolvableType#getSource()}. + * {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)} + * with additional context available. + * @param actualType the actual type of the target method parameter; + * for annotated controllers, the {@link MethodParameter} can be accessed + * via {@link ResolvableType#getSource()}. * @param elementType the type of Objects in the output stream * @param request the current request * @param response the current response @@ -99,12 +96,11 @@ public interface HttpMessageReader { /** * Server-side only alternative to - * {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)} with - * additional, context available. - * - * @param actualType the actual type of the target method parameter; for - * annotated controllers, the {@link MethodParameter} can be accessed via - * {@link ResolvableType#getSource()}. + * {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)} + * with additional, context available. + * @param actualType the actual type of the target method parameter; + * for annotated controllers, the {@link MethodParameter} can be accessed + * via {@link ResolvableType#getSource()}. * @param elementType the type of Objects in the output stream * @param request the current request * @param response the current response diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java index 848341cd3a..1a04e91136 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java @@ -69,7 +69,6 @@ public interface HttpMessageWriter { Mono write(Publisher inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map hints); - /** * Server-side only alternative to * {@link #write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)} diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java b/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java index 7d379987c8..163ba8478b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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,14 +26,14 @@ import javax.xml.bind.Unmarshaller; import org.springframework.util.Assert; /** + * Holder for {@link JAXBContext} isntances. + * * @author Arjen Poutsma * @since 5.0 */ final class JaxbContextContainer { - - private final ConcurrentMap, JAXBContext> jaxbContexts = - new ConcurrentHashMap<>(64); + private final ConcurrentMap, JAXBContext> jaxbContexts = new ConcurrentHashMap<>(64); public Marshaller createMarshaller(Class clazz) throws JAXBException { @@ -47,7 +47,7 @@ final class JaxbContextContainer { } private JAXBContext getJaxbContext(Class clazz) throws JAXBException { - Assert.notNull(clazz, "'clazz' must not be null"); + Assert.notNull(clazz, "Class must not be null"); JAXBContext jaxbContext = this.jaxbContexts.get(clazz); if (jaxbContext == null) { jaxbContext = JAXBContext.newInstance(clazz); diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java index 5b8cb3bac4..837796aee6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -109,9 +109,9 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { } } } - catch(IOException | HttpMessageNotReadableException exc) { - throw new RestClientException("Error while extracting response for type [" - + this.responseType + "] and content type [" + contentType + "]", exc); + catch (IOException | HttpMessageNotReadableException ex) { + throw new RestClientException("Error while extracting response for type [" + + this.responseType + "] and content type [" + contentType + "]", ex); } throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " + diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java index f568fc0cba..7797231062 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverterTests.java @@ -102,7 +102,7 @@ public class MappingJackson2XmlHttpMessageConverterTests { outputMessage.getHeaders().getContentType()); } - @Test(expected = HttpMessageNotReadableException.class) + @Test(expected = IOException.class) public void readInvalidXml() throws IOException { String body = "FooBar"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); @@ -154,7 +154,7 @@ public class MappingJackson2XmlHttpMessageConverterTests { MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); - this.thrown.expect(HttpMessageNotReadableException.class); + this.thrown.expect(IOException.class); this.converter.read(MyBean.class, inputMessage); } @@ -181,7 +181,7 @@ public class MappingJackson2XmlHttpMessageConverterTests { MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); - this.thrown.expect(HttpMessageNotReadableException.class); + this.thrown.expect(IOException.class); this.converter.read(MyBean.class, inputMessage); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerResponseResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerResponseResultHandler.java index 83fe18148f..5496812b62 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerResponseResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerResponseResultHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -35,21 +35,23 @@ public class ServerResponseResultHandler implements HandlerResultHandler { private final HandlerStrategies strategies; + /** - * Create a {@code ResponseResultHandler} with default strategies. + * Create a {@code ServerResponseResultHandler} with default strategies. */ public ServerResponseResultHandler() { this(HandlerStrategies.builder().build()); } /** - * Create a {@code ResponseResultHandler} with the given strategies. + * Create a {@code ServerResponseResultHandler} with the given strategies. */ public ServerResponseResultHandler(HandlerStrategies strategies) { - Assert.notNull(strategies, "'strategies' must not be null"); + Assert.notNull(strategies, "HandlerStrategies must not be null"); this.strategies = strategies; } + @Override public boolean supports(HandlerResult result) { return result.getReturnValue() @@ -59,8 +61,8 @@ public class ServerResponseResultHandler implements HandlerResultHandler { @Override public Mono handleResult(ServerWebExchange exchange, HandlerResult result) { - ServerResponse response = (ServerResponse) result.getReturnValue().orElseThrow( - IllegalStateException::new); + ServerResponse response = (ServerResponse) result.getReturnValue().orElseThrow(IllegalStateException::new); return response.writeTo(exchange, this.strategies); } + } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java index eac05c35d2..8e8fb26fc2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/HandlerResultHandlerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.reactive.result; import java.util.ArrayList; @@ -54,15 +55,11 @@ public abstract class HandlerResultHandlerSupport implements Ordered { private int order = LOWEST_PRECEDENCE; - protected HandlerResultHandlerSupport(RequestedContentTypeResolver contentTypeResolver) { - this(contentTypeResolver, new ReactiveAdapterRegistry()); - } - protected HandlerResultHandlerSupport(RequestedContentTypeResolver contentTypeResolver, ReactiveAdapterRegistry adapterRegistry) { - Assert.notNull(contentTypeResolver, "'contentTypeResolver' is required."); - Assert.notNull(adapterRegistry, "'adapterRegistry' is required."); + Assert.notNull(contentTypeResolver, "RequestedContentTypeResolver is required"); + Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required"); this.contentTypeResolver = contentTypeResolver; this.adapterRegistry = adapterRegistry; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java index 9ada9e9cde..e93d9f6d0c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java @@ -17,7 +17,6 @@ package org.springframework.web.reactive.result.method.annotation; import java.lang.annotation.Annotation; -import java.lang.reflect.Method; import java.util.Collections; import java.util.List; import java.util.Map; @@ -84,8 +83,8 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho ReactiveAdapterRegistry adapterRegistry) { super(adapterRegistry); - Assert.notEmpty(messageReaders, "At least one HttpMessageReader is required."); - Assert.notNull(adapterRegistry, "'adapterRegistry' is required"); + Assert.notEmpty(messageReaders, "At least one HttpMessageReader is required"); + Assert.notNull(adapterRegistry, "ReactiveAdapterRegistry is required"); this.messageReaders = messageReaders; this.supportedMediaTypes = messageReaders.stream() .flatMap(converter -> converter.getReadableMediaTypes().stream()) @@ -156,13 +155,12 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho } private Throwable handleReadError(MethodParameter parameter, Throwable ex) { - return ex instanceof DecodingException ? - new ServerWebInputException("Failed to read HTTP message", parameter, ex) : ex; + return (ex instanceof DecodingException ? + new ServerWebInputException("Failed to read HTTP message", parameter, ex) : ex); } - private ServerWebInputException handleMissingBody(MethodParameter parameter) { - Method method = parameter.getMethod(); - return new ServerWebInputException("Request body is missing: " + method.toGenericString()); + private ServerWebInputException handleMissingBody(MethodParameter param) { + return new ServerWebInputException("Request body is missing: " + param.getMethod().toGenericString()); } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java index dd332aeb6f..d18537a575 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -51,32 +51,27 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa /** * Constructor with {@link HttpMessageWriter}s and a * {@code RequestedContentTypeResolver}. - * * @param messageWriters for serializing Objects to the response body stream * @param contentTypeResolver for resolving the requested content type */ protected AbstractMessageWriterResultHandler(List> messageWriters, RequestedContentTypeResolver contentTypeResolver) { - super(contentTypeResolver); - Assert.notEmpty(messageWriters, "At least one message writer is required."); - this.messageWriters = messageWriters; + this(messageWriters, contentTypeResolver, new ReactiveAdapterRegistry()); } /** * Constructor with an additional {@link ReactiveAdapterRegistry}. - * * @param messageWriters for serializing Objects to the response body stream * @param contentTypeResolver for resolving the requested content type * @param adapterRegistry for adapting other reactive types (e.g. rx.Observable, * rx.Single, etc.) to Flux or Mono */ protected AbstractMessageWriterResultHandler(List> messageWriters, - RequestedContentTypeResolver contentTypeResolver, - ReactiveAdapterRegistry adapterRegistry) { + RequestedContentTypeResolver contentTypeResolver, ReactiveAdapterRegistry adapterRegistry) { super(contentTypeResolver, adapterRegistry); - Assert.notEmpty(messageWriters, "At least one message writer is required."); + Assert.notEmpty(messageWriters, "At least one message writer is required"); this.messageWriters = messageWriters; } @@ -124,8 +119,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa } else { if (getProducibleMediaTypes(elementType).isEmpty()) { - return Mono.error(new IllegalStateException( - "No converter for return value type: " + elementType)); + return Mono.error(new IllegalStateException("No converter for return value type: " + elementType)); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java index 5e14c6c747..7991603327 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/HandlerResultHandlerTests.java @@ -20,9 +20,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; import org.junit.Test; +import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.MediaType; import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.test.MockServerWebExchange; @@ -31,28 +31,17 @@ import org.springframework.web.reactive.accept.FixedContentTypeResolver; import org.springframework.web.reactive.accept.HeaderContentTypeResolver; import org.springframework.web.reactive.accept.RequestedContentTypeResolver; -import static org.junit.Assert.assertEquals; -import static org.springframework.http.MediaType.ALL; -import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM; -import static org.springframework.http.MediaType.IMAGE_GIF; -import static org.springframework.http.MediaType.IMAGE_JPEG; -import static org.springframework.http.MediaType.IMAGE_PNG; -import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.junit.Assert.*; +import static org.springframework.http.MediaType.*; /** * Unit tests for {@link HandlerResultHandlerSupport}. + * * @author Rossen Stoyanchev */ public class HandlerResultHandlerTests { - private TestResultHandler resultHandler; - - - @Before - public void setup() throws Exception { - this.resultHandler = new TestResultHandler(); - } + private final TestResultHandler resultHandler = new TestResultHandler(); @Test @@ -116,7 +105,7 @@ public class HandlerResultHandlerTests { } public TestResultHandler(RequestedContentTypeResolver contentTypeResolver) { - super(contentTypeResolver); + super(contentTypeResolver, new ReactiveAdapterRegistry()); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java index 0026f01b63..5c1dd015a5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -156,8 +156,8 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe * @param inputMessage the input messages. Used to inspect the {@code Accept} header. * @param outputMessage the output message to write to * @throws IOException thrown in case of I/O errors - * @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated by {@code Accept} header on - * the request cannot be met by the message converters + * @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated + * by the {@code Accept} header on the request cannot be met by the message converters */ @SuppressWarnings("unchecked") protected void writeWithMessageConverters(T value, MethodParameter returnType,