Search in sources :

Example 16 with MessageHeaders

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

the class DefaultContentTypeResolverTests method resolve.

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

Example 17 with MessageHeaders

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

the class DefaultContentTypeResolverTests method resolveStringContentType.

@Test
public void resolveStringContentType() {
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON_VALUE);
    MessageHeaders headers = new MessageHeaders(map);
    assertEquals(MimeTypeUtils.APPLICATION_JSON, this.resolver.resolve(headers));
}
Also used : HashMap(java.util.HashMap) MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 18 with MessageHeaders

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

the class DefaultContentTypeResolverTests method resolveDefaultMimeType.

@Test
public void resolveDefaultMimeType() {
    this.resolver.setDefaultMimeType(MimeTypeUtils.APPLICATION_JSON);
    MessageHeaders headers = new MessageHeaders(Collections.<String, Object>emptyMap());
    assertEquals(MimeTypeUtils.APPLICATION_JSON, this.resolver.resolve(headers));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) Test(org.junit.Test)

Example 19 with MessageHeaders

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

the class MappingJackson2MessageConverterTests method toMessageUtf16String.

@Test
public void toMessageUtf16String() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setSerializedPayloadClass(String.class);
    MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, contentType);
    MessageHeaders headers = new MessageHeaders(map);
    String payload = "Héllo Wörld";
    Message<?> message = converter.toMessage(payload, headers);
    assertEquals("\"" + payload + "\"", message.getPayload());
    assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
Also used : HashMap(java.util.HashMap) MessageHeaders(org.springframework.messaging.MessageHeaders) MimeType(org.springframework.util.MimeType) Test(org.junit.Test)

Example 20 with MessageHeaders

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

the class MessageHeaderAccessorTests method existingHeaders.

@Test
public void existingHeaders() throws InterruptedException {
    Map<String, Object> map = new HashMap<>();
    map.put("foo", "bar");
    map.put("bar", "baz");
    GenericMessage<String> message = new GenericMessage<>("payload", map);
    MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
    MessageHeaders actual = accessor.getMessageHeaders();
    assertEquals(3, actual.size());
    assertEquals("bar", actual.get("foo"));
    assertEquals("baz", actual.get("bar"));
}
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