public class SimpleMessageConverter extends java.lang.Object implements MessageConverter
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).
JmsTemplate.convertAndSend(java.lang.Object)
,
JmsTemplate.receiveAndConvert()
Constructor and Description |
---|
SimpleMessageConverter() |
Modifier and Type | Method and Description |
---|---|
protected BytesMessage |
createMessageForByteArray(byte[] bytes,
Session session)
Create a JMS BytesMessage for the given byte array.
|
protected MapMessage |
createMessageForMap(java.util.Map<?,?> map,
Session session)
Create a JMS MapMessage for the given Map.
|
protected ObjectMessage |
createMessageForSerializable(java.io.Serializable object,
Session session)
Create a JMS ObjectMessage for the given Serializable object.
|
protected TextMessage |
createMessageForString(java.lang.String text,
Session session)
Create a JMS TextMessage for the given String.
|
protected byte[] |
extractByteArrayFromMessage(BytesMessage message)
Extract a byte array from the given
BytesMessage . |
protected java.util.Map<java.lang.String,java.lang.Object> |
extractMapFromMessage(MapMessage message)
Extract a Map from the given
MapMessage . |
protected java.io.Serializable |
extractSerializableFromMessage(ObjectMessage message)
Extract a Serializable object from the given
ObjectMessage . |
protected java.lang.String |
extractStringFromMessage(TextMessage message)
Extract a String from the given TextMessage.
|
java.lang.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(java.lang.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.
|
public Message toMessage(java.lang.Object object, Session session) throws JMSException, MessageConversionException
toMessage
in interface MessageConverter
object
- the object to convertsession
- the Session to use for creating a JMS MessageJMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failurecreateMessageForString(java.lang.String, javax.jms.Session)
,
createMessageForByteArray(byte[], javax.jms.Session)
,
createMessageForMap(java.util.Map<?, ?>, javax.jms.Session)
,
createMessageForSerializable(java.io.Serializable, javax.jms.Session)
public java.lang.Object fromMessage(Message message) throws JMSException, MessageConversionException
fromMessage
in interface MessageConverter
message
- the message to convertJMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failureextractStringFromMessage(javax.jms.TextMessage)
,
extractByteArrayFromMessage(javax.jms.BytesMessage)
,
extractMapFromMessage(javax.jms.MapMessage)
,
extractSerializableFromMessage(javax.jms.ObjectMessage)
protected TextMessage createMessageForString(java.lang.String text, Session session) throws JMSException
text
- the String to convertsession
- current JMS sessionJMSException
- if thrown by JMS methodsSession.createTextMessage()
protected BytesMessage createMessageForByteArray(byte[] bytes, Session session) throws JMSException
bytes
- the byte array to convertsession
- current JMS sessionJMSException
- if thrown by JMS methodsSession.createBytesMessage()
protected MapMessage createMessageForMap(java.util.Map<?,?> map, Session session) throws JMSException
map
- the Map to convertsession
- current JMS sessionJMSException
- if thrown by JMS methodsSession.createMapMessage()
protected ObjectMessage createMessageForSerializable(java.io.Serializable object, Session session) throws JMSException
object
- the Serializable object to convertsession
- current JMS sessionJMSException
- if thrown by JMS methodsSession.createObjectMessage()
protected java.lang.String extractStringFromMessage(TextMessage message) throws JMSException
message
- the message to convertJMSException
- if thrown by JMS methodsprotected byte[] extractByteArrayFromMessage(BytesMessage message) throws JMSException
BytesMessage
.message
- the message to convertJMSException
- if thrown by JMS methodsprotected java.util.Map<java.lang.String,java.lang.Object> extractMapFromMessage(MapMessage message) throws JMSException
MapMessage
.message
- the message to convertJMSException
- if thrown by JMS methodsprotected java.io.Serializable extractSerializableFromMessage(ObjectMessage message) throws JMSException
ObjectMessage
.message
- the message to convertJMSException
- if thrown by JMS methods