Search in sources :

Example 11 with MessageHeaders

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

the class MessageConverterTests method toMessageWithHeaders.

@Test
public void toMessageWithHeaders() {
    Map<String, Object> map = new HashMap<>();
    map.put("foo", "bar");
    MessageHeaders headers = new MessageHeaders(map);
    Message<?> message = this.converter.toMessage("ABC", headers);
    assertNotNull(message.getHeaders().getId());
    assertNotNull(message.getHeaders().getTimestamp());
    assertEquals(MimeTypeUtils.TEXT_PLAIN, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    assertEquals("bar", message.getHeaders().get("foo"));
}
Also used : HashMap(java.util.HashMap) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 12 with MessageHeaders

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

the class MessageConverterTests method toMessageWithMutableMessageHeaders.

@Test
public void toMessageWithMutableMessageHeaders() {
    SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
    accessor.setHeader("foo", "bar");
    accessor.setNativeHeader("fooNative", "barNative");
    accessor.setLeaveMutable(true);
    MessageHeaders headers = accessor.getMessageHeaders();
    Message<?> message = this.converter.toMessage("ABC", headers);
    assertSame(headers, message.getHeaders());
    assertNull(message.getHeaders().getId());
    assertNull(message.getHeaders().getTimestamp());
    assertEquals(MimeTypeUtils.TEXT_PLAIN, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) Test(org.junit.Test)

Example 13 with MessageHeaders

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

the class SimpleMessageConverterTests method toMessageWithPayloadAndHeaders.

@Test
public void toMessageWithPayloadAndHeaders() {
    MessageHeaders headers = new MessageHeaders(Collections.<String, Object>singletonMap("foo", "bar"));
    Message<?> message = this.converter.toMessage("payload", headers);
    assertEquals("payload", message.getPayload());
    assertEquals("bar", message.getHeaders().get("foo"));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 14 with MessageHeaders

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

the class GenericMessagingTemplateTests method convertAndSendWithSimpMessageHeaders.

@Test
public void convertAndSendWithSimpMessageHeaders() {
    MessageHeaderAccessor accessor = new MessageHeaderAccessor();
    accessor.setHeader("key", "value");
    accessor.setLeaveMutable(true);
    MessageHeaders headers = accessor.getMessageHeaders();
    this.template.convertAndSend("channel", "data", headers);
    List<Message<byte[]>> messages = this.messageChannel.getMessages();
    Message<byte[]> message = messages.get(0);
    assertSame(headers, message.getHeaders());
    assertFalse(accessor.isMutable());
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 15 with MessageHeaders

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

the class DefaultContentTypeResolverTests method resolveInvalidStringContentType.

@Test(expected = InvalidMimeTypeException.class)
public void resolveInvalidStringContentType() {
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, "invalidContentType");
    MessageHeaders headers = new MessageHeaders(map);
    this.resolver.resolve(headers);
}
Also used : HashMap(java.util.HashMap) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

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