Search in sources :

Example 6 with SimpMessageHeaderAccessor

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

the class SendToMethodReturnValueHandlerTests method sendToDefaultDestinationWhenUsingDotPathSeparator.

@Test
public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", null);
    this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
    assertEquals("/topic/dest.foo.bar", accessor.getDestination());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 7 with SimpMessageHeaderAccessor

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

the class SendToMethodReturnValueHandlerTests method sendToUserDefaultDestinationWhenUsingDotPathSeparator.

@Test
public void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    TestUser user = new TestUser();
    Message<?> inputMessage = createMessage("sess1", "sub1", "/app/", "dest.foo.bar", user);
    this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
    verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
    SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
    assertEquals("/user/" + user.getName() + "/queue/dest.foo.bar", accessor.getDestination());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 8 with SimpMessageHeaderAccessor

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

the class SendToMethodReturnValueHandlerTests method sendToUserSessionWithoutUserName.

@Test
public void sendToUserSessionWithoutUserName() throws Exception {
    given(this.messageChannel.send(any(Message.class))).willReturn(true);
    String sessionId = "sess1";
    Message<?> inputMessage = createMessage(sessionId, "sub1", null, null, null);
    this.handler.handleReturnValue(PAYLOAD, this.sendToUserReturnType, inputMessage);
    verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());
    SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
    assertEquals("/user/sess1/dest1", accessor.getDestination());
    assertEquals("sess1", accessor.getSessionId());
    accessor = getCapturedAccessor(1);
    assertEquals("/user/sess1/dest2", accessor.getDestination());
    assertEquals("sess1", accessor.getSessionId());
}
Also used : Message(org.springframework.messaging.Message) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 9 with SimpMessageHeaderAccessor

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

the class SimpAnnotationMethodMessageHandlerTests method createMessage.

private Message<?> createMessage(String destination, Map<String, Object> headers) {
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
    accessor.setSessionId("session1");
    accessor.setSessionAttributes(new HashMap<>());
    accessor.setDestination(destination);
    if (headers != null) {
        for (Map.Entry<String, Object> entry : headers.entrySet()) {
            accessor.setHeader(entry.getKey(), entry.getValue());
        }
    }
    return MessageBuilder.withPayload(new byte[0]).setHeaders(accessor).build();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor)

Example 10 with SimpMessageHeaderAccessor

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

the class SubscriptionMethodReturnValueHandlerTests method createInputMessage.

private Message<?> createInputMessage(String sessId, String subsId, String dest, Principal principal) {
    SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
    headers.setSessionId(sessId);
    headers.setSubscriptionId(subsId);
    headers.setDestination(dest);
    headers.setUser(principal);
    return MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build();
}
Also used : SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor)

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