Package org.springframework.messaging

Examples of org.springframework.messaging.MessageHeaders


    assertNull(this.converter.toMessage(null, null));
  }

  @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"));
  }
View Full Code Here


  @Test
  public void toMessageWithPayloadAndMutableHeaders() {
    MessageHeaderAccessor accessor = new MessageHeaderAccessor();
    accessor.setHeader("foo", "bar");
    accessor.setLeaveMutable(true);
    MessageHeaders headers = accessor.getMessageHeaders();

    Message<?> message = this.converter.toMessage("payload", headers);

    assertEquals("payload", message.getPayload());
    assertSame(headers, message.getHeaders());
View Full Code Here

  @Test
  public void toMessage() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN);
    MessageHeaders headers = new MessageHeaders(map);
    Message<?> message = this.converter.toMessage("ABC", headers);

    assertEquals("ABC", new String(((byte[]) message.getPayload())));
  }
View Full Code Here

  public void toMessageUtf16() {
    Charset utf16 = Charset.forName("UTF-16BE");
    MimeType contentType = new MimeType("application", "json", utf16);
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, contentType);
    MessageHeaders headers = new MessageHeaders(map);
    String payload = "H\u00e9llo W\u00f6rld";
    Message<?> message = this.converter.toMessage(payload, headers);

    assertEquals("\"" + payload + "\"", new String((byte[]) message.getPayload(), utf16));
    assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
View Full Code Here

    Charset utf16 = Charset.forName("UTF-16BE");
    MimeType contentType = new MimeType("application", "json", utf16);
    Map<String, Object> map = new HashMap<>();
    map.put(MessageHeaders.CONTENT_TYPE, contentType);
    MessageHeaders headers = new MessageHeaders(map);
    String payload = "H\u00e9llo W\u00f6rld";
    Message<?> message = this.converter.toMessage(payload, headers);

    assertEquals("\"" + payload + "\"", message.getPayload());
    assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
View Full Code Here

  @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);
View Full Code Here

  @Test
  public void convertAndSendPayloadAndMutableHeadersToDestination() {
    MessageHeaderAccessor accessor = new MessageHeaderAccessor();
    accessor.setHeader("foo", "bar");
    accessor.setLeaveMutable(true);
    MessageHeaders messageHeaders = accessor.getMessageHeaders();

    this.template.setMessageConverter(new StringMessageConverter());
    this.template.convertAndSend("somewhere", "payload", messageHeaders);

    MessageHeaders actual = this.template.message.getHeaders();
    assertSame(messageHeaders, actual);
    assertEquals(new MimeType("text", "plain", Charset.forName("UTF-8")), actual.get(MessageHeaders.CONTENT_TYPE));
    assertEquals("bar", actual.get("foo"));
  }
View Full Code Here

    MessageConverter converter = new CompositeMessageConverter(
        Arrays.<MessageConverter>asList(new MappingJackson2MessageConverter()));
    this.template.setMessageConverter(converter);

    this.headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML);
    this.template.convertAndSend("home", "payload", new MessageHeaders(this.headers));
  }
View Full Code Here

  }

  @Test
  public void messageIdAndTimestampDefaultBehavior() {
    StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.SEND);
    MessageHeaders headers = headerAccessor.getMessageHeaders();

    assertNull(headers.getId());
    assertNull(headers.getTimestamp());
  }
View Full Code Here

  @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));
  }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.MessageHeaders

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.