org.mule.transport.jms
Class JmsMessageUtils

java.lang.Object
  extended by org.mule.transport.jms.JmsMessageUtils

public class JmsMessageUtils
extends java.lang.Object

JmsMessageUtils contains helper method for dealing with JMS messages in Mule.


Field Summary
static char REPLACEMENT_CHAR
           
 
Constructor Summary
JmsMessageUtils()
           
 
Method Summary
static javax.jms.Message copyJMSProperties(javax.jms.Message from, javax.jms.Message to, JmsConnector connector)
           
static java.lang.String encodeHeader(java.lang.String name)
          Encode a String so that is is a valid JMS header name
static java.lang.String getNameForDestination(javax.jms.Destination dest)
           
static byte[] toByteArray(javax.jms.Message message, java.lang.String jmsSpec, java.lang.String encoding)
           
static javax.jms.Message toMessage(java.lang.Object object, javax.jms.Session session)
           
static java.lang.Object toObject(javax.jms.Message source, java.lang.String jmsSpec, java.lang.String encoding)
           
protected static boolean validateMapMessageType(java.util.Map<?,?> candidate)
          MapMessage#writeObject(Object) accepts only primitives (and wrappers), String and byte[].
protected static boolean validateStreamMessageType(java.lang.Object candidate)
          StreamMessage.writeObject(Object) accepts only primitives (and wrappers), String and byte[].
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPLACEMENT_CHAR

public static final char REPLACEMENT_CHAR
See Also:
Constant Field Values
Constructor Detail

JmsMessageUtils

public JmsMessageUtils()
Method Detail

encodeHeader

public static java.lang.String encodeHeader(java.lang.String name)
Encode a String so that is is a valid JMS header name

Parameters:
name - the String to encode
Returns:
a valid JMS header name

toMessage

public static javax.jms.Message toMessage(java.lang.Object object,
                                          javax.jms.Session session)
                                   throws javax.jms.JMSException
Throws:
javax.jms.JMSException

toObject

public static java.lang.Object toObject(javax.jms.Message source,
                                        java.lang.String jmsSpec,
                                        java.lang.String encoding)
                                 throws javax.jms.JMSException,
                                        java.io.IOException
Throws:
javax.jms.JMSException
java.io.IOException

toByteArray

public static byte[] toByteArray(javax.jms.Message message,
                                 java.lang.String jmsSpec,
                                 java.lang.String encoding)
                          throws javax.jms.JMSException,
                                 java.io.IOException
Parameters:
message - the message to receive the bytes from. Note this only works for TextMessge, ObjectMessage, StreamMessage and BytesMessage.
jmsSpec - indicates the JMS API version, either JmsConstants.JMS_SPECIFICATION_102B or JmsConstants.JMS_SPECIFICATION_11. Any other value including null is treated as fallback to JmsConstants.JMS_SPECIFICATION_102B.
Returns:
a byte array corresponding with the message payload
Throws:
javax.jms.JMSException - if the message can't be read or if the message passed is a MapMessage
java.io.IOException - if a failure occurs while reading the stream and converting the message data

getNameForDestination

public static java.lang.String getNameForDestination(javax.jms.Destination dest)
                                              throws javax.jms.JMSException
Throws:
javax.jms.JMSException

copyJMSProperties

public static javax.jms.Message copyJMSProperties(javax.jms.Message from,
                                                  javax.jms.Message to,
                                                  JmsConnector connector)
                                           throws javax.jms.JMSException
Throws:
javax.jms.JMSException

validateStreamMessageType

protected static boolean validateStreamMessageType(java.lang.Object candidate)
StreamMessage.writeObject(Object) accepts only primitives (and wrappers), String and byte[]. An attempt to write anything else must fail with a MessageFormatException as per JMS 1.1 spec, Section 7.3 Standard Exceptions, page 89, 1st paragraph.

Unfortunately, some JMS vendors are not compliant in this area, enforce here for consistent behavior.

Parameters:
candidate - object to validate

validateMapMessageType

protected static boolean validateMapMessageType(java.util.Map<?,?> candidate)
MapMessage#writeObject(Object) accepts only primitives (and wrappers), String and byte[]. An attempt to write anything else must fail with a MessageFormatException as per JMS 1.1 spec, Section 7.3 Standard Exceptions, page 89, 1st paragraph.

Unfortunately, some JMS vendors are not compliant in this area, enforce here for consistent behavior. Here we handle non-primitive maps as ObjectMessage rather than creating a MapMessage

Parameters:
candidate - Map to validate


Copyright © 2003-2010 MuleSoft, Inc.. All Rights Reserved.