use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class SimpleBrokerMessageHandlerTests method createConnectMessage.
private Message<String> createConnectMessage(String sessionId, Principal user, long[] heartbeat) {
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.CONNECT);
accessor.setSessionId(sessionId);
accessor.setUser(user);
accessor.setHeader(SimpMessageHeaderAccessor.HEART_BEAT_HEADER, heartbeat);
return MessageBuilder.createMessage("", accessor.getMessageHeaders());
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class SimpleBrokerMessageHandlerTests method connect.
@Test
public void connect() {
String id = "sess1";
Message<String> connectMessage = startSession(id);
Message<?> connectAckMessage = this.messageCaptor.getValue();
SimpMessageHeaderAccessor connectAckHeaders = SimpMessageHeaderAccessor.wrap(connectAckMessage);
assertThat(connectAckHeaders.getHeader(SimpMessageHeaderAccessor.CONNECT_MESSAGE_HEADER)).isEqualTo(connectMessage);
assertThat(connectAckHeaders.getSessionId()).isEqualTo(id);
assertThat(connectAckHeaders.getUser().getName()).isEqualTo("joe");
assertThat(SimpMessageHeaderAccessor.getHeartbeat(connectAckHeaders.getMessageHeaders())).isEqualTo(new long[] { 10000, 10000 });
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class MessageBrokerConfigurationTests method testDotSeparator.
private void testDotSeparator(ApplicationContext context, boolean expectLeadingSlash) {
MessageChannel inChannel = context.getBean("clientInboundChannel", MessageChannel.class);
TestChannel outChannel = context.getBean("clientOutboundChannel", TestChannel.class);
MessageChannel brokerChannel = context.getBean("brokerChannel", MessageChannel.class);
inChannel.send(createConnectMessage("sess1", new long[] { 0, 0 }));
// 1. Subscribe to user destination
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
headers.setSessionId("sess1");
headers.setSubscriptionId("subs1");
headers.setDestination("/user/queue.q1");
Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());
inChannel.send(message);
// 2. Send message to user via inboundChannel
headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setSessionId("sess1");
headers.setDestination("/user/sess1/queue.q1");
message = MessageBuilder.createMessage("123".getBytes(), headers.getMessageHeaders());
inChannel.send(message);
assertThat(outChannel.messages.size()).isEqualTo(2);
Message<?> outputMessage = outChannel.messages.remove(1);
headers = StompHeaderAccessor.wrap(outputMessage);
assertThat(headers.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
Object expecteds1 = expectLeadingSlash ? "/queue.q1-usersess1" : "queue.q1-usersess1";
assertThat(headers.getDestination()).isEqualTo(expecteds1);
assertThat(new String((byte[]) outputMessage.getPayload())).isEqualTo("123");
outChannel.messages.clear();
// 3. Send message via broker channel
SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel);
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
accessor.setSessionId("sess1");
template.convertAndSendToUser("sess1", "queue.q1", "456".getBytes(), accessor.getMessageHeaders());
assertThat(outChannel.messages.size()).isEqualTo(1);
outputMessage = outChannel.messages.remove(0);
headers = StompHeaderAccessor.wrap(outputMessage);
assertThat(headers.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
Object expecteds = expectLeadingSlash ? "/queue.q1-usersess1" : "queue.q1-usersess1";
assertThat(headers.getDestination()).isEqualTo(expecteds);
assertThat(new String((byte[]) outputMessage.getPayload())).isEqualTo("456");
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class StompBrokerRelayMessageHandlerTests method destinationExcluded.
@Test
void destinationExcluded() {
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()));
assertThat(this.tcpClient.getSentMessages().size()).isEqualTo(1);
StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0);
assertThat(headers1.getCommand()).isEqualTo(StompCommand.CONNECT);
assertThat(headers1.getSessionId()).isEqualTo(StompBrokerRelayMessageHandler.SYSTEM_SESSION_ID);
}
use of org.springframework.messaging.simp.SimpMessageHeaderAccessor in project spring-framework-debug by Joker-5.
the class UserDestinationMessageHandlerTests method handleMessageWithoutActiveSession.
@Test
@SuppressWarnings("rawtypes")
void handleMessageWithoutActiveSession() {
this.handler.setBroadcastDestination("/topic/unresolved");
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo"));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(this.brokerChannel).send(captor.capture());
Message message = captor.getValue();
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(message);
assertThat(accessor.getDestination()).isEqualTo("/topic/unresolved");
assertThat(accessor.getFirstNativeHeader(ORIGINAL_DESTINATION)).isEqualTo("/user/joe/queue/foo");
// Should ignore our own broadcast to brokerChannel
this.handler.handleMessage(message);
Mockito.verifyNoMoreInteractions(this.brokerChannel);
}
Aggregations