Search in sources :

Example 91 with TextMessage

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);
    assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/plain;charset=UTF-8");
    verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) TextMessage(org.springframework.web.socket.TextMessage)

Example 92 with TextMessage

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"));
    XhrReceivingTransportHandler transportHandler = new XhrReceivingTransportHandler();
    transportHandler.initialize(sockJsConfig);
    assertThatExceptionOfType(SockJsMessageDeliveryException.class).isThrownBy(() -> transportHandler.handleRequest(this.request, this.response, wsHandler, session));
    assertThat(session.getCloseStatus()).isNull();
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) SockJsMessageDeliveryException(org.springframework.web.socket.sockjs.SockJsMessageDeliveryException) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) SockJsMessageDeliveryException(org.springframework.web.socket.sockjs.SockJsMessageDeliveryException) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TextMessage (org.springframework.web.socket.TextMessage)92 Test (org.junit.jupiter.api.Test)42 WebSocketSession (org.springframework.web.socket.WebSocketSession)20 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)16 IOException (java.io.IOException)14 Test (org.junit.Test)8 BinaryMessage (org.springframework.web.socket.BinaryMessage)8 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)7 URI (java.net.URI)6 Message (org.springframework.messaging.Message)6 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)6 StompEncoder (org.springframework.messaging.simp.stomp.StompEncoder)4 CloseStatus (org.springframework.web.socket.CloseStatus)4 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)4 ArrayList (java.util.ArrayList)3 MessageChannel (org.springframework.messaging.MessageChannel)3 ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)3 ImmutableMessageChannelInterceptor (org.springframework.messaging.support.ImmutableMessageChannelInterceptor)3 ShellLogResponseMessage (com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage)2 UncheckedIOException (java.io.UncheckedIOException)2