use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolErrorHandlerTests method handleClientMessageProcessingErrorWithReceipt.
@Test
public void handleClientMessageProcessingErrorWithReceipt() throws Exception {
String receiptId = "123";
StompHeaderAccessor clientHeaderAccessor = StompHeaderAccessor.create(StompCommand.SEND);
clientHeaderAccessor.setReceipt(receiptId);
MessageHeaders clientHeaders = clientHeaderAccessor.getMessageHeaders();
Message<byte[]> clientMessage = MessageBuilder.createMessage(new byte[0], clientHeaders);
Message<byte[]> actual = this.handler.handleClientMessageProcessingError(clientMessage, new Exception());
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(actual, StompHeaderAccessor.class);
assertNotNull(accessor);
assertEquals(receiptId, accessor.getReceiptId());
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageToClientWithBinaryWebSocketMessage.
// SPR-12475
@Test
public void handleMessageToClientWithBinaryWebSocketMessage() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
headers.setMessageId("mess0");
headers.setSubscriptionId("sub0");
headers.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
headers.setDestination("/queue/foo");
// Non-empty payload
byte[] payload = new byte[1];
Message<byte[]> message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, message);
assertEquals(1, this.session.getSentMessages().size());
WebSocketMessage<?> webSocketMessage = this.session.getSentMessages().get(0);
assertTrue(webSocketMessage instanceof BinaryMessage);
// Empty payload
payload = EMPTY_PAYLOAD;
message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
this.protocolHandler.handleMessageToClient(this.session, message);
assertEquals(2, this.session.getSentMessages().size());
webSocketMessage = this.session.getSentMessages().get(1);
assertTrue(webSocketMessage instanceof TextMessage);
}
use of org.springframework.messaging.simp.stomp.StompHeaderAccessor 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" + "