Search in sources :

Example 26 with MessageHeaders

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));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 27 with MessageHeaders

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));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 28 with MessageHeaders

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());
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) UUID(java.util.UUID) Test(org.junit.Test)

Example 29 with MessageHeaders

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());
}
Also used : StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 30 with MessageHeaders

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;
}
Also used : SimpMessageType(org.springframework.messaging.simp.SimpMessageType) MessageHeaders(org.springframework.messaging.MessageHeaders)

Aggregations

MessageHeaders (org.springframework.messaging.MessageHeaders)54 Test (org.junit.Test)39 HashMap (java.util.HashMap)15 Message (org.springframework.messaging.Message)9 SimpMessageType (org.springframework.messaging.simp.SimpMessageType)6 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)5 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 MimeType (org.springframework.util.MimeType)3 Principal (java.security.Principal)2 HashSet (java.util.HashSet)2 MessageConverter (org.springframework.messaging.converter.MessageConverter)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 TestPrincipal (org.springframework.messaging.simp.TestPrincipal)2 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Method (java.lang.reflect.Method)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1