Search in sources :

Example 11 with StompHeaders

use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-framework by spring-projects.

the class WebSocketStompClientTests method handleWebSocketMessageBinary.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleWebSocketMessageBinary() throws Exception {
    String text = "SEND\na:alpha\n\nMessage payload\0";
    connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(StandardCharsets.UTF_8)));
    ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
    verify(this.stompSession).handleMessage(captor.capture());
    Message<byte[]> message = captor.getValue();
    assertThat(message).isNotNull();
    StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
    StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
    assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
    assertThat(headers.getFirst("a")).isEqualTo("alpha");
    assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
}
Also used : TextMessage(org.springframework.web.socket.TextMessage) PongMessage(org.springframework.web.socket.PongMessage) Message(org.springframework.messaging.Message) BinaryMessage(org.springframework.web.socket.BinaryMessage) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) StompHeaders(org.springframework.messaging.simp.stomp.StompHeaders) BinaryMessage(org.springframework.web.socket.BinaryMessage) Test(org.junit.jupiter.api.Test)

Aggregations

StompHeaders (org.springframework.messaging.simp.stomp.StompHeaders)11 StompSession (org.springframework.messaging.simp.stomp.StompSession)6 Test (org.junit.jupiter.api.Test)5 Message (org.springframework.messaging.Message)4 Type (java.lang.reflect.Type)3 StompFrameHandler (org.springframework.messaging.simp.stomp.StompFrameHandler)3 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)3 StompSessionHandler (org.springframework.messaging.simp.stomp.StompSessionHandler)3 StompSessionHandlerAdapter (org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter)3 BinaryMessage (org.springframework.web.socket.BinaryMessage)3 PongMessage (org.springframework.web.socket.PongMessage)3 TextMessage (org.springframework.web.socket.TextMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)2 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)2 StompReceiptEvent (org.springframework.integration.stomp.event.StompReceiptEvent)2 SimpleMessageConverter (org.springframework.messaging.converter.SimpleMessageConverter)2 StompCommand (org.springframework.messaging.simp.stomp.StompCommand)2