Search in sources :

Example 1 with TextMessage

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

the class SimpleClientWebSocketHandler method afterConnectionEstablished.

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    TextMessage message = new TextMessage(this.greetingService.getGreeting());
    session.sendMessage(message);
}
Also used : TextMessage(org.springframework.web.socket.TextMessage)

Example 2 with TextMessage

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

the class SimpleClientWebSocketHandler method afterConnectionEstablished.

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    TextMessage message = new TextMessage(this.greetingService.getGreeting());
    session.sendMessage(message);
}
Also used : TextMessage(org.springframework.web.socket.TextMessage)

Example 3 with TextMessage

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

the class AbstractSockJsSession method delegateMessages.

public void delegateMessages(String... messages) throws SockJsMessageDeliveryException {
    List<String> undelivered = new ArrayList<>(Arrays.asList(messages));
    for (String message : messages) {
        try {
            if (isClosed()) {
                throw new SockJsMessageDeliveryException(this.id, undelivered, "Session closed");
            } else {
                this.handler.handleMessage(this, new TextMessage(message));
                undelivered.remove(0);
            }
        } catch (Throwable ex) {
            throw new SockJsMessageDeliveryException(this.id, undelivered, ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SockJsMessageDeliveryException(org.springframework.web.socket.sockjs.SockJsMessageDeliveryException) TextMessage(org.springframework.web.socket.TextMessage)

Example 4 with TextMessage

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

the class StompWebSocketIntegrationTests method sendSubscribeToControllerAndReceiveReply.

// SPR-11648
@Test
public void sendSubscribeToControllerAndReceiveReply() throws Exception {
    String destHeader = "destination:/app/number";
    TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();
    TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(1, message);
    WebSocketSession session = doHandshake(clientHandler, "/ws").get();
    try {
        assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
        String payload = clientHandler.actual.get(0).getPayload();
        assertTrue("Expected STOMP destination=/app/number, got " + payload, payload.contains(destHeader));
        assertTrue("Expected STOMP Payload=42, got " + payload, payload.contains("42"));
    } finally {
        session.close();
    }
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) Test(org.junit.Test)

Example 5 with TextMessage

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

the class StompWebSocketIntegrationTests method sendMessageToController.

@Test
public void sendMessageToController() throws Exception {
    TextMessage message = create(StompCommand.SEND).headers("destination:/app/simple").build();
    WebSocketSession session = doHandshake(new TestClientWebSocketHandler(0, message), "/ws").get();
    SimpleController controller = this.wac.getBean(SimpleController.class);
    try {
        assertTrue(controller.latch.await(TIMEOUT, TimeUnit.SECONDS));
    } finally {
        session.close();
    }
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) Test(org.junit.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