Spring AMQP

org.springframework.amqp.support.converter
Class SimpleMessageConverter

java.lang.Object
  extended by org.springframework.amqp.support.converter.SimpleMessageConverter
All Implemented Interfaces:
MessageConverter, BeanClassLoaderAware

public class SimpleMessageConverter
extends Object
implements MessageConverter, BeanClassLoaderAware

Implementation of MessageConverter that can work with Strings, Serializable instances, or byte arrays. The toMessage(Object, MessageProperties) method simply checks the type of the provided instance while the fromMessage(Message) method relies upon the content-type of the provided Message.

Author:
Mark Fisher, Oleg Zhurakousky

Field Summary
static String DEFAULT_CHARSET
           
 
Constructor Summary
SimpleMessageConverter()
           
 
Method Summary
protected  ObjectInputStream createObjectInputStream(InputStream is, String codebaseUrl)
          Create an ObjectInputStream for the given InputStream and codebase.
 Object fromMessage(Message message)
          Converts from a AMQP Message to an Object.
 void setBeanClassLoader(ClassLoader beanClassLoader)
           
 void setCodebaseUrl(String codebaseUrl)
          Set the codebase URL to download classes from if not found locally.
 void setDefaultCharset(String defaultCharset)
          Specify the default charset to use when converting to or from text-based Message body content.
 Message toMessage(Object object, MessageProperties messageProperties)
          Creates an AMQP Message from the provided Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
See Also:
Constant Field Values
Constructor Detail

SimpleMessageConverter

public SimpleMessageConverter()
Method Detail

setBeanClassLoader

public void setBeanClassLoader(ClassLoader beanClassLoader)
Specified by:
setBeanClassLoader in interface BeanClassLoaderAware

setCodebaseUrl

public void setCodebaseUrl(String codebaseUrl)
Set the codebase URL to download classes from if not found locally. Can consists of multiple URLs, separated by spaces.

Follows RMI's codebase conventions for dynamic class download.

See Also:
CodebaseAwareObjectInputStream, RMIClassLoader

setDefaultCharset

public void setDefaultCharset(String defaultCharset)
Specify the default charset to use when converting to or from text-based Message body content. If not specified, the charset will be "UTF-8".


fromMessage

public Object fromMessage(Message message)
                   throws MessageConversionException
Converts from a AMQP Message to an Object.

Specified by:
fromMessage in interface MessageConverter
Parameters:
message - the message to convert
Returns:
the converted Java object
Throws:
MessageConversionException - in case of conversion failure

toMessage

public Message toMessage(Object object,
                         MessageProperties messageProperties)
                  throws MessageConversionException
Creates an AMQP Message from the provided Object.

Specified by:
toMessage in interface MessageConverter
Parameters:
object - the object to convert
Returns:
the Rabbit Message
Throws:
MessageConversionException - in case of conversion failure

createObjectInputStream

protected ObjectInputStream createObjectInputStream(InputStream is,
                                                    String codebaseUrl)
                                             throws IOException
Create an ObjectInputStream for the given InputStream and codebase. The default implementation creates a CodebaseAwareObjectInputStream.

Parameters:
is - the InputStream to read from
codebaseUrl - the codebase URL to load classes from if not found locally (can be null)
Returns:
the new ObjectInputStream instance to use
Throws:
IOException - if creation of the ObjectInputStream failed
See Also:
CodebaseAwareObjectInputStream

Spring AMQP

Copyright © 2010. All Rights Reserved.