Skip to content

Commit a7ffbde

Browse files
committed
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`
1 parent 001b86b commit a7ffbde

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/inbound/WebSocketInboundChannelAdapter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@
5050
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
5151
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
5252
import org.springframework.messaging.simp.stomp.StompCommand;
53+
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
5354
import org.springframework.messaging.support.MessageBuilder;
5455
import org.springframework.util.Assert;
5556
import org.springframework.util.CollectionUtils;
@@ -58,6 +59,8 @@
5859
import org.springframework.web.socket.WebSocketMessage;
5960
import org.springframework.web.socket.WebSocketSession;
6061
import org.springframework.web.socket.messaging.SessionConnectedEvent;
62+
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
63+
import org.springframework.web.socket.messaging.SubProtocolHandler;
6164

6265
/**
6366
* @author Artem Bilan
@@ -219,8 +222,17 @@ public List<String> getSubProtocols() {
219222
@Override
220223
public void afterSessionStarted(WebSocketSession session) throws Exception {
221224
if (isActive()) {
222-
this.subProtocolHandlerRegistry.findProtocolHandler(session)
223-
.afterSessionStarted(session, this.subProtocolHandlerChannel);
225+
SubProtocolHandler protocolHandler = this.subProtocolHandlerRegistry.findProtocolHandler(session);
226+
protocolHandler.afterSessionStarted(session, this.subProtocolHandlerChannel);
227+
if (!this.server && protocolHandler instanceof StompSubProtocolHandler) {
228+
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECT);
229+
accessor.setSessionId(session.getId());
230+
accessor.setLeaveMutable(true);
231+
accessor.setAcceptVersion("1.1,1.2");
232+
233+
Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
234+
protocolHandler.handleMessageToClient(session, connectMessage);
235+
}
224236
}
225237
}
226238

spring-integration-websocket/src/test/java/org/springframework/integration/websocket/client/StompIntegrationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ public void sendMessageToController() throws Exception {
157157

158158
@Test
159159
public void sendMessageToControllerAndReceiveReplyViaTopic() throws Exception {
160+
Message<?> receive = this.webSocketEvents.receive(20000);
161+
assertNotNull(receive);
162+
Object event = receive.getPayload();
163+
assertThat(event, instanceOf(SessionConnectedEvent.class));
160164

161165
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
162166
headers.setSubscriptionId("subs1");
@@ -168,9 +172,9 @@ public void sendMessageToControllerAndReceiveReplyViaTopic() throws Exception {
168172

169173
this.webSocketOutputChannel.send(message);
170174

171-
Message<?> receive = this.webSocketEvents.receive(20000);
175+
receive = this.webSocketEvents.receive(20000);
172176
assertNotNull(receive);
173-
Object event = receive.getPayload();
177+
event = receive.getPayload();
174178
assertThat(event, instanceOf(ReceiptEvent.class));
175179
Message<?> receiptMessage = ((ReceiptEvent) event).getMessage();
176180
headers = StompHeaderAccessor.wrap(receiptMessage);

src/reference/asciidoc/index-docinfo.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@
3737
</author><author>
3838
<firstname>Amol</firstname>
3939
<surname>Nayak</surname>
40-
</author>
41-
</author><author>
40+
</author><author>
4241
<firstname>Jay</firstname>
4342
<surname>Bryant</surname>
44-
</author>
43+
</author>
4544
</authorgroup>
4645

4746
<copyright>

0 commit comments

Comments
 (0)