Package org.springframework.messaging.converter

Examples of org.springframework.messaging.converter.CompositeMessageConverter.fromMessage()


  public void testTupleToJson() {
    Tuple t = TupleBuilder.fromString("{\"foo\":\"bar\"}");
    Message<?> msg = MessageBuilder.withPayload(t).build();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeTypeUtils.APPLICATION_JSON);

    Message<String> result = (Message<String>) converter.fromMessage(msg, String.class);
    assertTrue(result.getPayload(), result.getPayload().contains("\"foo\":\"bar\""));
    assertEquals(MimeTypeUtils.APPLICATION_JSON,
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here


  public void testJavaSerialization() {
    Foo foo = new Foo();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/x-java-serialized-object"));
    Message<Foo> msg = MessageBuilder.withPayload(foo).copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeType.valueOf("application/x-java-object"))).build();
    Message<?> result = (Message<?>) converter.fromMessage(msg, byte[].class);
    assertTrue(result.getPayload() instanceof byte[]);
    assertEquals(MimeType.valueOf("application/x-java-serialized-object"),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));

    // Now convert back
View Full Code Here

    assertEquals(MimeType.valueOf("application/x-java-serialized-object"),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));

    // Now convert back
    converter = converterFactory.newInstance(MimeType.valueOf("application/x-java-object"));
    result = (Message<?>) converter.fromMessage(result, Foo.class);
    assertNotNull(result);
    assertTrue(result.getPayload() instanceof Foo);
    assertEquals(MimeType.valueOf("application/x-java-object;type=" + Foo.class.getName()),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @Test
  public void testStringToByteArray() throws UnsupportedEncodingException {
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/octet-stream"));
    Message<String> msg = MessageBuilder.withPayload("hello").copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeType.valueOf("text/plain;charset=UTF-8"))).build();
    byte[] result = (byte[]) converter.fromMessage(msg, byte[].class);
    assertEquals("hello", new String(result, "UTF-8"));
  }
}

View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.