Search in sources :

Example 26 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.

the class AbstractSockJsIntegrationTests method fallbackAfterTransportFailure.

@Test
public void fallbackAfterTransportFailure() throws Exception {
    this.testFilter.sendErrorMap.put("/websocket", 200);
    this.testFilter.sendErrorMap.put("/xhr_streaming", 500);
    TestClientHandler handler = new TestClientHandler();
    initSockJsClient(createWebSocketTransport(), createXhrTransport());
    WebSocketSession session = this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").get();
    assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, session.getClass());
    TextMessage message = new TextMessage("message1");
    session.sendMessage(message);
    handler.awaitMessage(message, 5000);
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) Test(org.junit.Test)

Example 27 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.

the class ClientSockJsSessionTests method send.

@Test
public void send() throws Exception {
    this.session.handleFrame(SockJsFrame.openFrame().getContent());
    this.session.sendMessage(new TextMessage("foo"));
    assertThat(this.session.sentMessage, equalTo(new TextMessage("[\"foo\"]")));
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 28 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.

the class ClientSockJsSessionTests method handleFrameMessage.

@Test
public void handleFrameMessage() throws Exception {
    this.session.handleFrame(SockJsFrame.openFrame().getContent());
    this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
    verify(this.handler).afterConnectionEstablished(this.session);
    verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
    verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
    verifyNoMoreInteractions(this.handler);
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 29 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.

the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithPrelude.

@Test
public void connectReceiveAndCloseWithPrelude() throws Exception {
    StringBuilder sb = new StringBuilder(2048);
    for (int i = 0; i < 2048; i++) {
        sb.append('h');
    }
    String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);
    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
    verifyNoMoreInteractions(this.webSocketHandler);
}
Also used : CloseStatus(org.springframework.web.socket.CloseStatus) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 30 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.

the class RestTemplateXhrTransportTests method connectReceiveAndClose.

@Test
public void connectReceiveAndClose() throws Exception {
    String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);
    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
    verifyNoMoreInteractions(this.webSocketHandler);
}
Also used : CloseStatus(org.springframework.web.socket.CloseStatus) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Aggregations

TextMessage (org.springframework.web.socket.TextMessage)65 Test (org.junit.Test)48 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)16 WebSocketSession (org.springframework.web.socket.WebSocketSession)10 BinaryMessage (org.springframework.web.socket.BinaryMessage)8 IOException (java.io.IOException)7 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)7 Message (org.springframework.messaging.Message)6 URI (java.net.URI)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 StompEncoder (org.springframework.messaging.simp.stomp.StompEncoder)4 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)4 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)4 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)3 MessageChannel (org.springframework.messaging.MessageChannel)3 ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)3 ImmutableMessageChannelInterceptor (org.springframework.messaging.support.ImmutableMessageChannelInterceptor)3 CloseStatus (org.springframework.web.socket.CloseStatus)3 TestWebSocketSession (org.springframework.web.socket.handler.TestWebSocketSession)3 SockJsMessageDeliveryException (org.springframework.web.socket.sockjs.SockJsMessageDeliveryException)3