|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2017 the original author or authors. |
| 2 | + * Copyright 2014-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
50 | 50 | import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
|
51 | 51 | import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
|
52 | 52 | import org.springframework.messaging.simp.stomp.StompCommand;
|
| 53 | +import org.springframework.messaging.simp.stomp.StompHeaderAccessor; |
53 | 54 | import org.springframework.messaging.support.MessageBuilder;
|
54 | 55 | import org.springframework.util.Assert;
|
55 | 56 | import org.springframework.util.CollectionUtils;
|
|
58 | 59 | import org.springframework.web.socket.WebSocketMessage;
|
59 | 60 | import org.springframework.web.socket.WebSocketSession;
|
60 | 61 | import org.springframework.web.socket.messaging.SessionConnectedEvent;
|
| 62 | +import org.springframework.web.socket.messaging.StompSubProtocolHandler; |
| 63 | +import org.springframework.web.socket.messaging.SubProtocolHandler; |
61 | 64 |
|
62 | 65 | /**
|
63 | 66 | * @author Artem Bilan
|
@@ -219,8 +222,17 @@ public List<String> getSubProtocols() {
|
219 | 222 | @Override
|
220 | 223 | public void afterSessionStarted(WebSocketSession session) throws Exception {
|
221 | 224 | 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 | + } |
224 | 236 | }
|
225 | 237 | }
|
226 | 238 |
|
|
0 commit comments