Search in sources :

Example 36 with StompHeaderAccessor

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

the class MessageBrokerConfigurationTests method clientOutboundChannelUsedByAnnotatedMethod.

@Test
public void clientOutboundChannelUsedByAnnotatedMethod() {
    TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
    SimpAnnotationMethodMessageHandler messageHandler = this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSessionId("sess1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setSubscriptionId("subs1");
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
    messageHandler.handleMessage(message);
    message = channel.messages.get(0);
    headers = StompHeaderAccessor.wrap(message);
    assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
    assertEquals("/foo", headers.getDestination());
    assertEquals("bar", new String((byte[]) message.getPayload()));
}
Also used : SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Test(org.junit.Test)

Example 37 with StompHeaderAccessor

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

the class MessageBrokerConfigurationTests method brokerChannelUsedByAnnotatedMethod.

@Test
public void brokerChannelUsedByAnnotatedMethod() {
    TestChannel channel = this.simpleBrokerContext.getBean("brokerChannel", TestChannel.class);
    SimpAnnotationMethodMessageHandler messageHandler = this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setSessionId("sess1");
    headers.setSessionAttributes(new ConcurrentHashMap<>());
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
    messageHandler.handleMessage(message);
    message = channel.messages.get(0);
    headers = StompHeaderAccessor.wrap(message);
    assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
    assertEquals("/bar", headers.getDestination());
    assertEquals("bar", new String((byte[]) message.getPayload()));
}
Also used : SimpAnnotationMethodMessageHandler(org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Test(org.junit.Test)

Example 38 with StompHeaderAccessor

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

the class MessageBrokerConfigurationTests method clientOutboundChannelUsedBySimpleBroker.

@Test
public void clientOutboundChannelUsedBySimpleBroker() {
    TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
    SimpleBrokerMessageHandler broker = this.simpleBrokerContext.getBean(SimpleBrokerMessageHandler.class);
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
    headers.setSessionId("sess1");
    headers.setSubscriptionId("subs1");
    headers.setDestination("/foo");
    Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
    // subscribe
    broker.handleMessage(message);
    headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setSessionId("sess1");
    headers.setDestination("/foo");
    message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders());
    // message
    broker.handleMessage(message);
    message = channel.messages.get(0);
    headers = StompHeaderAccessor.wrap(message);
    assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
    assertEquals("/foo", headers.getDestination());
    assertEquals("bar", new String((byte[]) message.getPayload()));
}
Also used : SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Test(org.junit.Test)

Aggregations

StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)38 Test (org.junit.Test)28 TextMessage (org.springframework.web.socket.TextMessage)19 Message (org.springframework.messaging.Message)10 BinaryMessage (org.springframework.web.socket.BinaryMessage)9 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)6 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)5 StompEncoder (org.springframework.messaging.simp.stomp.StompEncoder)4 StompHeaders (org.springframework.messaging.simp.stomp.StompHeaders)3 PongMessage (org.springframework.web.socket.PongMessage)3 Principal (java.security.Principal)2 MessageHeaders (org.springframework.messaging.MessageHeaders)2 SimpAttributes (org.springframework.messaging.simp.SimpAttributes)2 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)2 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)2 ByteBuffer (java.nio.ByteBuffer)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1