@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { // WebSocketHandlerDecorator could close the session if (!session.isOpen()) { return; } this.stats.incrementSessionCount(session); session = decorateSession(session); this.sessions.put(session.getId(), new WebSocketSessionHolder(session)); findProtocolHandler(session).afterSessionStarted(session, this.clientInboundChannel); }
@Test public void nullSubProtocol() throws Exception { this.webSocketHandler.setDefaultProtocolHandler(defaultHandler); this.webSocketHandler.afterConnectionEstablished(session); verify(this.defaultHandler).afterSessionStarted( isA(ConcurrentWebSocketSessionDecorator.class), eq(this.inClientChannel)); verify(this.stompHandler, times(0)).afterSessionStarted(session, this.inClientChannel); verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel); }
@Test public void emptySubProtocol() throws Exception { this.session.setAcceptedProtocol(""); this.webSocketHandler.setDefaultProtocolHandler(this.defaultHandler); this.webSocketHandler.afterConnectionEstablished(session); verify(this.defaultHandler).afterSessionStarted( isA(ConcurrentWebSocketSessionDecorator.class), eq(this.inClientChannel)); verify(this.stompHandler, times(0)).afterSessionStarted(session, this.inClientChannel); verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel); }
@Test public void subProtocolMatch() throws Exception { this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler)); this.session.setAcceptedProtocol("v12.sToMp"); this.webSocketHandler.afterConnectionEstablished(session); verify(this.stompHandler).afterSessionStarted( isA(ConcurrentWebSocketSessionDecorator.class), eq(this.inClientChannel)); verify(this.mqttHandler, times(0)).afterSessionStarted(session, this.inClientChannel); }
@Test public void noSubProtocolOneHandler() throws Exception { this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler)); this.webSocketHandler.afterConnectionEstablished(session); verify(this.stompHandler).afterSessionStarted( isA(ConcurrentWebSocketSessionDecorator.class), eq(this.inClientChannel)); }
@Test public void subProtocolDefaultHandlerOnly() throws Exception { this.webSocketHandler.setDefaultProtocolHandler(stompHandler); this.session.setAcceptedProtocol("v12.sToMp"); this.webSocketHandler.afterConnectionEstablished(session); verify(this.stompHandler).afterSessionStarted( isA(ConcurrentWebSocketSessionDecorator.class), eq(this.inClientChannel)); }
@Override public void afterSessionStarted(WebSocketSession session) throws Exception { // NOSONAR Thrown from the delegate if (isActive()) { 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); } } }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { // WebSocketHandlerDecorator could close the session if (!session.isOpen()) { return; } this.stats.incrementSessionCount(session); session = decorateSession(session); this.sessions.put(session.getId(), new WebSocketSessionHolder(session)); findProtocolHandler(session).afterSessionStarted(session, this.clientInboundChannel); }
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { // WebSocketHandlerDecorator could close the session if (!session.isOpen()) { return; } this.stats.incrementSessionCount(session); session = decorateSession(session); this.sessions.put(session.getId(), new WebSocketSessionHolder(session)); findProtocolHandler(session).afterSessionStarted(session, this.clientInboundChannel); }
@Override public void afterSessionStarted(WebSocketSession session) throws Exception { // NOSONAR Thrown from the delegate if (isActive()) { 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); } } }