use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageBuilderTests method testBuildMessageWithMutableHeaders.
@Test
public void testBuildMessageWithMutableHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
Message<?> message = MessageBuilder.createMessage("payload", headers);
accessor.setHeader("foo", "bar");
assertEquals("bar", headers.get("foo"));
assertSame(accessor, MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageBuilderTests method testBuildMessageWithDefaultMutability.
@Test
public void testBuildMessageWithDefaultMutability() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
MessageHeaders headers = accessor.getMessageHeaders();
Message<?> message = MessageBuilder.createMessage("foo", headers);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Already immutable");
accessor.setHeader("foo", "bar");
assertSame(accessor, MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class));
}
use of org.springframework.messaging.MessageHeaders in project spring-framework by spring-projects.
the class MessageHeaderAccessorTests method idTimestampWithMutableHeaders.
@Test
public void idTimestampWithMutableHeaders() {
MessageHeaderAccessor accessor = new MessageHeaderAccessor();
accessor.setIdGenerator(() -> MessageHeaders.ID_VALUE_NONE);
accessor.setEnableTimestamp(false);
accessor.setLeaveMutable(true);
MessageHeaders headers = accessor.getMessageHeaders();
assertNull(headers.getId());
assertNull(headers.getTimestamp());
final UUID id = new UUID(0L, 23L);
accessor.setIdGenerator(() -> id);
accessor.setEnableTimestamp(true);
accessor.setImmutable();
assertSame(id, accessor.getMessageHeaders().getId());
assertNotNull(headers.getTimestamp());
}
use of org.springframework.messaging.MessageHeaders 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.MessageHeaders in project spring-security by spring-projects.
the class SimpMessageTypeMatcher method matches.
public boolean matches(Message<? extends Object> message) {
MessageHeaders headers = message.getHeaders();
SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers);
return typeToMatch == messageType;
}
Aggregations