Package org.springframework.messaging.converter

Examples of org.springframework.messaging.converter.CompositeMessageConverter


    }
    if (CollectionUtils.isEmpty(targetMimeTypeConverters)) {
      throw new ConversionException("No message converter is registered for "
          + targetMimeType.toString());
    }
    return new CompositeMessageConverter(targetMimeTypeConverters);
  }
View Full Code Here


    ModuleTypeConversionPlugin plugin = context.getBean(ModuleTypeConversionPlugin.class);

    CompositeMessageConverterFactory factory = (CompositeMessageConverterFactory) TestUtils.getPropertyValue(
        plugin, "converterFactory");
    CompositeMessageConverter converters = factory.newInstance(MimeType.valueOf("application/x-xd-foo"));
    assertEquals(1, converters.getConverters().size());
    assertTrue(converters.getConverters().iterator().next() instanceof StubPojoToStringConverter);
  }
View Full Code Here

  }

  @Test
  public void testPojoToJsonString() {
    String json = "{\"foo\":\"bar\"}";
    CompositeMessageConverter converter = converterFactory.newInstance(MimeTypeUtils.APPLICATION_JSON);
    Message<?> msg = (Message<?>) converter.fromMessage(new GenericMessage<Foo>(new Foo()), String.class);
    assertEquals(json, msg.getPayload());
    assertEquals(MimeTypeUtils.APPLICATION_JSON, msg.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  }

  @Test
  public void testObjectToString() {
    String text = "[bar]";
    CompositeMessageConverter converter = converterFactory.newInstance(MimeTypeUtils.TEXT_PLAIN);
    Message<?> msg = (Message<?>) converter.fromMessage(new GenericMessage<Foo>(new Foo()), String.class);
    assertEquals(text, msg.getPayload());
    assertEquals(MimeTypeUtils.TEXT_PLAIN, msg.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @Test
  public void testJsonStringToPojo() {
    String json = "{\"foo\":\"bar\"}";
    Message<?> msg = MessageBuilder.withPayload(json)
        .build();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/x-java-object"));
    Message<?> result = (Message<?>) converter.fromMessage(msg, Foo.class);
    Foo foo = (Foo) result.getPayload();
    assertEquals("bar", foo.getFoo());
    assertEquals(MimeType.valueOf("application/x-java-object;type=" + foo.getClass().getName()),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public void testJsonStringToMap() {
    String json = "{\"foo\":\"bar\"}";
    Message<?> msg = MessageBuilder.withPayload(json)
        .build();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/x-java-object"));
    Message<Map<String, String>> result = (Message<Map<String, String>>) converter.fromMessage(msg, HashMap.class);
    Map<String, String> map = result.getPayload();
    assertEquals("bar", map.get("foo"));
    assertEquals(MimeType.valueOf("application/x-java-object;type=" + HashMap.class.getName()),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

    String json = "{\"foo\":\"bar\"}";

    Message<?> msg = MessageBuilder.withPayload(json).copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON))
        .build();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/x-java-object"));

    Message<?> result = (Message<?>) converter.fromMessage(msg, Foo.class);
    Foo foo = (Foo) result.getPayload();
    assertEquals("bar", foo.getFoo());
    assertEquals(MimeType.valueOf("application/x-java-object;type=" + foo.getClass().getName()),
        result.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  }

  @Test
  public void testJsonStringWithWrongContentTypeHeaderReturnsNull() {
    String json = "{\"foo\":\"bar\"}";
    CompositeMessageConverter converter = converterFactory.newInstance(MimeTypeUtils.APPLICATION_JSON);

    Message<?> msg = MessageBuilder.withPayload(json).copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_XML))
        .build();

    Message<?> result = (Message<?>) converter.fromMessage(msg, Foo.class);
    assertNull(result);
  }
View Full Code Here

  @Test
  public void testByteArrayToString() {
    String json = "{\"foo\":\"bar\"}";
    Message<?> msg = MessageBuilder.withPayload(json.getBytes()).build();
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("text/plain"));

    Object result = converter.fromMessage(msg, String.class);
    assertEquals(json, result);
  }
View Full Code Here

  }

  @Test
  public void testByteArrayToStringWithCharset() throws UnsupportedEncodingException {
    String text = "Hello \u3044\u3002";
    CompositeMessageConverter converter = converterFactory.newInstance(MimeType.valueOf("application/x-xd-string"));
    Message<?> msg = MessageBuilder.withPayload(text.getBytes("UTF-8")).copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeType.valueOf("text/plain;Charset=UTF-8")))
        .build();

    Object result = converter.fromMessage(msg, String.class);
    assertEquals(text, result);

    msg = MessageBuilder.withPayload(text.getBytes("ISO-8859-1")).copyHeaders(
        Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeType.valueOf("text/plain;Charset=ISO-8859-1")))
        .build();
    result = converter.fromMessage(msg, String.class);
    assertEquals("Hello ??", result);
  }
View Full Code Here

TOP

Related Classes of org.springframework.messaging.converter.CompositeMessageConverter

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.