Package org.springframework.util

Examples of org.springframework.util.MimeType$SpecificityComparator


  }

  protected final Message<?> deserializePayloadIfNecessary(Message<?> message) {
    Message<?> messageToSend = message;
    Object originalPayload = message.getPayload();
    MimeType contentType = contentTypeResolver.resolve(message.getHeaders());
    Object payload = deserializePayload(originalPayload, contentType);
    if (payload != null) {
      MessageBuilder<Object> transformed = MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders());
      Object originalContentType = message.getHeaders().get(ORIGINAL_CONTENT_TYPE_HEADER);
      transformed.setHeader(MessageHeaders.CONTENT_TYPE, originalContentType);
View Full Code Here


    if (logger.isDebugEnabled()) {
      logger.debug("module " + (isInput ? "input" : "output") + "Type is " + contentTypeString);
    }
    SimpleModule sm = (SimpleModule) module;
    try {
      MimeType contentType = resolveContentType(contentTypeString, module);

      AbstractMessageChannel channel = getChannel(module, isInput);

      CompositeMessageConverter converters = null;
      try {
View Full Code Here

  /**
   * Don't need to manipulate message headers. Just return the payload
   */
  @Override
  public Object convertFromInternal(Message<?> message, Class<?> targetClass) {
    MimeType mimeType = contentTypeResolver.resolve(message.getHeaders());
    byte[] converted = null;
    if (mimeType == null || mimeType.getParameter("Charset") == null) {
      converted = ((String) message.getPayload()).getBytes();
    }
    else {
      String encoding = mimeType.getParameter("Charset");
      if (encoding != null) {
        try {
          converted = ((String) message.getPayload()).getBytes(encoding);
        }
        catch (UnsupportedEncodingException e) {
View Full Code Here

  /**
   * Don't need to manipulate message headers. Just return payload
   */
  @Override
  public Object convertFromInternal(Message<?> message, Class<?> targetClass) {
    MimeType mimeType = contentTypeResolver.resolve(message.getHeaders());

    String converted = null;

    if (mimeType == null || mimeType.getParameter("Charset") == null) {
      converted = new String((byte[]) message.getPayload());
    }
    else {
      String encoding = mimeType.getParameter("Charset");
      if (encoding != null) {
        try {
          converted = new String((byte[]) message.getPayload(), encoding);
        }
        catch (UnsupportedEncodingException e) {
View Full Code Here

  @Test
  public void testPojoSerialization() {
    Message<?> converted = messageBus.serializePayloadIfNecessary(
        new GenericMessage<Foo>(new Foo("bar")),
        MimeTypeUtils.APPLICATION_OCTET_STREAM);
    MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
    assertEquals("application", mimeType.getType());
    assertEquals("x-java-object", mimeType.getSubtype());
    assertEquals(Foo.class.getName(), mimeType.getParameter("type"));

    Message<?> reconstructed = messageBus.deserializePayloadIfNecessary(converted);
    assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
    assertNull(reconstructed.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @Test
  public void testPojoWithXJavaObjectMimeTypeNoType() {
    Message<?> converted = messageBus.serializePayloadIfNecessary(
        new GenericMessage<Foo>(new Foo("bar")),
        MimeTypeUtils.APPLICATION_OCTET_STREAM);
    MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
    assertEquals("application", mimeType.getType());
    assertEquals("x-java-object", mimeType.getSubtype());
    assertEquals(Foo.class.getName(), mimeType.getParameter("type"));

    Message<?> reconstructed = messageBus.deserializePayloadIfNecessary(converted);
    assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
    assertNull(reconstructed.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @Test
  public void testPojoWithXJavaObjectMimeTypeExplicitType() {
    Message<?> converted = messageBus.serializePayloadIfNecessary(
        new GenericMessage<Foo>(new Foo("bar")),
        MimeTypeUtils.APPLICATION_OCTET_STREAM);
    MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
    assertEquals("application", mimeType.getType());
    assertEquals("x-java-object", mimeType.getSubtype());
    assertEquals(Foo.class.getName(), mimeType.getParameter("type"));

    Message<?> reconstructed = messageBus.deserializePayloadIfNecessary(converted);
    assertEquals("bar", ((Foo) reconstructed.getPayload()).getBar());
    assertNull(reconstructed.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

  @Test
  public void testTupleSerialization() {
    Tuple payload = TupleBuilder.tuple().of("foo", "bar");
    Message<?> converted = messageBus.serializePayloadIfNecessary(new GenericMessage<Tuple>(payload),
        MimeTypeUtils.APPLICATION_OCTET_STREAM);
    MimeType mimeType = contentTypeResolver.resolve(converted.getHeaders());
    assertEquals("application", mimeType.getType());
    assertEquals("x-java-object", mimeType.getSubtype());
    assertEquals(DefaultTuple.class.getName(), mimeType.getParameter("type"));

    Message<?> reconstructed = messageBus.deserializePayloadIfNecessary(converted);
    assertEquals("bar", ((Tuple) reconstructed.getPayload()).getString("foo"));
    assertNull(reconstructed.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }
View Full Code Here

    assertNull(reconstructed.getHeaders().get(MessageHeaders.CONTENT_TYPE));
  }

  @Test
  public void mimeTypeIsSimpleObject() throws ClassNotFoundException {
    MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new Object());
    String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
    assertEquals(Object.class, Class.forName(className));
  }
View Full Code Here

    assertEquals(Object.class, Class.forName(className));
  }

  @Test
  public void mimeTypeIsObjectArray() throws ClassNotFoundException {
    MimeType mt = JavaClassMimeTypeConversion.mimeTypeFromObject(new String[0]);
    String className = JavaClassMimeTypeConversion.classNameFromMimeType(mt);
    assertEquals(String[].class, Class.forName(className));
  }
View Full Code Here

TOP

Related Classes of org.springframework.util.MimeType$SpecificityComparator

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.