diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java index d232cb94459..bbbdfd4ee8a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java @@ -179,8 +179,8 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH } } } - else if (annotation instanceof SendTo) { - SendTo sendTo = (SendTo) annotation; + else { + SendTo sendTo = (SendTo) annotation; // possibly null String[] destinations = getTargetDestinations(sendTo, message, this.defaultDestinationPrefix); for (String destination : destinations) { destination = this.placeholderHelper.replacePlaceholders(destination, varResolver); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java index c6be730949c..63427c35fae 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java @@ -27,7 +27,6 @@ import javax.security.auth.Subject; import com.fasterxml.jackson.annotation.JsonView; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -176,7 +175,6 @@ public class SendToMethodReturnValueHandlerTests { } @Test - @Ignore // TODO: NULLABLE public void sendToNoAnnotations() throws Exception { given(this.messageChannel.send(any(Message.class))).willReturn(true); @@ -346,7 +344,6 @@ public class SendToMethodReturnValueHandlerTests { } @Test - @Ignore // TODO: NULLABLE public void testHeadersToSend() throws Exception { Message message = createMessage("sess1", "sub1", "/app", "/dest", null); @@ -530,7 +527,6 @@ public class SendToMethodReturnValueHandlerTests { } @Test - @Ignore // TODO: NULLABLE public void jsonView() throws Exception { given(this.messageChannel.send(any(Message.class))).willReturn(true); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java index 5576ccda8ef..9b895bb8988 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java @@ -26,7 +26,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -238,7 +237,6 @@ public class SimpAnnotationMethodMessageHandlerTests { } @Test - @Ignore // TODO: NULLABLE @SuppressWarnings("unchecked") public void listenableFutureSuccess() { Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build(); @@ -277,7 +275,6 @@ public class SimpAnnotationMethodMessageHandlerTests { } @Test - @Ignore // TODO: NULLABLE @SuppressWarnings("unchecked") public void completableFutureSuccess() { Message emptyMessage = (Message) MessageBuilder.withPayload(new byte[0]).build(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java index 32ff11079d2..c5534b33257 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java @@ -19,7 +19,6 @@ package org.springframework.messaging.simp.user; import java.nio.charset.StandardCharsets; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -123,7 +122,6 @@ public class UserDestinationMessageHandlerTests { } @Test - @Ignore // TODO: NULLABLE public void handleMessageFromBrokerWithActiveSession() { TestSimpUser simpUser = new TestSimpUser("joe"); simpUser.addSessions(new TestSimpSession("123")); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java index 8e903c7cd14..205c919dc21 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java @@ -200,11 +200,11 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements logger.debug("Read [" + targetType + "] as \"" + contentType + "\" with [" + converter + "]"); } if (message.hasBody()) { - HttpInputMessage inputMessageToUse = + HttpInputMessage msgToUse = getAdvice().beforeBodyRead(message, parameter, targetType, converterType); - body = (genericConverter != null ? genericConverter.read(targetType, contextClass, message) : - ((HttpMessageConverter) converter).read(targetClass, message)); - body = getAdvice().afterBodyRead(body, inputMessageToUse, parameter, targetType, converterType); + body = (genericConverter != null ? genericConverter.read(targetType, contextClass, msgToUse) : + ((HttpMessageConverter) converter).read(targetClass, msgToUse)); + body = getAdvice().afterBodyRead(body, msgToUse, parameter, targetType, converterType); } else { body = getAdvice().handleEmptyBody(null, message, parameter, targetType, converterType); 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 e9fe6f8d2e8..deaf2b823c8 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 @@ -117,6 +117,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe @Nullable ContentNegotiationManager manager, @Nullable List requestResponseBodyAdvice) { super(converters, requestResponseBodyAdvice); + this.contentNegotiationManager = (manager != null ? manager : new ContentNegotiationManager()); this.pathStrategy = initPathStrategy(this.contentNegotiationManager); this.safeExtensions.addAll(this.contentNegotiationManager.getAllFileExtensions()); @@ -163,7 +164,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe * @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated * by the {@code Accept} header on the request cannot be met by the message converters */ - @SuppressWarnings("unchecked") + @SuppressWarnings({"rawtypes", "unchecked"}) protected void writeWithMessageConverters(@Nullable T value, MethodParameter returnType, ServletServerHttpRequest inputMessage, ServletServerHttpResponse outputMessage) throws IOException, HttpMediaTypeNotAcceptableException, HttpMessageNotWritableException { @@ -223,35 +224,26 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe if (selectedMediaType != null) { selectedMediaType = selectedMediaType.removeQualityValue(); - for (HttpMessageConverter messageConverter : this.messageConverters) { - if (messageConverter instanceof GenericHttpMessageConverter) { - if (((GenericHttpMessageConverter) messageConverter).canWrite( - declaredType, valueType, selectedMediaType)) { - outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType, - (Class>) messageConverter.getClass(), - inputMessage, outputMessage); - if (outputValue != null) { - addContentDispositionHeader(inputMessage, outputMessage); - ((GenericHttpMessageConverter) messageConverter).write( - outputValue, declaredType, selectedMediaType, outputMessage); - if (logger.isDebugEnabled()) { - logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType + - "\" using [" + messageConverter + "]"); - } - } - return; - } - } - else if (messageConverter.canWrite(valueType, selectedMediaType)) { + for (HttpMessageConverter converter : this.messageConverters) { + GenericHttpMessageConverter genericConverter = + (converter instanceof GenericHttpMessageConverter ? (GenericHttpMessageConverter) converter : null); + if (genericConverter != null ? + ((GenericHttpMessageConverter) converter).canWrite(declaredType, valueType, selectedMediaType) : + converter.canWrite(valueType, selectedMediaType)) { outputValue = (T) getAdvice().beforeBodyWrite(outputValue, returnType, selectedMediaType, - (Class>) messageConverter.getClass(), + (Class>) converter.getClass(), inputMessage, outputMessage); if (outputValue != null) { addContentDispositionHeader(inputMessage, outputMessage); - ((HttpMessageConverter) messageConverter).write(outputValue, selectedMediaType, outputMessage); + if (genericConverter != null) { + genericConverter.write(outputValue, declaredType, selectedMediaType, outputMessage); + } + else { + ((HttpMessageConverter) converter).write(outputValue, selectedMediaType, outputMessage); + } if (logger.isDebugEnabled()) { logger.debug("Written [" + outputValue + "] as \"" + selectedMediaType + - "\" using [" + messageConverter + "]"); + "\" using [" + converter + "]"); } } return; @@ -305,7 +297,9 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe * @since 4.2 */ @SuppressWarnings("unchecked") - protected List getProducibleMediaTypes(HttpServletRequest request, Class valueClass, @Nullable Type declaredType) { + protected List getProducibleMediaTypes(HttpServletRequest request, Class valueClass, + @Nullable Type declaredType) { + Set mediaTypes = (Set) request.getAttribute(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); if (!CollectionUtils.isEmpty(mediaTypes)) { return new ArrayList<>(mediaTypes); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java index 109ed5ef5dd..dc191ec42b4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java @@ -89,7 +89,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter * @since 4.2 */ public RequestResponseBodyMethodProcessor(List> converters, - List requestResponseBodyAdvice) { + @Nullable List requestResponseBodyAdvice) { super(converters, null, requestResponseBodyAdvice); } @@ -99,7 +99,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter * {@code @ResponseBody}. */ public RequestResponseBodyMethodProcessor(List> converters, - ContentNegotiationManager manager, List requestResponseBodyAdvice) { + @Nullable ContentNegotiationManager manager, @Nullable List requestResponseBodyAdvice) { super(converters, manager, requestResponseBodyAdvice); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java index faa82b01e54..cd84c9715c2 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessorTests.java @@ -507,7 +507,6 @@ public class RequestResponseBodyMethodProcessorTests { } @Test // SPR-12501 - @Ignore // TODO: NULLABLE public void resolveArgumentWithJacksonJsonView() throws Exception { String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"; this.servletRequest.setContent(content.getBytes("UTF-8")); @@ -534,7 +533,6 @@ public class RequestResponseBodyMethodProcessorTests { } @Test // SPR-12501 - @Ignore // TODO: NULLABLE public void resolveHttpEntityArgumentWithJacksonJsonView() throws Exception { String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"; this.servletRequest.setContent(content.getBytes("UTF-8")); @@ -562,7 +560,6 @@ public class RequestResponseBodyMethodProcessorTests { } @Test // SPR-12501 - @Ignore // TODO: NULLABLE public void resolveArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception { String content = "withwithwithout"; this.servletRequest.setContent(content.getBytes("UTF-8")); @@ -589,7 +586,6 @@ public class RequestResponseBodyMethodProcessorTests { } @Test // SPR-12501 - @Ignore // TODO: NULLABLE public void resolveHttpEntityArgumentWithJacksonJsonViewAndXmlMessageConverter() throws Exception { String content = "withwithwithout"; this.servletRequest.setContent(content.getBytes("UTF-8")); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java index 6dd7d61c27d..231e9bb283c 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 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. @@ -23,7 +23,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -67,7 +66,6 @@ import static org.springframework.web.socket.messaging.StompTextMessageBuilder.* * @author Rossen Stoyanchev */ @RunWith(Parameterized.class) -@Ignore // TODO: NULLABLE public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests { private static final long TIMEOUT = 10; @@ -120,8 +118,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration } } - // SPR-10930 - @Test + @Test // SPR-10930 public void sendMessageToBrokerAndReceiveReplyViaTopic() throws Exception { TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/foo").build(); TextMessage m2 = create(StompCommand.SEND).headers("destination:/topic/foo").body("5").build(); @@ -140,8 +137,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration } } - // SPR-11648 - @Test + @Test // SPR-11648 public void sendSubscribeToControllerAndReceiveReply() throws Exception { String destHeader = "destination:/app/number"; TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();