@Test(expected = IllegalStateException.class) public void subProtocolNoMatch() throws Exception { this.webSocketHandler.setDefaultProtocolHandler(defaultHandler); this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler)); this.session.setAcceptedProtocol("wamp"); this.webSocketHandler.afterConnectionEstablished(session); }
@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)); }
@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); }
@Bean public WebSocketHandler subProtocolWebSocketHandler() { SubProtocolWebSocketHandler webSocketHandler = new SubProtocolWebSocketHandler(clientInboundChannel(), clientOutboundChannel()); webSocketHandler.setDefaultProtocolHandler(stompSubProtocolHandler()); return webSocketHandler; }