Fix WebSocketInChA according latest SF

* The `SimpleBrokerMessageHandler` has been fixed the way it consults
a `session` store for sending reply.
The session can be added to that store only when we send a `CONNECT`
command.
Fix `WebSocketInboundChannelAdapter` to send additional `CONNECT` message
in the `afterSessionStarted()` and when selected `SubProtocolHandler` is
a `StompSubProtocolHandler`
* Add extract check into the `StompIntegrationTests` for events: now
we also get a `SessionConnectedEvent` as well
* Fix typo in the `index-docinfo.xml`
This commit is contained in:
Artem Bilan
2018-07-24 14:59:39 -04:00
parent 001b86b641
commit a7ffbde07f
3 changed files with 23 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 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.
@@ -50,6 +50,7 @@ import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler;
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
import org.springframework.messaging.simp.stomp.StompCommand;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -58,6 +59,8 @@ import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.messaging.SessionConnectedEvent;
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.messaging.SubProtocolHandler;
/**
* @author Artem Bilan
@@ -219,8 +222,17 @@ public class WebSocketInboundChannelAdapter extends MessageProducerSupport
@Override
public void afterSessionStarted(WebSocketSession session) throws Exception {
if (isActive()) {
this.subProtocolHandlerRegistry.findProtocolHandler(session)
.afterSessionStarted(session, this.subProtocolHandlerChannel);
SubProtocolHandler protocolHandler = this.subProtocolHandlerRegistry.findProtocolHandler(session);
protocolHandler.afterSessionStarted(session, this.subProtocolHandlerChannel);
if (!this.server && protocolHandler instanceof StompSubProtocolHandler) {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECT);
accessor.setSessionId(session.getId());
accessor.setLeaveMutable(true);
accessor.setAcceptVersion("1.1,1.2");
Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
protocolHandler.handleMessageToClient(session, connectMessage);
}
}
}

View File

@@ -157,6 +157,10 @@ public class StompIntegrationTests {
@Test
public void sendMessageToControllerAndReceiveReplyViaTopic() throws Exception {
Message<?> receive = this.webSocketEvents.receive(20000);
assertNotNull(receive);
Object event = receive.getPayload();
assertThat(event, instanceOf(SessionConnectedEvent.class));
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSubscriptionId("subs1");
@@ -168,9 +172,9 @@ public class StompIntegrationTests {
this.webSocketOutputChannel.send(message);
Message<?> receive = this.webSocketEvents.receive(20000);
receive = this.webSocketEvents.receive(20000);
assertNotNull(receive);
Object event = receive.getPayload();
event = receive.getPayload();
assertThat(event, instanceOf(ReceiptEvent.class));
Message<?> receiptMessage = ((ReceiptEvent) event).getMessage();
headers = StompHeaderAccessor.wrap(receiptMessage);

View File

@@ -37,11 +37,10 @@
</author><author>
<firstname>Amol</firstname>
<surname>Nayak</surname>
</author>
</author><author>
</author><author>
<firstname>Jay</firstname>
<surname>Bryant</surname>
</author>
</author>
</authorgroup>
<copyright>