use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method handleRequest.
private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception {
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
transportHandler.initialize(new StubSockJsServiceConfig());
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class HttpReceivingTransportHandlerTests method delegateMessageException.
@Test
public void delegateMessageException() throws Exception {
StubSockJsServiceConfig sockJsConfig = new StubSockJsServiceConfig();
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8"));
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
TestHttpSockJsSession session = new TestHttpSockJsSession("1", sockJsConfig, wsHandler, null);
session.delegateConnectionEstablished();
willThrow(new Exception()).given(wsHandler).handleMessage(session, new TextMessage("x"));
try {
XhrReceivingTransportHandler transportHandler = new XhrReceivingTransportHandler();
transportHandler.initialize(sockJsConfig);
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
fail("Expected exception");
} catch (SockJsMessageDeliveryException ex) {
assertNull(session.getCloseStatus());
}
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketServerSockJsSessionTests method handleMessageEmptyPayload.
@Test
public void handleMessageEmptyPayload() throws Exception {
this.session.handleMessage(new TextMessage(""), this.webSocketSession);
verifyNoMoreInteractions(this.webSocketHandler);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClientWithImmutableMessageInterceptor.
@Test
public void handleMessageFromClientWithImmutableMessageInterceptor() {
AtomicReference<Boolean> mutable = new AtomicReference<>();
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
mutable.set(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class).isMutable());
return message;
}
});
channel.addInterceptor(new ImmutableMessageChannelInterceptor());
StompSubProtocolHandler handler = new StompSubProtocolHandler();
handler.afterSessionStarted(this.session, channel);
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
handler.handleMessageFromClient(this.session, message, channel);
assertNotNull(mutable.get());
assertTrue(mutable.get());
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClient.
@Test
public void handleMessageFromClient() {
TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).headers("login:guest", "passcode:guest", "accept-version:1.1,1.0", "heart-beat:10000,10000").build();
this.protocolHandler.afterSessionStarted(this.session, this.channel);
this.protocolHandler.handleMessageFromClient(this.session, textMessage, this.channel);
verify(this.channel).send(this.messageCaptor.capture());
Message<?> actual = this.messageCaptor.getValue();
assertNotNull(actual);
assertEquals("s1", SimpMessageHeaderAccessor.getSessionId(actual.getHeaders()));
assertNotNull(SimpMessageHeaderAccessor.getSessionAttributes(actual.getHeaders()));
assertNotNull(SimpMessageHeaderAccessor.getUser(actual.getHeaders()));
assertEquals("joe", SimpMessageHeaderAccessor.getUser(actual.getHeaders()).getName());
assertNotNull(SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
assertArrayEquals(new long[] { 10000, 10000 }, SimpMessageHeaderAccessor.getHeartbeat(actual.getHeaders()));
StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(actual);
assertEquals(StompCommand.CONNECT, stompAccessor.getCommand());
assertEquals("guest", stompAccessor.getLogin());
assertEquals("guest", stompAccessor.getPasscode());
assertArrayEquals(new long[] { 10000, 10000 }, stompAccessor.getHeartbeat());
assertEquals(new HashSet<>(Arrays.asList("1.1", "1.0")), stompAccessor.getAcceptVersion());
assertEquals(0, this.session.getSentMessages().size());
}
Aggregations