public class JmsMessageUtils extends Object
JmsMessageUtils
contains helper method for dealing with JMS
messages in Mule.Modifier and Type | Field and Description |
---|---|
static char |
REPLACEMENT_CHAR |
Constructor and Description |
---|
JmsMessageUtils() |
Modifier and Type | Method and Description |
---|---|
static Message |
copyJMSProperties(Message from,
Message to,
JmsConnector connector) |
static String |
encodeHeader(String name)
Encode a String so that is is a valid JMS header name
|
static String |
getNameForDestination(Destination dest) |
static byte[] |
toByteArray(Message message,
String jmsSpec,
String encoding) |
static Message |
toMessage(Object object,
Session session) |
static Object |
toObject(Message source,
String jmsSpec,
String encoding) |
protected static boolean |
validateMapMessageType(Map<?,?> candidate)
MapMessage#writeObject(Object) accepts only primitives (and wrappers), String and byte[]. |
protected static boolean |
validateStreamMessageType(Object candidate)
StreamMessage.writeObject(Object) accepts only primitives (and wrappers), String and byte[]. |
public static final char REPLACEMENT_CHAR
public static String encodeHeader(String name)
name
- the String to encodepublic static Message toMessage(Object object, Session session) throws JMSException
JMSException
public static Object toObject(Message source, String jmsSpec, String encoding) throws JMSException, IOException
JMSException
IOException
public static byte[] toByteArray(Message message, String jmsSpec, String encoding) throws JMSException, IOException
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
.JMSException
- if the message can't be read or if the message passed is
a MapMessageIOException
- if a failure occurs while reading the stream and
converting the message datapublic static String getNameForDestination(Destination dest) throws JMSException
JMSException
public static Message copyJMSProperties(Message from, Message to, JmsConnector connector) throws JMSException
JMSException
protected static boolean validateStreamMessageType(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.candidate
- object to validateprotected static boolean validateMapMessageType(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
candidate
- Map to validateCopyright © 2003–2016 MuleSoft, Inc.. All rights reserved.