Search in sources :

Example 16 with SimpMessageHeaderAccessor

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

the class SimpleBrokerMessageHandlerTests method createSubscriptionMessage.

private Message<String> createSubscriptionMessage(String sessionId, String subcriptionId, String destination) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.SUBSCRIBE);
    headers.setSubscriptionId(subcriptionId);
    headers.setDestination(destination);
    headers.setSessionId(sessionId);
    return MessageBuilder.createMessage("", headers.getMessageHeaders());
}
Also used : SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor)

Example 17 with SimpMessageHeaderAccessor

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

the class StompBrokerRelayMessageHandlerTests method destinationExcluded.

@Test
public void destinationExcluded() throws Exception {
    this.brokerRelay.start();
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    headers.setSessionId("sess1");
    headers.setDestination("/user/daisy/foo");
    this.brokerRelay.handleMessage(MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders()));
    assertEquals(1, this.tcpClient.getSentMessages().size());
    StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0);
    assertEquals(StompCommand.CONNECT, headers1.getCommand());
    assertEquals(StompBrokerRelayMessageHandler.SYSTEM_SESSION_ID, headers1.getSessionId());
}
Also used : SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 18 with SimpMessageHeaderAccessor

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

the class StompHeaderAccessorTests method toNativeHeadersContentType.

@Test
public void toNativeHeadersContentType() {
    SimpMessageHeaderAccessor simpHeaderAccessor = SimpMessageHeaderAccessor.create();
    simpHeaderAccessor.setContentType(MimeType.valueOf("application/atom+xml"));
    Message<byte[]> message = MessageBuilder.createMessage(new byte[0], simpHeaderAccessor.getMessageHeaders());
    StompHeaderAccessor stompHeaderAccessor = StompHeaderAccessor.wrap(message);
    Map<String, List<String>> map = stompHeaderAccessor.toNativeHeaderMap();
    assertEquals("application/atom+xml", map.get(StompHeaderAccessor.STOMP_CONTENT_TYPE_HEADER).get(0));
}
Also used : List(java.util.List) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 19 with SimpMessageHeaderAccessor

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

the class StompSubProtocolHandlerTests method handleMessageToClientWithSimpConnectAck.

@Test
public void handleMessageToClientWithSimpConnectAck() {
    StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECT);
    accessor.setHeartbeat(10000, 10000);
    accessor.setAcceptVersion("1.0,1.1");
    Message<?> connectMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
    SimpMessageHeaderAccessor ackAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT_ACK);
    ackAccessor.setHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER, connectMessage);
    ackAccessor.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, new long[] { 15000, 15000 });
    Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, ackAccessor.getMessageHeaders());
    this.protocolHandler.handleMessageToClient(this.session, ackMessage);
    assertEquals(1, this.session.getSentMessages().size());
    TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
    assertEquals("CONNECTED\n" + "version:1.1\n" + "heart-beat:15000,15000\n" + "user-name:joe\n" + "\n" + "", actual.getPayload());
}
Also used : StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) TextMessage(org.springframework.web.socket.TextMessage) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 20 with SimpMessageHeaderAccessor

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

the class StompSubProtocolHandlerTests method handleMessageToClientWithSimpHeartbeat.

@Test
public void handleMessageToClientWithSimpHeartbeat() {
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.HEARTBEAT);
    accessor.setSessionId("s1");
    accessor.setUser(new TestPrincipal("joe"));
    Message<byte[]> ackMessage = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
    this.protocolHandler.handleMessageToClient(this.session, ackMessage);
    assertEquals(1, this.session.getSentMessages().size());
    TextMessage actual = (TextMessage) this.session.getSentMessages().get(0);
    assertEquals("\n", actual.getPayload());
}
Also used : TestPrincipal(org.springframework.messaging.simp.TestPrincipal) TextMessage(org.springframework.web.socket.TextMessage) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Aggregations

SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)54 Test (org.junit.Test)34 Message (org.springframework.messaging.Message)14 MessageHeaders (org.springframework.messaging.MessageHeaders)5 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)5 TextMessage (org.springframework.web.socket.TextMessage)5 MessageChannel (org.springframework.messaging.MessageChannel)3 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)3 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 HttpRequestHandler (org.springframework.web.HttpRequestHandler)3 Principal (java.security.Principal)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MissingCsrfTokenException (org.springframework.security.web.csrf.MissingCsrfTokenException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MessageSendingOperations (org.springframework.messaging.core.MessageSendingOperations)1