[jboss-svn-commits] JBL Code SVN: r23966 - labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 19 09:50:52 EST 2008
Author: beve
Date: 2008-11-19 09:50:52 -0500 (Wed, 19 Nov 2008)
New Revision: 23966
Modified:
labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposer.java
labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposerImpl.java
Log:
Updated javadocs and method order.
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposer.java 2008-11-19 14:13:12 UTC (rev 23965)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposer.java 2008-11-19 14:50:52 UTC (rev 23966)
@@ -29,7 +29,7 @@
import org.jboss.esb.api.message.MessageProcessingException;
/**
- * JMS Message Composer.
+ * An ESBMessageComposer composes ESB Messages using the contents a an JMSMessage.
*
* @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
*
@@ -37,8 +37,8 @@
public interface EsbMessageComposer
{
/**
- * Decompose the ESB Message object payload and uses the payload to create a
- * new instance of T.
+ * Composes/creates an ESB Message object populating its payload using the payload
+ * of the passed-in JMS Message objects payload
*
* @param message The ESB message object instance.
* @param t The class parameter
@@ -50,6 +50,8 @@
/**
* Can extract any of the properties that have been set on the JMS Message.
+ * This could for example be all the user defined properties as well as
+ * the standard JMS header field.
*
* @param jmsMessage The JMS Message.
* @return The JMS Properties.
Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposerImpl.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposerImpl.java 2008-11-19 14:13:12 UTC (rev 23965)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/composers/EsbMessageComposerImpl.java 2008-11-19 14:50:52 UTC (rev 23966)
@@ -48,16 +48,15 @@
import org.jboss.esb.jms.StreamMessageInputStream;
/**
- * JMS Message Composer implementation.
+ * Concrete ESBMessageComposer implementation.
*
* @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
*
- * @param <T extends javax.jms.Message>
*/
public final class EsbMessageComposerImpl implements EsbMessageComposer
{
/**
- * Extracts the content from the passed in JMS Message object.
+ * Composes/creates a ESB Message using the content from the passed-in JMS Message object.
* <br>
* The following conversions are done bases on the message type:
* <lu>
@@ -68,10 +67,10 @@
* <li>StreamMessage -> org.jboss.esb.jms.StreamMessageInputStream</li>
* </lu>
*
- * @param jmsMessage the JMS Message object instance.
- * @param invocationContext the ESB {@link InvocationContext}.
- * @return Message the populated ESB Message object instance.
- * @throws MessageProcessingException if an error occurs while trying to extract the JMS messages contents.
+ * @param jmsMessage The JMS Message object instance.
+ * @param invocationContext The ESB {@link InvocationContext}.
+ * @return Message The populated ESB Message object instance.
+ * @throws MessageProcessingException If an error occurs while trying to extract the JMS messages contents.
*/
public Message composeEsbMessage(final javax.jms.Message jmsMessage, final InvocationContext invocationContext) throws MessageProcessingException
{
@@ -111,6 +110,89 @@
}
/**
+ * Just sets the ESB Message payload.
+ *
+ * @param object The object to set as the payload
+ * @param esbMessage The ESB Message object instance.
+ * @throws MessageProcessingException The the object to set is null.
+ */
+ private void setPayload(final Object object, final Message esbMessage) throws MessageProcessingException
+ {
+ if (object == null)
+ {
+ throw new MessageProcessingException("Content in JMSMessage was null");
+ }
+ esbMessage.setPayload(object);
+ }
+
+ /**
+ * Gets the Map from a JMS MessageMap instance.
+ *
+ * @param jmsMessage The JMS Message Object instance.
+ * @return Map The extracted Map.
+ * @throws JMSException If an exception occurs during extraction.
+ * @throws MessageProcessingException If the map is empty.
+ */
+ private final Map<String, Object> getMap(final javax.jms.Message jmsMessage) throws JMSException, MessageProcessingException
+ {
+ final MapMessage jmsMap = (MapMessage) jmsMessage;
+ final Map<String, Object> esbMap = new HashMap<String, Object>();
+ final Enumeration<?> mapNames = jmsMap.getMapNames();
+ while (mapNames.hasMoreElements())
+ {
+ final String key = (String) mapNames.nextElement();
+ final Object value = jmsMap.getObject(key);
+ esbMap.put(key, value);
+ }
+ if (esbMap.isEmpty())
+ {
+ throw new MessageProcessingException("Map in JMSMessage [" + jmsMessage + "] contained zero key value pairs.");
+ }
+ return esbMap;
+ }
+
+ /**
+ * Read the bytes from the supplied JMS Message.
+ * @param jmsMessage The JMS Message.
+ * @return The message bytes.
+ * @throws JMSException Error Access message bytes.
+ */
+ private static byte[] readBytes(final BytesMessage jmsMessage) throws JMSException
+ {
+ jmsMessage.reset();
+ int msgLength = 0;
+ final int buffSize = 50000;
+ byte[] data = new byte[buffSize];
+ while (true)
+ {
+ int len = jmsMessage.readBytes(data);
+ if (len > 0)
+ {
+ msgLength += len;
+ }
+ else
+ {
+ break;
+ }
+ }
+ if (msgLength == 0)
+ {
+ throw new JMSException("Content in JMSMessage [" + jmsMessage + "] was of zero length");
+ }
+ byte[] content = new byte[msgLength];
+ if (msgLength <= buffSize)
+ {
+ System.arraycopy(data, 0, content, 0, msgLength);
+ }
+ else
+ {
+ jmsMessage.reset();
+ jmsMessage.readBytes(content);
+ }
+ return content;
+ }
+
+ /**
* Will extract all the properties that have been set on the JMS Message and
* also extract all the set JMS Headers.
* <p/>
@@ -123,10 +205,14 @@
* <li>JMSTimestamp -> get(JmsConstants.TIMESTAMP</li>
* <li>JMSReplyTo -> get(JmsConstants.REPLY_TO</li>
* <li>JMSPriority -> get(JmsConstants.PRIORITY</li>
+ * <li>JMSDeliveryMode -> get(JmsConstants.DELIVERY_MODE</li>
* </ul>
+ * Note that user defined properties will also be added to the
+ * returned Properties object. They will simple have the key and
+ * values as they had in the JMS Message object.
*
- * @param jmsMessage The JMS Message.
- * @return The JMS Properties.
+ * @param jmsMessage The JMS Message.
+ * @return Propertis The JMS Properties.
* @throws JMSException Error extracting properties.
*/
public Properties extractJmsProperties(final javax.jms.Message jmsMessage) throws MessageProcessingException
@@ -144,61 +230,77 @@
return properties;
}
- private void addDeliveryMode(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ /**
+ * Note that JMS standard header fields are not considered properties and are not set by this method.
+ *
+ * @param jmsMessage The JMS Message.
+ * @param properties The properties object to add the properties to.
+ * @throws MessageProcessingException
+ * @throws JMSException
+ */
+ private void addUserDefinedProperties(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
+ String propertyName = null;
+ Object value = null;
try
{
- int deliveryMode = jmsMessage.getJMSDeliveryMode();
- properties.put(DELIVERY_MODE, deliveryMode);
+ final Enumeration<String> propertyNames = jmsMessage.getPropertyNames();
+ while (propertyNames.hasMoreElements())
+ {
+ propertyName = propertyNames.nextElement();
+ value = jmsMessage.getObjectProperty(propertyName);
+ properties.put(propertyName, value);
+ }
}
- catch (final JMSException e)
+ catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSDeliveredMode property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve user defined property '" + propertyName + "' which had the value '" + value + "'", e);
}
}
- private void addPriority(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addCorrelationId(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- int priority = jmsMessage.getJMSPriority();
- if (priority >= 0 && priority <= 9)
+ final String correlationID = jmsMessage.getJMSCorrelationID();
+ if (correlationID != null)
{
- properties.put(PRIORITY, Integer.valueOf(priority));
+ properties.put(CORRELATION_ID, correlationID);
}
}
- catch (final JMSException e)
+ catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSPriority property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSCorrelationID property from JMS Message:", e);
}
}
- private void addReplyTo(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addExpiration(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- Destination replyTo = jmsMessage.getJMSReplyTo();
- if (replyTo != null)
+ final long expiration = jmsMessage.getJMSExpiration();
+ if (expiration > 0L)
{
- properties.put(REPLY_TO, replyTo);
+ properties.put(EXPIRATION, Long.valueOf(expiration));
}
}
catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSReplyTo property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSExpiration property from JMS Message:", e);
}
+
}
- private void addTimestamp(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addRedelivered(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- final long timestamp = jmsMessage.getJMSTimestamp();
- properties.put(TIMESTAMP, Long.valueOf(timestamp));
+ final boolean redelivered = jmsMessage.getJMSRedelivered();
+ properties.put(REDELIVERED, redelivered);
}
catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSTimestamp property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSRedelivered property from JMS Message:", e);
}
}
@@ -222,163 +324,64 @@
}
- private void addRedelivered(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addTimestamp(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- final boolean redelivered = jmsMessage.getJMSRedelivered();
- properties.put(REDELIVERED, redelivered);
+ final long timestamp = jmsMessage.getJMSTimestamp();
+ properties.put(TIMESTAMP, Long.valueOf(timestamp));
}
catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSRedelivered property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSTimestamp property from JMS Message:", e);
}
}
- private void addExpiration(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addReplyTo(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- final long expiration = jmsMessage.getJMSExpiration();
- if (expiration > 0L)
+ Destination replyTo = jmsMessage.getJMSReplyTo();
+ if (replyTo != null)
{
- properties.put(EXPIRATION, Long.valueOf(expiration));
+ properties.put(REPLY_TO, replyTo);
}
}
catch (JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSExpiration property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSReplyTo property from JMS Message:", e);
}
-
}
- private void addCorrelationId(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addPriority(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
try
{
- final String correlationID = jmsMessage.getJMSCorrelationID();
- if (correlationID != null)
+ int priority = jmsMessage.getJMSPriority();
+ if (priority >= 0 && priority <= 9)
{
- properties.put(CORRELATION_ID, correlationID);
+ properties.put(PRIORITY, Integer.valueOf(priority));
}
}
- catch (JMSException e)
+ catch (final JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve JMSCorrelationID property from JMS Message:", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSPriority property from JMS Message:", e);
}
}
- /**
- * Note that JMS standard header fields are not considered properties and are not set by this method.
- *
- * @param jmsMessage The JMS Message.
- * @param properties The properties object to add the properties to.
- * @throws MessageProcessingException
- * @throws JMSException
- */
- private void addUserDefinedProperties(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
+ private void addDeliveryMode(final javax.jms.Message jmsMessage, final Properties properties) throws MessageProcessingException
{
- String propertyName = null;
- Object value = null;
try
{
- final Enumeration<String> propertyNames = jmsMessage.getPropertyNames();
- while (propertyNames.hasMoreElements())
- {
- propertyName = propertyNames.nextElement();
- value = jmsMessage.getObjectProperty(propertyName);
- properties.put(propertyName, value);
- }
+ int deliveryMode = jmsMessage.getJMSDeliveryMode();
+ properties.put(DELIVERY_MODE, deliveryMode);
}
- catch (JMSException e)
+ catch (final JMSException e)
{
- throw new MessageProcessingException("JMSException while trying to retrieve user defined property '" + propertyName + "' which had the value '" + value + "'", e);
+ throw new MessageProcessingException("JMSException while trying to retrieve JMSDeliveredMode property from JMS Message:", e);
}
}
- /**
- * Just sets the ESB Message payload.
- *
- * @param object The object to set as the payload
- * @param esbMessage The ESB Message object instance.
- * @throws MessageProcessingException The the object to set is null.
- */
- private void setPayload(final Object object, final Message esbMessage) throws MessageProcessingException
- {
- if (object == null)
- {
- throw new MessageProcessingException("Content in JMSMessage was null");
- }
- esbMessage.setPayload(object);
- }
-
- /**
- * Gets the Map from a JMS MessageMap instance.
- *
- * @param jmsMessage The JMS Message Object instance.
- * @return Map The extracted Map.
- * @throws JMSException If an exception occurs during extraction.
- * @throws MessageProcessingException If the map is empty.
- */
- private final Map<String, Object> getMap(final javax.jms.Message jmsMessage) throws JMSException, MessageProcessingException
- {
- final MapMessage jmsMap = (MapMessage) jmsMessage;
- final Map<String, Object> esbMap = new HashMap<String, Object>();
- final Enumeration<?> mapNames = jmsMap.getMapNames();
- while (mapNames.hasMoreElements())
- {
- final String key = (String) mapNames.nextElement();
- final Object value = jmsMap.getObject(key);
- esbMap.put(key, value);
- }
- if (esbMap.isEmpty())
- {
- throw new MessageProcessingException("Map in JMSMessage [" + jmsMessage + "] contained zero key value pairs.");
- }
- return esbMap;
- }
-
- /**
- * Read the bytes from the supplied JMS Message.
- * @param jmsMessage The JMS Message.
- * @return The message bytes.
- * @throws JMSException Error Access message bytes.
- */
- private static byte[] readBytes(final BytesMessage jmsMessage) throws JMSException
- {
- jmsMessage.reset();
- int msgLength = 0;
- final int buffSize = 50000;
- byte[] data = new byte[buffSize];
- while (true)
- {
- int len = jmsMessage.readBytes(data);
- if (len > 0)
- {
- msgLength += len;
- }
- else
- {
- break;
- }
- }
- if (msgLength == 0)
- {
- throw new JMSException("Content in JMSMessage [" + jmsMessage + "] was of zero length");
- }
- byte[] content = new byte[msgLength];
- if (msgLength <= buffSize)
- {
- System.arraycopy(data, 0, content, 0, msgLength);
- }
- else
- {
- jmsMessage.reset();
- jmsMessage.readBytes(content);
- }
- return content;
- }
-
public void setConfiguration(Properties properties)
{
//NoOp
More information about the jboss-svn-commits
mailing list