Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.jms.support.converter
Class SimpleMessageConverter

    java.lang.Object
      org.springframework.jms.support.converter.SimpleMessageConverter

All Implemented Interfaces:
  MessageConverter

Direct Known Subclasses:
  SimpleMessageConverter102

    public class SimpleMessageConverter

extends java.lang.Object
implements 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
See Also:
  `JmsTemplate.convertAndSend(java.lang.Object)`, `JmsTemplate.receiveAndConvert()`

Constructor Summary
`SimpleMessageConverter()`

Method Summary
`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(java.util.Map<?,?> map, javax.jms.Session session)` Create a JMS MapMessage for the given Map.
`protected javax.jms.ObjectMessage` | `createMessageForSerializable(java.io.Serializable object, javax.jms.Session session)` Create a JMS ObjectMessage for the given Serializable object.
`protected javax.jms.TextMessage` | `createMessageForString(java.lang.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 java.util.Map` | `extractMapFromMessage(javax.jms.MapMessage message)` Extract a Map from the given `MapMessage`.
`protected java.io.Serializable` | `extractSerializableFromMessage(javax.jms.ObjectMessage message)` Extract a Serializable object from the given `ObjectMessage`.
`protected java.lang.String` | `extractStringFromMessage(javax.jms.TextMessage message)` Extract a String from the given TextMessage.
`java.lang.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(java.lang.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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SimpleMessageConverter

    public SimpleMessageConverter()

Method Detail

### toMessage

    public javax.jms.Message toMessage(java.lang.Object object,
                                       javax.jms.Session session)
                                throws javax.jms.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:
    `toMessage` in interface `MessageConverter`
  Parameters:
    `object` - the object to convert
    `session` - the Session to use for creating a JMS Message
  Returns:
    the JMS Message
  Throws:
    `javax.jms.JMSException` - if thrown by JMS API methods
    `MessageConversionException` - in case of conversion failure
  See Also:
    `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 java.lang.Object fromMessage(javax.jms.Message message)
                                 throws javax.jms.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.

  Specified by:
    `fromMessage` in interface `MessageConverter`
  Parameters:
    `message` - the message to convert
  Returns:
    the converted Java object
  Throws:
    `javax.jms.JMSException` - if thrown by JMS API methods
    `MessageConversionException` - in case of conversion failure
  See Also:
    `extractStringFromMessage(javax.jms.TextMessage)`, `extractByteArrayFromMessage(javax.jms.BytesMessage)`, `extractMapFromMessage(javax.jms.MapMessage)`, `extractSerializableFromMessage(javax.jms.ObjectMessage)`

### createMessageForString

    protected javax.jms.TextMessage createMessageForString(java.lang.String text,
                                                           javax.jms.Session session)
                                                    throws javax.jms.JMSException

  Create a JMS TextMessage for the given String.

  Parameters:
    `text` - the String to convert
    `session` - current JMS session
  Returns:
    the resulting message
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods
  See Also:
    `Session.createTextMessage()`

### createMessageForByteArray

    protected javax.jms.BytesMessage createMessageForByteArray(byte[] bytes,
                                                               javax.jms.Session session)
                                                        throws javax.jms.JMSException

  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:
    `javax.jms.JMSException` - if thrown by JMS methods
  See Also:
    `Session.createBytesMessage()`

### createMessageForMap

    protected javax.jms.MapMessage createMessageForMap(java.util.Map<?,?> map,
                                                       javax.jms.Session session)
                                                throws javax.jms.JMSException

  Create a JMS MapMessage for the given Map.

  Parameters:
    `map` - the Map to convert
    `session` - current JMS session
  Returns:
    the resulting message
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods
  See Also:
    `Session.createMapMessage()`

### createMessageForSerializable

    protected javax.jms.ObjectMessage createMessageForSerializable(java.io.Serializable object,
                                                                   javax.jms.Session session)
                                                            throws javax.jms.JMSException

  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:
    `javax.jms.JMSException` - if thrown by JMS methods
  See Also:
    `Session.createObjectMessage()`

### extractStringFromMessage

    protected java.lang.String extractStringFromMessage(javax.jms.TextMessage message)
                                                 throws javax.jms.JMSException

  Extract a String from the given TextMessage.

  Parameters:
    `message` - the message to convert
  Returns:
    the resulting String
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods

### extractByteArrayFromMessage

    protected byte[] extractByteArrayFromMessage(javax.jms.BytesMessage message)
                                          throws javax.jms.JMSException

  Extract a byte array from the given `BytesMessage`.

  Parameters:
    `message` - the message to convert
  Returns:
    the resulting byte array
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods

### extractMapFromMessage

    protected java.util.Map extractMapFromMessage(javax.jms.MapMessage message)
                                           throws javax.jms.JMSException

  Extract a Map from the given `MapMessage`.

  Parameters:
    `message` - the message to convert
  Returns:
    the resulting Map
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods

### extractSerializableFromMessage

    protected java.io.Serializable extractSerializableFromMessage(javax.jms.ObjectMessage message)
                                                           throws javax.jms.JMSException

  Extract a Serializable object from the given `ObjectMessage`.

  Parameters:
    `message` - the message to convert
  Returns:
    the resulting Serializable object
  Throws:
    `javax.jms.JMSException` - if thrown by JMS methods

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD