类 SimpleMessageConverter
- java.lang.Object
- org.springframework.jms.support.converter.SimpleMessageConverter
- 所有已实现的接口:
MessageConverter
public class SimpleMessageConverter extends Object implements MessageConverter
A simple message converter which is able to handle TextMessages, BytesMessages, MapMessages, and ObjectMessages. Used as default conversion strategy byJmsTemplate
, forconvertAndSend
andreceiveAndConvert
operations.Converts a String to a
TextMessage
, a byte array to aBytesMessage
, a Map to aMapMessage
, and a Serializable object to aObjectMessage
(or vice versa).- 从以下版本开始:
- 1.1
- 作者:
- Juergen Hoeller
- 另请参阅:
JmsTemplate.convertAndSend(java.lang.Object)
,JmsTemplate.receiveAndConvert()
构造器概要
构造器 构造器 说明 SimpleMessageConverter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected BytesMessage
createMessageForByteArray(byte[] bytes, Session session)
Create a JMS BytesMessage for the given byte array.protected MapMessage
createMessageForMap(Map<?,?> map, Session session)
Create a JMS MapMessage for the given Map.protected ObjectMessage
createMessageForSerializable(Serializable object, Session session)
Create a JMS ObjectMessage for the given Serializable object.protected TextMessage
createMessageForString(String text, Session session)
Create a JMS TextMessage for the given String.protected byte[]
extractByteArrayFromMessage(BytesMessage message)
Extract a byte array from the givenBytesMessage
.protected Map<String,Object>
extractMapFromMessage(MapMessage message)
Extract a Map from the givenMapMessage
.protected Serializable
extractSerializableFromMessage(ObjectMessage message)
Extract a Serializable object from the givenObjectMessage
.protected String
extractStringFromMessage(TextMessage message)
Extract a String from the given TextMessage.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.
构造器详细资料
SimpleMessageConverter
public SimpleMessageConverter()
方法详细资料
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.- 指定者:
toMessage
在接口中MessageConverter
- 参数:
object
- the object to convertsession
- the Session to use for creating a JMS Message- 返回:
- the JMS Message
- 抛出:
JMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failure- 另请参阅:
createMessageForString(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)
fromMessage
public Object fromMessage(Message message) throws JMSException, MessageConversionException
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.- 指定者:
fromMessage
在接口中MessageConverter
- 参数:
message
- the message to convert- 返回:
- the converted Java object
- 抛出:
JMSException
- if thrown by JMS API methodsMessageConversionException
- in case of conversion failure- 另请参阅:
extractStringFromMessage(javax.jms.TextMessage)
,extractByteArrayFromMessage(javax.jms.BytesMessage)
,extractMapFromMessage(javax.jms.MapMessage)
,extractSerializableFromMessage(javax.jms.ObjectMessage)
createMessageForString
protected TextMessage createMessageForString(String text, Session session) throws JMSException
Create a JMS TextMessage for the given String.- 参数:
text
- the String to convertsession
- current JMS session- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methods- 另请参阅:
Session.createTextMessage()
createMessageForByteArray
protected BytesMessage createMessageForByteArray(byte[] bytes, Session session) throws JMSException
Create a JMS BytesMessage for the given byte array.- 参数:
bytes
- the byyte array to convertsession
- current JMS session- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methods- 另请参阅:
Session.createBytesMessage()
createMessageForMap
protected MapMessage createMessageForMap(Map<?,?> map, Session session) throws JMSException
Create a JMS MapMessage for the given Map.- 参数:
map
- the Map to convertsession
- current JMS session- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methods- 另请参阅:
Session.createMapMessage()
createMessageForSerializable
protected ObjectMessage createMessageForSerializable(Serializable object, Session session) throws JMSException
Create a JMS ObjectMessage for the given Serializable object.- 参数:
object
- the Serializable object to convertsession
- current JMS session- 返回:
- the resulting message
- 抛出:
JMSException
- if thrown by JMS methods- 另请参阅:
Session.createObjectMessage()
extractStringFromMessage
protected String extractStringFromMessage(TextMessage message) throws JMSException
Extract a String from the given TextMessage.- 参数:
message
- the message to convert- 返回:
- the resulting String
- 抛出:
JMSException
- if thrown by JMS methods
extractByteArrayFromMessage
protected byte[] extractByteArrayFromMessage(BytesMessage message) throws JMSException
Extract a byte array from the givenBytesMessage
.- 参数:
message
- the message to convert- 返回:
- the resulting byte array
- 抛出:
JMSException
- if thrown by JMS methods
extractMapFromMessage
protected Map<String,Object> extractMapFromMessage(MapMessage message) throws JMSException
Extract a Map from the givenMapMessage
.- 参数:
message
- the message to convert- 返回:
- the resulting Map
- 抛出:
JMSException
- if thrown by JMS methods
extractSerializableFromMessage
protected Serializable extractSerializableFromMessage(ObjectMessage message) throws JMSException
Extract a Serializable object from the givenObjectMessage
.- 参数:
message
- the message to convert- 返回:
- the resulting Serializable object
- 抛出:
JMSException
- if thrown by JMS methods