Ensure matching user destination returned
Before this change, when a client subscribed to a "user" destination (e.g. /user/foo), actual messages received in response to that subscription contained the server-translated, unique user destination (e.g. /foo-user123). This is not an issue for clients such as stomp.js since the subscription is unique and sufficient to match subscription responses. However, other STOMP clients do additional checks on the destination of the subscription and the response. This change ensures that messages sent to clients on user destionations always contain a destination that matches the one on the original subscription. Issue: SPR-11423
This commit is contained in:
@@ -35,6 +35,7 @@ import org.springframework.messaging.simp.stomp.StompDecoder;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.simp.user.DefaultUserSessionRegistry;
|
||||
import org.springframework.messaging.simp.user.DestinationUserNameProvider;
|
||||
import org.springframework.messaging.simp.user.UserDestinationMessageHandler;
|
||||
import org.springframework.messaging.simp.user.UserSessionRegistry;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
@@ -138,6 +139,22 @@ public class StompSubProtocolHandlerTests {
|
||||
assertEquals("joe", replyHeaders.getNativeHeader("user-name").get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessageToClientUserDestination() {
|
||||
|
||||
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
|
||||
headers.setMessageId("mess0");
|
||||
headers.setSubscriptionId("sub0");
|
||||
headers.setDestination("/queue/foo-user123");
|
||||
headers.setHeader(UserDestinationMessageHandler.SUBSCRIBE_DESTINATION, "/user/queue/foo");
|
||||
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
|
||||
this.protocolHandler.handleMessageToClient(this.session, message);
|
||||
|
||||
assertEquals(1, this.session.getSentMessages().size());
|
||||
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
|
||||
assertTrue(((String) textMessage.getPayload()).contains("destination:/user/queue/foo\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleMessageFromClient() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user