Class SimpleMessageConverter
java.lang.Object
org.springframework.jms.support.converter.SimpleMessageConverter
- All Implemented Interfaces:
MessageConverter
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 TextMessage, a byte array to a
BytesMessage, a Map to a MapMessage, and
a Serializable object to a ObjectMessage (or vice versa).
- Since:
- 1.1
- Author:
- Juergen Hoeller, Sam Brannen
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected BytesMessagecreateMessageForByteArray(byte[] bytes, Session session) Create a JMS BytesMessage for the given byte array.protected MapMessagecreateMessageForMap(Map<?, ?> map, Session session) Create a JMS MapMessage for the given Map.protected ObjectMessagecreateMessageForSerializable(Serializable object, Session session) Create a JMS ObjectMessage for the given Serializable object.protected TextMessagecreateMessageForString(String text, Session session) Create a JMS TextMessage for the given String.protected byte[]extractByteArrayFromMessage(BytesMessage message) Extract a byte array from the givenBytesMessage.extractMapFromMessage(MapMessage message) Extract a Map from the givenMapMessage.protected SerializableExtract a Serializable object from the givenObjectMessage.protected StringextractStringFromMessage(TextMessage message) Extract a String from the given TextMessage.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.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.
-
Constructor Details
-
SimpleMessageConverter
public SimpleMessageConverter()
-
-
Method Details
-
toMessage
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException 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.- Specified by:
toMessagein interfaceMessageConverter- Parameters:
object- the object to convertsession- the Session to use for creating a JMS Message- Returns:
- the JMS Message
- Throws:
JMSException- if thrown by JMS API methodsMessageConversionException- in case of conversion failure- See Also:
-
fromMessage
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.- Specified by:
fromMessagein interfaceMessageConverter- Parameters:
message- the message to convert- Returns:
- the converted Java object
- Throws:
JMSException- if thrown by JMS API methodsMessageConversionException- in case of conversion failure- See Also:
-
createMessageForString
Create a JMS TextMessage for the given String.- Parameters:
text- the String to convertsession- current JMS session- Returns:
- the resulting message
- Throws:
JMSException- if thrown by JMS methods- See Also:
-
createMessageForByteArray
Create a JMS BytesMessage for the given byte array.- Parameters:
bytes- the byte array to convertsession- current JMS session- Returns:
- the resulting message
- Throws:
JMSException- if thrown by JMS methods- See Also:
-
createMessageForMap
Create a JMS MapMessage for the given Map.- Parameters:
map- the Map to convertsession- current JMS session- Returns:
- the resulting message
- Throws:
JMSException- if thrown by JMS methods- See Also:
-
createMessageForSerializable
protected ObjectMessage createMessageForSerializable(Serializable object, Session session) throws JMSException Create a JMS ObjectMessage for the given Serializable object.- Parameters:
object- the Serializable object to convertsession- current JMS session- Returns:
- the resulting message
- Throws:
JMSException- if thrown by JMS methods- See Also:
-
extractStringFromMessage
Extract a String from the given TextMessage.- Parameters:
message- the message to convert- Returns:
- the resulting String
- Throws:
JMSException- if thrown by JMS methods
-
extractByteArrayFromMessage
Extract a byte array from the givenBytesMessage.- Parameters:
message- the message to convert- Returns:
- the resulting byte array
- Throws:
JMSException- if thrown by JMS methods
-
extractMapFromMessage
Extract a Map from the givenMapMessage.- Parameters:
message- the message to convert- Returns:
- the resulting Map
- Throws:
JMSException- if thrown by JMS methods
-
extractSerializableFromMessage
Extract a Serializable object from the givenObjectMessage.- Parameters:
message- the message to convert- Returns:
- the resulting Serializable object
- Throws:
JMSException- if thrown by JMS methods
-