public class SimpleMessageConverter extends 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 javax.jms.BytesMessage |
createMessageForByteArray(byte[] bytes,
javax.jms.Session session)
Create a JMS BytesMessage for the given byte array.
|
protected javax.jms.MapMessage |
createMessageForMap(Map<?,?> map,
javax.jms.Session session)
Create a JMS MapMessage for the given Map.
|
protected javax.jms.ObjectMessage |
createMessageForSerializable(Serializable object,
javax.jms.Session session)
Create a JMS ObjectMessage for the given Serializable object.
|
protected javax.jms.TextMessage |
createMessageForString(String text,
javax.jms.Session session)
Create a JMS TextMessage for the given String.
|
protected byte[] |
extractByteArrayFromMessage(javax.jms.BytesMessage message)
Extract a byte array from the given
BytesMessage . |
protected Map |
extractMapFromMessage(javax.jms.MapMessage message)
Extract a Map from the given
MapMessage . |
protected Serializable |
extractSerializableFromMessage(javax.jms.ObjectMessage message)
Extract a Serializable object from the given
ObjectMessage . |
protected String |
extractStringFromMessage(javax.jms.TextMessage message)
Extract a String from the given TextMessage.
|
Object |
fromMessage(javax.jms.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.
|
javax.jms.Message |
toMessage(Object object,
javax.jms.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 javax.jms.Message toMessage(Object object, javax.jms.Session session) throws javax.jms.JMSException, MessageConversionException
toMessage
in interface MessageConverter
object
- the object to convertsession
- the Session to use for creating a JMS Messagejavax.jms.JMSException
- 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 Object fromMessage(javax.jms.Message message) throws javax.jms.JMSException, MessageConversionException
fromMessage
in interface MessageConverter
message
- the message to convertjavax.jms.JMSException
- 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 javax.jms.TextMessage createMessageForString(String text, javax.jms.Session session) throws javax.jms.JMSException
text
- the String to convertsession
- current JMS sessionjavax.jms.JMSException
- if thrown by JMS methodsSession.createTextMessage()
protected javax.jms.BytesMessage createMessageForByteArray(byte[] bytes, javax.jms.Session session) throws javax.jms.JMSException
bytes
- the byyte array to convertsession
- current JMS sessionjavax.jms.JMSException
- if thrown by JMS methodsSession.createBytesMessage()
protected javax.jms.MapMessage createMessageForMap(Map<?,?> map, javax.jms.Session session) throws javax.jms.JMSException
map
- the Map to convertsession
- current JMS sessionjavax.jms.JMSException
- if thrown by JMS methodsSession.createMapMessage()
protected javax.jms.ObjectMessage createMessageForSerializable(Serializable object, javax.jms.Session session) throws javax.jms.JMSException
object
- the Serializable object to convertsession
- current JMS sessionjavax.jms.JMSException
- if thrown by JMS methodsSession.createObjectMessage()
protected String extractStringFromMessage(javax.jms.TextMessage message) throws javax.jms.JMSException
message
- the message to convertjavax.jms.JMSException
- if thrown by JMS methodsprotected byte[] extractByteArrayFromMessage(javax.jms.BytesMessage message) throws javax.jms.JMSException
BytesMessage
.message
- the message to convertjavax.jms.JMSException
- if thrown by JMS methodsprotected Map extractMapFromMessage(javax.jms.MapMessage message) throws javax.jms.JMSException
MapMessage
.message
- the message to convertjavax.jms.JMSException
- if thrown by JMS methodsprotected Serializable extractSerializableFromMessage(javax.jms.ObjectMessage message) throws javax.jms.JMSException
ObjectMessage
.message
- the message to convertjavax.jms.JMSException
- if thrown by JMS methodsCopyright © 2015. All rights reserved.