public class

SimpleMessageConverter

extends Object
implements MessageConverter
java.lang.Object
   ↳ org.springframework.jms.support.converter.SimpleMessageConverter
Known Direct Subclasses

Class Overview

A simple message converter which is able to handle TextMessages, BytesMessages, MapMessages, and ObjectMessages. Used as default conversion strategy by JmsTemplate, for convertAndSend and receiveAndConvert operations.

Converts a String to a javax.jms.TextMessage, a byte array to a javax.jms.BytesMessage, a Map to a javax.jms.MapMessage, and a Serializable object to a javax.jms.ObjectMessage (or vice versa).

Summary

Public Constructors
SimpleMessageConverter()
Public Methods
Object fromMessage(Message message)
This implementation converts a TextMessage back to a String, a ByteMessage back to a byte array, a MapMessage back to a Map, and an ObjectMessage back to a Serializable object.
Message toMessage(Object object, Session session)
This implementation creates a TextMessage for a String, a BytesMessage for a byte array, a MapMessage for a Map, and an ObjectMessage for a Serializable object.
Protected Methods
BytesMessage createMessageForByteArray(byte[] bytes, Session session)
Create a JMS BytesMessage for the given byte array.
MapMessage createMessageForMap(Map<?, ?> map, Session session)
Create a JMS MapMessage for the given Map.
ObjectMessage createMessageForSerializable(Serializable object, Session session)
Create a JMS ObjectMessage for the given Serializable object.
TextMessage createMessageForString(String text, Session session)
Create a JMS TextMessage for the given String.
byte[] extractByteArrayFromMessage(BytesMessage message)
Extract a byte array from the given BytesMessage.
Map extractMapFromMessage(MapMessage message)
Extract a Map from the given MapMessage.
Serializable extractSerializableFromMessage(ObjectMessage message)
Extract a Serializable object from the given ObjectMessage.
String extractStringFromMessage(TextMessage message)
Extract a String from the given TextMessage.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.jms.support.converter.MessageConverter

Public Constructors

public SimpleMessageConverter ()

Public Methods

public Object fromMessage (Message message)

This implementation converts a TextMessage back to a String, a ByteMessage back to a byte array, a MapMessage back to a Map, and an ObjectMessage back to a Serializable object. Returns the plain Message object in case of an unknown message type.

Parameters
message the message to convert
Returns
  • the converted Java object
Throws
JMSException
MessageConversionException

public Message toMessage (Object object, Session session)

This implementation creates a TextMessage for a String, a BytesMessage for a byte array, a MapMessage for a Map, and an ObjectMessage for a Serializable object.

Parameters
object the object to convert
session the Session to use for creating a JMS Message
Returns
  • the JMS Message
Throws
JMSException
MessageConversionException

Protected Methods

protected BytesMessage createMessageForByteArray (byte[] bytes, Session session)

Create a JMS BytesMessage for the given byte array.

Parameters
bytes the byyte array to convert
session current JMS session
Returns
  • the resulting message
Throws
if thrown by JMS methods
JMSException
See Also
  • javax.jms.Session#createBytesMessage

protected MapMessage createMessageForMap (Map<?, ?> map, Session session)

Create a JMS MapMessage for the given Map.

Parameters
map the Map to convert
session current JMS session
Returns
  • the resulting message
Throws
if thrown by JMS methods
JMSException
See Also
  • javax.jms.Session#createMapMessage

protected ObjectMessage createMessageForSerializable (Serializable object, Session session)

Create a JMS ObjectMessage for the given Serializable object.

Parameters
object the Serializable object to convert
session current JMS session
Returns
  • the resulting message
Throws
if thrown by JMS methods
JMSException
See Also
  • javax.jms.Session#createObjectMessage

protected TextMessage createMessageForString (String text, Session session)

Create a JMS TextMessage for the given String.

Parameters
text the String to convert
session current JMS session
Returns
  • the resulting message
Throws
if thrown by JMS methods
JMSException
See Also
  • javax.jms.Session#createTextMessage

protected byte[] extractByteArrayFromMessage (BytesMessage message)

Extract a byte array from the given BytesMessage.

Parameters
message the message to convert
Returns
  • the resulting byte array
Throws
if thrown by JMS methods
JMSException

protected Map extractMapFromMessage (MapMessage message)

Extract a Map from the given MapMessage.

Parameters
message the message to convert
Returns
  • the resulting Map
Throws
if thrown by JMS methods
JMSException

protected Serializable extractSerializableFromMessage (ObjectMessage message)

Extract a Serializable object from the given ObjectMessage.

Parameters
message the message to convert
Returns
  • the resulting Serializable object
Throws
if thrown by JMS methods
JMSException

protected String extractStringFromMessage (TextMessage message)

Extract a String from the given TextMessage.

Parameters
message the message to convert
Returns
  • the resulting String
Throws
if thrown by JMS methods
JMSException