From fabc5fb7254c5c65a5f64f26c9ad99a5bb41561b Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 7 Jun 2017 15:26:55 -0400 Subject: [PATCH] Fix STOMP and WebSocket modules to the latest SF * The `@MessageMapping` now requires `@SendTo` for replies even if we are going to send to the default topic * Fix assertion for exception message in the `StompInboundChannelAdapterWebSocketIntegrationTests` --- ...annelAdapterWebSocketIntegrationTests.java | 3 +- .../client/StompIntegrationTests.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java index 71a466b860..2d1c7c3e58 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java @@ -176,7 +176,8 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju Throwable throwable = errorMessage.getPayload(); assertThat(throwable, instanceOf(MessageHandlingException.class)); assertThat(throwable.getCause(), instanceOf(MessageConversionException.class)); - assertThat(throwable.getMessage(), containsString("No suitable converter, payloadType=interface java.util.Map")); + assertThat(throwable.getMessage(), + containsString("No suitable converter for payload type [interface java.util.Map]")); this.serverContext.close(); diff --git a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java index 091a50fb5d..a5ee7f9f1c 100644 --- a/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java +++ b/spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-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. @@ -70,6 +70,7 @@ import org.springframework.messaging.MessageHandler; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.handler.annotation.MessageExceptionHandler; import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.annotation.SendToUser; import org.springframework.messaging.simp.annotation.SubscribeMapping; import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; @@ -102,6 +103,7 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport; /** * @author Artem Bilan + * * @since 4.1 */ @ContextConfiguration @@ -426,6 +428,7 @@ public class StompIntegrationTests extends LogAdjustingTestSupport { static class IncrementController { @MessageMapping("/increment") + @SendTo public int handle(int i) { return i + 1; } @@ -491,15 +494,22 @@ public class StompIntegrationTests extends LogAdjustingTestSupport { @Bean public ApplicationListener webSocketEventListener( final AbstractSubscribableChannel clientOutboundChannel) { - return event -> { - Message message = event.getMessage(); - StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message); - if (stompHeaderAccessor.getReceipt() != null) { - stompHeaderAccessor.setHeader("stompCommand", StompCommand.RECEIPT); - stompHeaderAccessor.setReceiptId(stompHeaderAccessor.getReceipt()); - clientOutboundChannel.send( - MessageBuilder.createMessage(new byte[0], stompHeaderAccessor.getMessageHeaders())); + // Cannot be lambda because Java can't infer generic type from lambdas, + // therefore we end up with ClassCastException for other event types + return new ApplicationListener() { + + @Override + public void onApplicationEvent(SessionSubscribeEvent event) { + Message message = event.getMessage(); + StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message); + if (stompHeaderAccessor.getReceipt() != null) { + stompHeaderAccessor.setHeader("stompCommand", StompCommand.RECEIPT); + stompHeaderAccessor.setReceiptId(stompHeaderAccessor.getReceipt()); + clientOutboundChannel.send( + MessageBuilder.createMessage(new byte[0], stompHeaderAccessor.getMessageHeaders())); + } } + }; }