use of org.springframework.web.socket.messaging.StompSubProtocolHandler in project spring-integration by spring-projects.
the class SubProtocolHandlerRegistryTests method testResolveSessionId.
@Test
public void testResolveSessionId() {
SubProtocolHandlerRegistry subProtocolHandlerRegistry = new SubProtocolHandlerRegistry(new StompSubProtocolHandler());
Message<String> message = MessageBuilder.withPayload("foo").setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, "TEST_SESSION").build();
String sessionId = subProtocolHandlerRegistry.resolveSessionId(message);
assertEquals(sessionId, "TEST_SESSION");
message = MessageBuilder.withPayload("foo").setHeader("MY_SESSION_ID", "TEST_SESSION").build();
sessionId = subProtocolHandlerRegistry.resolveSessionId(message);
assertNull(sessionId);
}
use of org.springframework.web.socket.messaging.StompSubProtocolHandler in project spring-integration by spring-projects.
the class SubProtocolHandlerRegistryTests method testSingleHandler.
@Test
public void testSingleHandler() {
SubProtocolHandler testProtocolHandler = spy(new StompSubProtocolHandler());
when(testProtocolHandler.getSupportedProtocols()).thenReturn(Collections.singletonList("foo"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = new SubProtocolHandlerRegistry(Collections.<SubProtocolHandler>singletonList(testProtocolHandler));
WebSocketSession session = mock(WebSocketSession.class);
when(session.getAcceptedProtocol()).thenReturn("foo", (String) null);
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);
}
use of org.springframework.web.socket.messaging.StompSubProtocolHandler in project spring-integration by spring-projects.
the class SubProtocolHandlerRegistryTests method testProtocolHandlers.
@Test
public void testProtocolHandlers() {
SubProtocolHandler defaultProtocolHandler = mock(SubProtocolHandler.class);
SubProtocolHandlerRegistry subProtocolHandlerRegistry = new SubProtocolHandlerRegistry(Collections.<SubProtocolHandler>singletonList(new StompSubProtocolHandler()), defaultProtocolHandler);
WebSocketSession session = mock(WebSocketSession.class);
when(session.getAcceptedProtocol()).thenReturn("v10.stomp", (String) null);
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertThat(protocolHandler, instanceOf(StompSubProtocolHandler.class));
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, defaultProtocolHandler);
assertEquals(subProtocolHandlerRegistry.getSubProtocols(), new StompSubProtocolHandler().getSupportedProtocols());
}
use of org.springframework.web.socket.messaging.StompSubProtocolHandler in project spring-integration by spring-projects.
the class SubProtocolHandlerRegistryTests method testHandlerSelection.
@Test
public void testHandlerSelection() {
SubProtocolHandler testProtocolHandler = new StompSubProtocolHandler();
SubProtocolHandlerRegistry subProtocolHandlerRegistry = new SubProtocolHandlerRegistry(testProtocolHandler);
WebSocketSession session = mock(WebSocketSession.class);
when(session.getAcceptedProtocol()).thenReturn("foo", "", null);
try {
subProtocolHandlerRegistry.findProtocolHandler(session);
fail("IllegalStateException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("No handler for sub-protocol 'foo'"));
}
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);
}
use of org.springframework.web.socket.messaging.StompSubProtocolHandler in project spring-framework by spring-projects.
the class SockJsWebSocketHandlerTests method getSubProtocols.
@Test
public void getSubProtocols() throws Exception {
SubscribableChannel channel = mock(SubscribableChannel.class);
SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
handler.addProtocolHandler(stompHandler);
TaskScheduler scheduler = mock(TaskScheduler.class);
DefaultSockJsService service = new DefaultSockJsService(scheduler);
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
assertThat(sockJsHandler.getSubProtocols()).isEqualTo(stompHandler.getSupportedProtocols());
}
Aggregations