[jboss-svn-commits] JBL Code SVN: r13941 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/actions/routing and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Aug 1 16:55:54 EDT 2007
Author: beve
Date: 2007-08-01 16:55:53 -0400 (Wed, 01 Aug 2007)
New Revision: 13941
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ESBPropertiesSetter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/JMSPropertiesSetter.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyJMSUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/jms/
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetterUnitTest.java
Modified:
labs/jbossesb/trunk/product/.classpath
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/AbstractRouter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
Log:
JMS Header Fields and Propeties relatated Jiras:
JBESB-658
JBESB-691
JBESB-724
Modified: labs/jbossesb/trunk/product/.classpath
===================================================================
--- labs/jbossesb/trunk/product/.classpath 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/.classpath 2007-08-01 20:55:53 UTC (rev 13941)
@@ -13,7 +13,6 @@
<classpathentry kind="lib" path="lib/ext/emma.jar"/>
<classpathentry kind="lib" path="lib/ext/groovy-all-1.0.jar"/>
<classpathentry kind="lib" path="lib/ext/hsqldb.jar"/>
- <classpathentry kind="lib" path="lib/ext/jaxr-api-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/ext/jbossall-client.jar"/>
<classpathentry kind="lib" path="lib/ext/jboss-system.jar"/>
<classpathentry kind="lib" path="lib/ext/jbossts-common.jar"/>
@@ -27,7 +26,6 @@
<classpathentry kind="lib" path="lib/ext/ognl-2.6.9.jar"/>
<classpathentry kind="lib" path="lib/ext/opencsv-1.6.jar"/>
<classpathentry kind="lib" path="lib/ext/properties-plugin.jar"/>
- <classpathentry kind="lib" path="lib/ext/scout-1.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/ext/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/ext/xalan-2.7.0.jar"/>
<classpathentry kind="lib" path="lib/ext/xbean.jar"/>
@@ -67,8 +65,19 @@
<classpathentry kind="lib" path="lib/ext/jbossweb.jar"/>
<classpathentry kind="lib" path="lib/ext/stringtemplate-3.0.jar"/>
<classpathentry kind="lib" path="lib/ext/trove.jar"/>
- <classpathentry kind="lib" path="lib/ext/jboss-test.jar"/>
<classpathentry kind="lib" path="lib/ext/jakarta-oro-2.0.8.jar"/>
<classpathentry kind="lib" path="lib/ext/commons-ssl-0.3.4.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/antlr-3.0b7.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/core-3.2.1.v_677_R32x.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/drools-compiler-4.0.0.11754MR2.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/drools-core-4.0.0.11754MR2.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/drools-decisiontables-4.0.0.11754MR2.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/drools-jsr94-4.0.0.11754MR2.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/janino-2.5.6.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/jsr94-1.1.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/jxl-2.4.2.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/mvel14-1.2beta16.jar"/>
+ <classpathentry kind="lib" path="/jbrules_trunk/lib/ext/xpp3-1.1.3.4.O.jar"/>
+ <classpathentry kind="lib" path="lib/ext/quartz-1.6.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/AbstractRouter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/AbstractRouter.java 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/AbstractRouter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -63,7 +63,7 @@
/* (non-Javadoc)
* @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
*/
- public final Message process(Message message) throws ActionProcessingException {
+ public Message process(Message message) throws ActionProcessingException {
if(unwrap) {
route(ActionUtils.getTaskObject(message));
} else {
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/JMSRouter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -23,10 +23,12 @@
package org.jboss.soa.esb.actions.routing;
import java.io.Serializable;
+import java.net.URISyntaxException;
import java.util.List;
import java.util.Properties;
import javax.jms.BytesMessage;
+import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
@@ -43,15 +45,19 @@
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.common.Configuration;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.helpers.NamingContext;
+import org.jboss.soa.esb.notification.jms.DefaultJMSPropertiesSetter;
+import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
import org.jboss.soa.esb.util.Util;
/**
- * JSM Routing Action Processor.
+ * JMS Routing Action Processor.
* <p/>
* Sample Action Configuration:
* <pre>
@@ -63,9 +69,15 @@
* </pre>
* Note how properties to be set on the message are prefixed with "message-prop-".
* <p/>
- * To unwrap the message payload from the message before routing, set the "unwrap" property to "true".
+ * <ul>
+ * <li>'unwrap' true will extract the message payload from the Message object before sending</li>
+ * <li>'unwrap' false false will send the serialized Message object</li>
+ * </ul>
+ *
* TODO: Add support for JMS Topic destinations.
+ *
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @author <a href="mailto:daniel.bevenius at redpill.se">daniel.bevenius at redpill.se</a>
* @since Version 4.0
*/
public class JMSRouter extends AbstractRouter {
@@ -74,13 +86,26 @@
*/
private static Logger logger = Logger.getLogger(JMSRouter.class);
/**
+ * Indicates whether processing of the action pipeline
+ * should continue or not.
+ */
+ public static final String ATTR_CONTINUE_ACTION_PIPELINE_PROCESSING = "continue-processing";
+ /**
* Routing properties.
*/
private List<KeyValuePair> properties;
/**
+ * The JMS Queue name from the configuration
+ */
+ private String queueName;
+ /**
* JMS Queue setup.
*/
private JMSSendQueueSetup queueSetup;
+ /**
+ * Strategy for setting JMSProperties
+ */
+ private JMSPropertiesSetter jmsPropertiesStrategy = new DefaultJMSPropertiesSetter();
/**
* Public constructor.
@@ -106,67 +131,110 @@
this.properties = properties;
- String queueName = KeyValuePair.getValue("jndiName", properties);
+ queueName = KeyValuePair.getValue("jndiName", properties);
if(queueName == null) {
throw new ConfigurationException("JMSRouter must specify a 'jndiName' property.");
}
- try {
- queueSetup = new JMSSendQueueSetup(queueName);
- } catch (Throwable t) {
- new ConfigurationException("Failed to configure JMS Queue for routing.", t);
- }
- this.properties = properties;
+ createQueueSetup( queueName );
}
+
+ /**
+ * Will simply pass the message to the route method unmodified.
+ * @return <code>null</code> which will case the action pipeline processing to stop
+ */
+ @Override
+ public org.jboss.soa.esb.message.Message process( org.jboss.soa.esb.message.Message message ) throws ActionProcessingException
+ {
+ route ( message );
+
+ return null;
+ }
/* (non-Javadoc)
* @see org.jboss.soa.esb.actions.routing.AbstractRouter#route(java.lang.Object)
*/
public void route(Object message) throws ActionProcessingException {
- if(!(message instanceof Serializable) && !(message instanceof org.jboss.soa.esb.message.Message)) {
- throw new ActionProcessingException("Cannot send Object [" + message.getClass().getName() + "] to destination [" + queueSetup.queueName + "]. Object must be serializable.");
+ if(!(message instanceof org.jboss.soa.esb.message.Message)) {
+ throw new ActionProcessingException("Cannot send Object [" + message.getClass().getName() + "] to destination [" + queueName + "]. Object must be an instance of org.jboss.soa.esb.message.Message) .");
}
+ final org.jboss.soa.esb.message.Message esbMessage = (org.jboss.soa.esb.message.Message)message;
+
try {
Message jmsMessage = null;
- // Send the message to the queue...
- if (message instanceof org.jboss.soa.esb.message.Message) {
- message = Util.serialize((org.jboss.soa.esb.message.Message)message);
- jmsMessage = createObjectMessage(message);
- } else if(message instanceof String) {
- jmsMessage = queueSetup.jmsSession.createTextMessage();
-
- if(logger.isDebugEnabled()) {
- logger.debug("Sending Text message: [" + message + "] to destination [" + queueSetup.queueName + "].");
- }
- ((TextMessage)jmsMessage).setText((String)message);
- } else if(message instanceof byte[]) {
- jmsMessage = queueSetup.jmsSession.createBytesMessage();
-
- if(logger.isDebugEnabled()) {
- logger.debug("Sending byte[] message: [" + message + "] to destination [" + queueSetup.queueName + "].");
- }
- ((BytesMessage)jmsMessage).writeBytes((byte[])message);
- } else {
- jmsMessage = createObjectMessage(message);
- }
+ if ( unwrap ) {
+ Object objectFromBody = ActionUtils.getTaskObject(esbMessage);
+ jmsMessage = createJMSMessageWithObjectType( objectFromBody );
+ }
+ else {
+ jmsMessage = createObjectMessage(Util.serialize(esbMessage));
+ }
+
setStringProperties(jmsMessage);
- queueSetup.jmsProducer.send(jmsMessage);
+ setJMSProperties( esbMessage, jmsMessage );
+ send( jmsMessage );
+
} catch(Exception e) {
- String errorMessage = "Exception while sending message [" + message + "] to destination [";
+ StringBuilder sb = new StringBuilder();
+ sb.append("Exception while sending message [").append(message).append("] to destination [");
if (queueSetup != null)
- errorMessage += queueSetup.queueName + "].";
+ sb.append(queueSetup.queueName).append("].");
else
- errorMessage += "null ].";
+ sb.append("null ].");
+ String errorMessage = sb.toString();
logger.error(errorMessage, e);
throw new ActionProcessingException(errorMessage, e);
}
}
+
+ protected Message createJMSMessageWithObjectType( Object objectFromBody ) throws JMSException
+ {
+ Message jmsMessage = null;
+ if(objectFromBody instanceof String) {
+ jmsMessage = queueSetup.jmsSession.createTextMessage();
- private Message createObjectMessage(Object message) throws JMSException {
+ if(logger.isDebugEnabled()) {
+ logger.debug("Sending Text message: [" + objectFromBody + "] to destination [" + queueSetup.queueName + "].");
+ }
+
+ ((TextMessage)jmsMessage).setText((String)objectFromBody);
+ } else if(objectFromBody instanceof byte[]) {
+ jmsMessage = queueSetup.jmsSession.createBytesMessage();
+
+ if(logger.isDebugEnabled()) {
+ logger.debug("Sending byte[] message: [" + objectFromBody + "] to destination [" + queueSetup.queueName + "].");
+ }
+
+ ((BytesMessage)jmsMessage).writeBytes((byte[])objectFromBody);
+ } else {
+ jmsMessage = createObjectMessage(objectFromBody);
+ }
+
+ return jmsMessage;
+ }
+
+ protected void send( Message jmsMessage ) throws JMSException
+ {
+ queueSetup.jmsProducer.send(jmsMessage);
+ }
+
+ /**
+ * This method will set appropriate JMSProperties on the outgoing JMS Message instance.
+ * </p>
+ * Sublclasses can either override this method to add a different behaviour, or they can
+ * set the strategy by calling {@link #setJmsPropertiesStrategy(JMSPropertiesSetter)}.
+ * </p>
+ * See {@link org.jboss.soa.esb.notification.jms.JMSPropertiesSetter} for more info.
+ */
+ protected void setJMSProperties(org.jboss.soa.esb.message.Message fromESBMessage, Message toJMSMessage ) throws JMSException {
+ jmsPropertiesStrategy.setJMSProperties( fromESBMessage, toJMSMessage );
+ }
+
+ protected Message createObjectMessage(Object message) throws JMSException {
Message jmsMessage;
jmsMessage = queueSetup.jmsSession.createObjectMessage();
@@ -209,17 +277,27 @@
super.finalize();
}
+ protected void createQueueSetup( String queueName ) throws ConfigurationException
+ {
+ try {
+ queueSetup = new JMSSendQueueSetup(queueName);
+ } catch (Throwable t) {
+ throw new ConfigurationException("Failed to configure JMS Queue for routing.", t);
+ }
+ }
+
private static class JMSSendQueueSetup {
QueueSession jmsSession;
Queue jmsQueue;
MessageProducer jmsProducer;
String queueName;
JmsConnectionPool pool;
+ Properties environment;
// TODO: Modify to support topic destinations too
private JMSSendQueueSetup(String queueName) throws NamingException, JMSException, ConnectionException {
- Properties environment = new Properties();
+ environment = new Properties();
environment.setProperty(Context.PROVIDER_URL, Configuration.getJndiServerURL());
environment.setProperty(Context.INITIAL_CONTEXT_FACTORY, Configuration.getJndiServerContextFactory());
environment.setProperty(Context.URL_PKG_PREFIXES, Configuration.getJndiServerPkgPrefix());
@@ -253,4 +331,31 @@
}
}
+ protected void setJMSReplyTo( Message jmsMessage, org.jboss.soa.esb.message.Message esbMessage ) throws URISyntaxException, JMSException, NamingException, ConnectionException
+ {
+ EPR replyToEpr = esbMessage.getHeader().getCall().getReplyTo();
+ if( !( replyToEpr instanceof JMSEpr) )
+ return;
+
+ JMSEpr jmsEpr = (JMSEpr) replyToEpr;
+ String destinationType = jmsEpr.getDestinationType();
+ Destination jmsDestination = null;
+
+ if ( destinationType.equals( JMSEpr.QUEUE_TYPE ))
+ {
+ jmsDestination = queueSetup.jmsSession.createQueue( jmsEpr.getDestinationName() );
+ }
+ else
+ {
+ /* Topics are currently not supported.
+ JmsConnectionPool pool = JmsConnectionPoolContainer.getPool(queueSetup.environment, "ConnectionFactory", JMSEpr.TOPIC_TYPE);
+ jmsDestination = pool.getTopicSession().createTopic( jmsEpr.getDestinationName() );
+ */
+ }
+
+ if ( jmsDestination != null )
+ jmsMessage.setJMSReplyTo( jmsDestination );
+
+ }
+
}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Enumeration;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
+
+/**
+ * Default impl of ESBPropertiesSetter.
+ * </p>
+ * The following JMS Header fields are set on the ESB Message instance:
+ * <lu>
+ * <li> JMSMessageID -> Call.setMessagID
+ * <li> JMSCorrelationID -> Call.setRelatesTo URI = jms:correlationID#YYXX-123456780-GG
+ * <li> JMSReplyTo -> Call.setReplyTo
+ * <li> JMSExpiration -> Properties( key = JMSPropertiesSetter.JMS_EXPIRATION )
+ * </lu>
+ * Note: JMSCorrelationID is set as a fragment on the URI and can be retrieved like this:
+ * correlationURI.getFragment();
+ *
+ * @author <a href="mailto:daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @since 4.2
+ *
+ */
+public class DefaultESBPropertiesSetter implements ESBPropertiesSetter
+{
+ private Logger log = Logger.getLogger( DefaultESBPropertiesSetter.class );
+
+ public void setPropertiesFromJMSMessage( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ setMessageID( fromJMSMessage, toESBMessage );
+ setCorrelationID( fromJMSMessage, toESBMessage );
+ setReplyTo( fromJMSMessage, toESBMessage );
+ setExpiration( fromJMSMessage, toESBMessage );
+ setProperties( fromJMSMessage, toESBMessage );
+ }
+
+ private void setMessageID( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ if ( fromJMSMessage.getJMSMessageID()!=null)
+ {
+ try
+ {
+ toESBMessage.getHeader().getCall().setMessageID( new URI( fromJMSMessage.getJMSMessageID() ));
+ }
+ catch (URISyntaxException e)
+ {
+ String errorMessage = "Could not set ESB MessageID to JMSMessageID [" + fromJMSMessage.getJMSMessageID() + "]";
+ log.error( errorMessage, e );
+ throw new JMSException( errorMessage );
+ }
+ }
+ }
+
+ private void setCorrelationID( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ if ( fromJMSMessage.getJMSCorrelationID()!=null)
+ {
+ try
+ {
+ final URI correlationURI = new URI( JMSEpr.JMS_PROTOCOL, "correlationID" , fromJMSMessage.getJMSCorrelationID() );
+ toESBMessage.getHeader().getCall().setRelatesTo( correlationURI );
+ }
+ catch (URISyntaxException e)
+ {
+ final String errorMessage = "Could not ESB setRelatesTo to JMSCorrelationID [ " + fromJMSMessage.getJMSCorrelationID() + "]";
+ log.error( errorMessage, e );
+ throw new JMSException( errorMessage );
+ }
+ }
+ }
+
+ private void setReplyTo( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ if ( fromJMSMessage.getJMSReplyTo()!=null)
+ {
+ final Destination replyToDestination = fromJMSMessage.getJMSReplyTo();
+ final String connectionFactory = ModulePropertyManager.getPropertyManager("javax.jms.ConnectionFactory").getProperty(ConnectionFactory.class.getName(), "ConnectionFactory");
+ String destType = null;
+ String destName = null;
+ if ( replyToDestination instanceof Queue )
+ {
+ final Queue queue = ( Queue ) replyToDestination;
+ destName = queue.getQueueName();
+ destType = JMSEpr.QUEUE_TYPE;
+ }
+ else
+ {
+ final Topic topic = ( Topic ) replyToDestination;
+ destName = topic.getTopicName();
+ destType = JMSEpr.TOPIC_TYPE;
+ }
+ toESBMessage.getHeader().getCall().setReplyTo( new JMSEpr( destType , destName, connectionFactory ) );
+ }
+ }
+
+ private void setExpiration( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ if( fromJMSMessage.getJMSExpiration() != 0 )
+ {
+ toESBMessage.getProperties().setProperty( JMSPropertiesSetter.JMS_EXPIRATION, fromJMSMessage.getJMSExpiration() );
+ }
+ }
+
+ private void setProperties( final Message fromJMSMessage, final org.jboss.soa.esb.message.Message toESBMessage ) throws JMSException
+ {
+ @SuppressWarnings("unchecked")
+ Enumeration<String> properties = fromJMSMessage.getPropertyNames();
+ if (null != properties)
+ {
+ while (properties.hasMoreElements())
+ {
+ String key = properties.nextElement();
+ Object value = fromJMSMessage.getObjectProperty(key);
+ if (null != value)
+ toESBMessage.getProperties().setProperty(key, value);
+ }
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ESBPropertiesSetter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ESBPropertiesSetter.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/ESBPropertiesSetter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import javax.jms.JMSException;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Strategy for setting ESB Message object properties.
+ *
+ * @author <a href="mailto:daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @since 4.2
+ */
+public interface ESBPropertiesSetter
+{
+ /**
+ *
+ * @param from JMS Message instance to extract properties from
+ * @param to ESB Message instance to set the properties on
+ * @throws JMSException
+ */
+ void setPropertiesFromJMSMessage ( javax.jms.Message fromJMSMessage, Message toESBMessage ) throws JMSException;
+
+}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContents.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -23,84 +23,139 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Enumeration;
-
import javax.jms.BytesMessage;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;
-
-import org.jboss.soa.esb.common.Environment;
+import org.apache.log4j.Logger;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
/**
- * Default gateway action for plain jms messages <p/>It will just drop the
-* jms message contents into a esb Message
+* Default gateway action for plain jms messages <p/>
+* It will just drop the jms message contents into a esb Message
*
-* @author <a
-* href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+* @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+* @author <a href="mailto:daniel.bevenius at redpill.se">Daniel Bevenius</a>
* @since Version 4.0
*
*/
public class PackageJmsMessageContents
{
- @SuppressWarnings("unchecked")
- public Message process (Object obj) throws JMSException, IOException
- {
- if (!(obj instanceof javax.jms.Message))
- throw new IllegalArgumentException(
- "Object must be instance of javax.jms.Message");
- byte[] bytes = getMessageContent((javax.jms.Message) obj);
- if (null == bytes) return null;
+ private Logger log = Logger.getLogger( PackageJmsMessageContents.class );
+ /**
+ * Strategy for setting JMS Properties on the ESB Message object created
+ * by the process method.
+ */
+ private ESBPropertiesSetter esbPropertiesStrategy = new DefaultESBPropertiesSetter();
+
+ /**
+ * Will just drop the jms message contents into a esb Message
+ *
+ * @param obj An instance of Message
+ * @return <code>esbMessage</code> A newly created ESB Message object populated with the contents
+ * obj argument passed in.
+ * @throws JMSException
+ * @throws IOException
+ * @see #setESBMessageBody(javax.jms.Message, Message)
+ */
+ public Message process (final Object obj) throws JMSException, IOException
+ {
+ if ( !(obj instanceof javax.jms.Message))
+ throw new IllegalArgumentException("Object must be instance of javax.jms.Message");
+
+ final javax.jms.Message jmsMessage = (javax.jms.Message) obj;
+
+ final Message esbMessage = MessageFactory.getInstance().getMessage();
+
+ setESBMessageBody( jmsMessage, esbMessage );
+
+ if ( esbMessage.getBody().getByteArray() == null )
+ return null;
+
+ setPropertiesFromJMSMessage ( jmsMessage, esbMessage );
+
+ return esbMessage;
+ }
+
+ /**
+ * Set the {@link ESBPropertiesSetter} to be used
+ *
+ * @param esbPropertiesStrategy the strategy to be used
+ */
+ public void setEsbPropertiesStrategy( ESBPropertiesSetter esbPropertiesStrategy )
+ {
+ this.esbPropertiesStrategy = esbPropertiesStrategy;
+ }
+
+ /**
+ * Delegates to {@link DefaultESBPropertiesSetter#setPropertiesFromJMSMessage(javax.jms.Message, Message)}
+ * by default, but this method can be overridden by subclasses that need a different behaviour.
+ * </p>
+ * It is also possible to set a different strategy by setting {@link #setEsbPropertiesStrategy(ESBPropertiesSetter)}
+ */
+ protected void setPropertiesFromJMSMessage( javax.jms.Message fromJMS, org.jboss.soa.esb.message.Message toESB ) throws JMSException
+ {
+ esbPropertiesStrategy.setPropertiesFromJMSMessage( fromJMS, toESB );
+ }
- javax.jms.Message jmsMsg = (javax.jms.Message) obj;
- Message message = MessageFactory.getInstance().getMessage();
- message.getBody().setByteArray(getMessageContent(jmsMsg));
-
- if (jmsMsg instanceof ObjectMessage) {
- ObjectMessage msg = (ObjectMessage) jmsMsg;
- message.getBody().add(msg.getObject());
- }
- if (jmsMsg.getJMSMessageID()!=null) {
- message.getBody().add(Environment.JMS_MESSAGE_ID, jmsMsg.getJMSMessageID());
- }
- Enumeration<String> EE = jmsMsg.getPropertyNames();
- if (null != EE)
- {
- while (EE.hasMoreElements())
- {
- String name = EE.nextElement();
- Object value = jmsMsg.getObjectProperty(name);
- if (null != value)
- message.getProperties().setProperty(name, value);
- }
- }
- return message;
- }
-
- private byte[] getMessageContent (javax.jms.Message jMess) throws JMSException, IOException
- {
- if (jMess instanceof TextMessage)
- return ((TextMessage) jMess).getText().getBytes();
-
- if (jMess instanceof BytesMessage)
- {
- BytesMessage jBytes = (BytesMessage) jMess;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] ba = new byte[1000];
- int iQread;
- while (-1 != (iQread = jBytes.readBytes(ba)))
- if (iQread > 0) out.write(ba, 0, iQread);
- out.close();
- return out.toByteArray();
- }
-
- if (jMess instanceof ObjectMessage)
- return ((ObjectMessage) jMess).getObject().toString()
- .getBytes();
- JmsGatewayListener._logger
- .warn("Message type " + jMess.getClass().getSimpleName() + " not supported - Message is ignored");
- return null;
- }
+ /**
+ * This method will set the ESB Message's body to the appropriate type matching
+ * the JMS Message fromJMSMessage argument.
+ * <p>
+ * TextMessage -> Body.add ( String );
+ * BytesMessage -> Body.setByteArray ( byte[] );
+ * ObjectMessage -> Body.add ( Object );
+ * </p>
+ * Note: this method will always set the bodies byte array
+ * to be backward compatible.
+ *
+ * @param fromJMSMessage
+ * @param toESBMessage
+ * @throws JMSException
+ * @throws IOException
+ */
+ private void setESBMessageBody( final javax.jms.Message fromJMSMessage, final Message toESBMessage ) throws JMSException, IOException
+ {
+ byte[] bodyAsBytes = null;
+
+ if (fromJMSMessage instanceof TextMessage)
+ {
+ final String text = ((TextMessage) fromJMSMessage).getText();
+ toESBMessage.getBody().add( text );
+ bodyAsBytes = text.getBytes();
+ }
+ else if (fromJMSMessage instanceof BytesMessage)
+ {
+ final BytesMessage jBytes = (BytesMessage) fromJMSMessage;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] ba = new byte[1000];
+ int iQread;
+ while (-1 != (iQread = jBytes.readBytes(ba)))
+ {
+ if (iQread > 0) out.write(ba, 0, iQread);
+ out.close();
+ }
+ bodyAsBytes = out.toByteArray();
+ }
+ else if (fromJMSMessage instanceof ObjectMessage)
+ {
+ final Object object = ((ObjectMessage) fromJMSMessage).getObject();
+ toESBMessage.getBody().add( object );
+
+ bodyAsBytes = object.toString() .getBytes();
+ }
+ else
+ log.warn("Message type " + fromJMSMessage.getClass().getSimpleName() + " not supported - Message is ignored");
+
+ // Always set the byte array content on the body object to be backward compatible
+ // TODO: Should be removed at some point.
+ setByteArrayOnBody( toESBMessage, bodyAsBytes );
+ }
+
+ @Deprecated
+ private void setByteArrayOnBody( final Message esbMessage, final byte[] bytes )
+ {
+ esbMessage.getBody().setByteArray( bytes );
+ }
} // ____________________________________________________
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -35,9 +35,10 @@
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPool;
import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.notification.jms.DefaultJMSPropertiesSetter;
+import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
/**
* Abstract class that defines the behaviour of NotifyQueues and NotifyTopics
@@ -55,6 +56,11 @@
public abstract class NotifyJMS extends NotificationTarget
{
protected Logger log = Logger.getLogger(this.getClass());
+
+ /**
+ * Strategy for setting JMSProperties
+ */
+ private JMSPropertiesSetter jmsPropertiesStrategy = new DefaultJMSPropertiesSetter();
/**
* Abstract method - All classes that extend NotifyJMS must implement it
@@ -167,40 +173,39 @@
* Send a JMS message using p_o to fill in the message content and the list
* of message properties that will be added to the JMS message header fields
*
- * @param message
+ * @param esbMessage
* Object - This object or thie object's toString() method will
* supply contents of JMS message
* @see NotifyJMS#CHILD_MSG_PROP
*/
- public void sendNotification (org.jboss.soa.esb.message.Message message) throws NotificationException
+ public void sendNotification (org.jboss.soa.esb.message.Message esbMessage) throws NotificationException
{
try
{
- Message oMsg = null;
+ Message jmsMessage = null;
- if (MessageType.JAVA_SERIALIZED.equals(message.getType()))
+ if (MessageType.JAVA_SERIALIZED.equals(esbMessage.getType()))
{
- oMsg = m_oSess[0].createObjectMessage(message.getBody().getByteArray());
+ jmsMessage = m_oSess[0].createObjectMessage(esbMessage.getBody().getByteArray());
}
else
{
String content=null;
- if (message.getBody().getByteArray()!=null) {
- content = new String(message.getBody().getByteArray());
+ if (esbMessage.getBody().getByteArray()!=null) {
+ content = new String(esbMessage.getBody().getByteArray());
}
- oMsg = m_oSess[0].createTextMessage(content);
+ jmsMessage = m_oSess[0].createTextMessage(content);
}
- if (message.getBody().get(Environment.JMS_MESSAGE_ID)!=null) {
- oMsg.setJMSCorrelationID((String)message.getBody().get(Environment.JMS_MESSAGE_ID));
- }
-
+
+ setJMSProperties( esbMessage, jmsMessage );
+
for (Iterator II = m_oProps.keySet().iterator(); II.hasNext();)
{
String sKey = (String) II.next();
String sVal = m_oProps.getProperty(sKey);
- oMsg.setStringProperty(sKey, sVal);
+ jmsMessage.setStringProperty(sKey, sVal);
}
- sendToAll(oMsg);
+ sendToAll(jmsMessage);
}
catch (JMSException ex)
{
@@ -209,13 +214,25 @@
} // __________________________________
/**
+ * This method will set appropriate JMSProperties on the outgoing JMSMessage object.
+ * </p>
+ * Sublclasses can either override this method add a different behaviour, or they can
+ * set the strategy by calling {@link #setJmsPropertiesStrategy(JMSPropertiesSetter)}.
+ * </p>
+ * See {@link org.jboss.soa.esb.notification.jms.JMSPropertiesSetter} for more info.
+ */
+ protected void setJMSProperties(org.jboss.soa.esb.message.Message fromESBMessage, Message toJMSMessage ) throws JMSException {
+ jmsPropertiesStrategy.setJMSProperties( fromESBMessage, toJMSMessage );
+ }
+
+ /**
* Template method for sending JMS messages to destinations.
* </p>
* Subclasses implement send(Message, MessageProducer) which
* performs sending/publishing.
*
* @param p_oMsg the JMS Message to send.
- * @throws JMSException if any of the sends fail a JMSExcpetion will be
+ * @throws JMSException if any of the sends fail a JMSException will be
* thrown. The exception will contain an error
* message and stacktrace for every failed send.
*/
@@ -245,5 +262,16 @@
release();
}
}
+
+ /**
+ * Sets the strategy for handling the setting of properties on an outgoing
+ * JMS Message.
+ *
+ * @param jmsPropertiesStrategy the strategy to use.
+ */
+ public void setJmsPropertiesStrategy( JMSPropertiesSetter jmsPropertiesStrategy )
+ {
+ this.jmsPropertiesStrategy = jmsPropertiesStrategy;
+ }
} // ____________________________________________________________________________
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetter.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.notification.jms;
+
+import java.net.URI;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Properties;
+
+/**
+ * Default impl of JMSPropertiesSetter.
+ * </p>
+ * The following JMS Header fields are set from the ESB Message instance:
+ * <lu>
+ * <li> Call.setMessagID -> JMSMessageID
+ * <li> Call.setRelatesTo -> JMSCorrelationID
+ * <li> Call.setReplyTo -> JMSReplyTo
+ * <li> Properties( key = JSMPropertiesSetter.JMS_EXPIRATION ) -> JMSExpiration
+ * </lu>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class DefaultJMSPropertiesSetter implements JMSPropertiesSetter
+{
+ private Logger log = Logger.getLogger( DefaultJMSPropertiesSetter.class );
+
+ /**
+ * Set JMS Header fields on the outgoing JMS Message.
+ * </p>
+ * This implementation will simply set the JMSCorrelationID to
+ * the MessageID of the Message object.<br>
+ * Subclasses may override this method set other properties.
+ * </p>
+ *
+ * @param toJMSMessage the out-going JMSMessage object
+ * @param esbMsg the Message object from the ESB
+ * @throws JMSException
+ */
+ public void setJMSProperties( final org.jboss.soa.esb.message.Message fromESBMessage , final Message toJMSMessage ) throws JMSException
+ {
+ setJMSMessageID( fromESBMessage, toJMSMessage );
+ setJMSExpiration( fromESBMessage,toJMSMessage );
+ setProperties( fromESBMessage, toJMSMessage );
+ }
+
+ private void setJMSMessageID( final org.jboss.soa.esb.message.Message fromESBMessage , final Message toJMSMessage ) throws JMSException
+ {
+ final URI messageID = fromESBMessage.getHeader().getCall().getMessageID();
+ if ( messageID != null )
+ {
+ log.debug( "Setting outgoing JMSCorreletionID to : " + messageID );
+ toJMSMessage.setJMSCorrelationID( messageID.toString() );
+ }
+ }
+
+ private void setJMSExpiration( final org.jboss.soa.esb.message.Message fromESBMessage, final Message toJMSMessage ) throws JMSException
+ {
+ final Object expirationObj = fromESBMessage.getProperties().getProperty( JMS_EXPIRATION );
+ if ( expirationObj instanceof Long )
+ {
+ final Long expire = (Long) expirationObj;
+ log.debug( "Setting outgoing JMSExpiration to : " + expire );
+ toJMSMessage.setJMSExpiration( expire );
+ }
+ }
+
+ private void setProperties( final org.jboss.soa.esb.message.Message fromESBMessage, final Message toJMSMessage ) throws JMSException
+ {
+ Properties properties = fromESBMessage.getProperties();
+ for ( String key : properties.getNames() )
+ {
+ log.debug( "Property name : " + key );
+ Object property = properties.getProperty( key );
+ if ( property != null )
+ toJMSMessage.setObjectProperty( key, property );
+ }
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/JMSPropertiesSetter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/JMSPropertiesSetter.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/notification/jms/JMSPropertiesSetter.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.notification.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+/**
+ * Sets JMS Fields and Properties from an ESB Message instance
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public interface JMSPropertiesSetter
+{
+
+ /**
+ * Key used when setting the JMSExpiration as a
+ * property on an ESB Message instance.
+ */
+ String JMS_EXPIRATION = "javax.jms.message.expiration";
+
+ /**
+ * Sets JMS properties fields on the outgoing JMS Message.
+ * </p>
+ *
+ * @param jmsMessage the out-going JMS Message object
+ * @param esbMsg the Message object from the ESB
+ *
+ * @throws JMSException
+ */
+ void setJMSProperties( org.jboss.soa.esb.message.Message fromESBMsg, Message toJMSMessage ) throws JMSException;
+
+}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2007-08-01 20:41:11 UTC (rev 13940)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/JmsRouterIntegrationTest.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -22,32 +22,150 @@
package org.jboss.soa.esb.actions.routing;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.NamingException;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockejb.jms.ObjectMessageImpl;
+import org.mockejb.jms.TextMessageImpl;
-public class JmsRouterIntegrationTest extends TestCase
+/**
+ *
+ * @author John Doe
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class JmsRouterIntegrationTest
{
- public JmsRouterIntegrationTest ()
+ @SuppressWarnings ( "unused")
+ private Logger log = Logger.getLogger( JmsRouterIntegrationTest.class );
+
+ private final String messageID = "1234-junittest";
+ private final String bodyContent = "hello";
+ private Message msg;
+ private ConfigTree tree;
+
+ @Before
+ public void setup() throws URISyntaxException
{
+ msg = createESBMessageObject( messageID, bodyContent );
+ tree = createConfigTree();
}
+
+ @Test
+ public void process_unwrap_false() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ MockJMSRouter router = new MockJMSRouter(tree);
+ router.route( msg );
+
+ assertProcessContract( messageID, msg, router );
+ }
+
+ @Test
+ public void process_unwrap_true() throws ConfigurationException, NamingException, JMSException, ActionProcessingException, URISyntaxException
+ {
+ tree.setAttribute( "unwrap", "true" );
+ MockJMSRouter router = new MockJMSRouter( tree );
+
+ router.route( msg );
+
+ assertProcessContract( messageID, msg, router );
+ final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
+
+ assertTrue ( jmsMessage instanceof TextMessage );
+ final javax.jms.TextMessage textMessage = (TextMessage) jmsMessage;
+
+ assertEquals ( textMessage.getJMSCorrelationID(), messageID );
+ assertEquals ( textMessage.getText(), bodyContent );
+ }
- public void testRouter () throws Exception
+ @Test ( expected = ActionProcessingException.class )
+ public void route_negative() throws ConfigurationException, NamingException, JMSException, ActionProcessingException
{
- ConfigTree tree = new ConfigTree("test");
+ ConfigTree tree = createConfigTree();
+ JMSRouter router = new MockJMSRouter(tree);
+ router.route( "test" );
+ }
+
+ @Test
+ public void setJMSReplyTo_queue() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
+ {
+ final String queueName = "testQueue";
- tree.setAttribute("jndiName", "foobar");
+ TextMessageImpl jmsMessage = new TextMessageImpl();
- JMSRouter router = new JMSRouter(tree);
+ JMSEpr jmsEpr = new JMSEpr( JMSEpr.QUEUE_TYPE, queueName , "ConnectionFactory" );
+ msg.getHeader().getCall().setReplyTo( jmsEpr );
+ JMSRouter router = new JMSRouter( createConfigTree() );
+ router.setJMSReplyTo( jmsMessage, msg );
+
+ Destination replyTo = jmsMessage.getJMSReplyTo();
+ assertTrue( replyTo instanceof Queue );
+ Queue replyToQueue = (Queue) replyTo;
+ assertEquals( queueName , replyToQueue.getQueueName() );
+
+ }
+
+ @Test
+ @Ignore
+ public void setJMSReplyTo_topic() throws JMSException, URISyntaxException, ConfigurationException, NamingException, ConnectionException
+ {
+ final String queueName = "testTopic";
+
+ TextMessageImpl jmsMessage = new TextMessageImpl();
+
+ JMSEpr jmsEpr = new JMSEpr( JMSEpr.TOPIC_TYPE, queueName , "ConnectionFactory" );
+ msg.getHeader().getCall().setReplyTo( jmsEpr );
+ JMSRouter router = new JMSRouter( createConfigTree() );
+ router.setJMSReplyTo( jmsMessage, msg );
+
+ Destination replyTo = jmsMessage.getJMSReplyTo();
+ assertTrue( replyTo instanceof Topic );
+ Topic replyToTopic = (Topic) replyTo;
+ assertEquals( queueName , replyToTopic.getTopicName() );
+ }
+
+ /*
+ * Not quite sure that this is supposed to be testing.
+ * Can we remove this test? /Daniel
+ */
+ @Test
+ @Ignore
+ public void testRouter () throws Exception
+ {
boolean exception = false;
Message msg = MessageFactory.getInstance().getMessage();
msg.getBody().setByteArray("hello world".getBytes());
-
+ JMSRouter router = new JMSRouter( createConfigTree() );
try
{
router.route(msg);
@@ -79,4 +197,83 @@
router.getOkNotification(null);
}
+ private void assertProcessContract( final String messageID, final Message msg, JMSRouter router ) throws ActionProcessingException, JMSException
+ {
+ final Message message = router.process ( msg );
+ assertNull ( "Routers process should return null", message );
+ final javax.jms.Message jmsMessage = ((MockJMSRouter) router).getJmsMessage();
+ assertEquals ( jmsMessage.getJMSCorrelationID(), messageID );
+ }
+
+ private static class MockJMSRouter extends JMSRouter
+ {
+ @SuppressWarnings ( "unused" )
+ private Logger log = Logger.getLogger( MockJMSRouter.class );
+
+ private javax.jms.Message jmsMessage;
+
+ public MockJMSRouter(ConfigTree propertiesTree) throws ConfigurationException, NamingException, JMSException
+ {
+ super( propertiesTree );
+ }
+
+ public MockJMSRouter(String actionName, List<KeyValuePair> properties) throws ConfigurationException
+ {
+ super( actionName, properties );
+ }
+
+ @Override
+ protected void createQueueSetup( String queueName ) throws ConfigurationException { }
+
+ @Override
+ protected void send( javax.jms.Message jmsMessage ) throws JMSException
+ {
+ this.jmsMessage = jmsMessage;
+ }
+
+ public javax.jms.Message getJmsMessage()
+ {
+ return jmsMessage;
+ }
+
+ @Override
+ protected javax.jms.Message createJMSMessageWithObjectType( Object objectFromBody ) throws JMSException
+ {
+ TextMessageImpl textMessage = new TextMessageImpl();
+ textMessage.setText( new String ((byte[])objectFromBody) );
+ return textMessage;
+ }
+
+ @Override
+ protected javax.jms.Message createObjectMessage( Object message ) throws JMSException
+ {
+ ObjectMessageImpl impl = new ObjectMessageImpl();
+ impl.setObject( (Serializable) message );
+ return impl;
+ }
+ }
+
+ private Message createESBMessageObject( final String messageID, final String body) throws URISyntaxException
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ msg.getHeader().getCall().setMessageID( new URI ( "1234-junittest" ) );
+ msg.getBody().setByteArray( body.getBytes());
+ return msg;
+ }
+
+ private static ConfigTree createConfigTree()
+ {
+ ConfigTree tree = new ConfigTree("test");
+ tree.setAttribute("jndiName", "/queue/A");
+ return tree;
+ }
+
+ /*
+ * Just here to help Ant to find annotated test.
+ */
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter( JmsRouterIntegrationTest.class );
+ }
+
}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/DefaultESBPropertiesSetterUnitTest.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import static org.junit.Assert.assertEquals;
+import java.net.URI;
+import javax.jms.JMSException;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.TextMessageImpl;
+
+/**
+ * Unit test for DefaultESBPropertiesSetter
+ * </p>
+ *
+ * @author <a href="mailto:daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @since 4.2
+ */
+public class DefaultESBPropertiesSetterUnitTest
+{
+ @SuppressWarnings ("unused")
+ private Logger log = Logger .getLogger( DefaultESBPropertiesSetterUnitTest.class );
+
+ private final static String jmsMessageID = "123456780";
+ private final static String jmsCorrelationID = "YYXX-123456780-GG";
+ private ESBPropertiesSetter strategy;
+ private javax.jms.Message fromJMSTextMessage;
+ private Message toESBMessage;
+
+ @Test (expected = JMSException.class )
+ public void setPropertiesFromJMSMessage_MessageID_negative() throws JMSException
+ {
+ log.debug( "The following Exception is expected: ");
+ fromJMSTextMessage.setJMSMessageID( " -- // == " );
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+ }
+
+ @Test
+ public void setPropertiesFromJMSMessage_MessageID() throws JMSException
+ {
+ fromJMSTextMessage.setJMSMessageID( jmsMessageID );
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ URI messageID = toESBMessage.getHeader().getCall().getMessageID();
+ assertEquals( jmsMessageID, messageID.toString() );
+ }
+
+ @Test
+ public void setPropertiesFromJMSMessage_CorrelationID() throws JMSException
+ {
+ fromJMSTextMessage.setJMSCorrelationID( jmsCorrelationID );
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ assertEquals( jmsCorrelationID, toESBMessage.getHeader().getCall().getRelatesTo().getFragment() );
+ }
+
+ @Test
+ public void setPropertiesFromJMSMessage_ReplyTo() throws JMSException
+ {
+ final String destinationName = "testDest";
+ final MockQueue queue = new MockQueue( destinationName );
+ fromJMSTextMessage.setJMSReplyTo( queue );
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ final EPR replyToEPR = toESBMessage.getHeader().getCall().getReplyTo();
+
+ assertEquals( "jms://localhost/testDest", replyToEPR.getAddr().getAddress() );
+
+ final String connectionFactory = replyToEPR.getAddr().getExtensionValue( JMSEpr.CONNECTION_FACTORY_TAG );
+ assertEquals ( "ConnectionFactory", connectionFactory );
+ }
+
+ @Test
+ public void setPropertiesFromJMSMessage_Expiration() throws JMSException
+ {
+ final long expire = 1234l;
+ fromJMSTextMessage.setJMSExpiration( expire );
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ assertEquals( expire, toESBMessage.getProperties().getProperty( JMSPropertiesSetter.JMS_EXPIRATION ) );
+ }
+
+ @Test
+ public void setPropertiesFromJMSMessage_withProperties() throws JMSException
+ {
+ final String propertyKey = "myProperty";
+ final String propertyValue = "myPropertyValue";
+ fromJMSTextMessage.setStringProperty( propertyKey, propertyValue );
+
+ strategy.setPropertiesFromJMSMessage( fromJMSTextMessage , toESBMessage );
+
+ assertEquals( propertyValue, toESBMessage.getProperties().getProperty( propertyKey )) ;
+ }
+
+ @Before
+ public void setup()
+ {
+ fromJMSTextMessage = new TextMessageImpl();
+ toESBMessage = MessageFactory.getInstance().getMessage();
+ strategy = new DefaultESBPropertiesSetter();
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/PackageJmsMessageContentsUnitTest.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,526 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.gateway;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Enumeration;
+
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.message.Message;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.ObjectMessageImpl;
+import org.mockejb.jms.TextMessageImpl;
+
+/**
+ * Unit test for PackageJmsMessageContents
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class PackageJmsMessageContentsUnitTest
+{
+ @SuppressWarnings ( "unused" )
+ private Logger log = Logger.getLogger( PackageJmsMessageContentsUnitTest.class );
+
+ private final static String messageContent = "Test Message Content";
+ private final static String jmsMessageID = "123456780";
+ private final static String jmsCorrelationID = "YYXX-123456780-GG";
+
+ private PackageJmsMessageContents packer;
+ private ObjectMessageImpl objectMsg;
+
+ @Before
+ public void setup()
+ {
+ packer = new PackageJmsMessageContents();
+ objectMsg = new ObjectMessageImpl();
+ }
+
+ @Test
+ public void process_ObjectMessage() throws JMSException, IOException, URISyntaxException
+ {
+ objectMsg.setObject( messageContent );
+ Message message = packer.process( objectMsg );
+
+ assertThatByteArrayHasBeenSet( message );
+
+ Object object = message.getBody().get();
+ assertTrue ( object instanceof String );
+ assertEquals ( String.class.getName(), object.getClass().getName() );
+
+ assertEquals ( messageContent, new String ( message.getBody().getByteArray() ) );
+ }
+
+ @Test
+ public void process_TextMessage() throws JMSException, IOException, URISyntaxException
+ {
+ TextMessageImpl textMessage = new TextMessageImpl();
+ textMessage.setText( messageContent );
+ Message message = packer.process( textMessage );
+
+ assertThatByteArrayHasBeenSet( message );
+
+ Object object = message.getBody().get();
+ assertTrue ( object instanceof String );
+ final String actualContent = (String) object;
+ assertEquals ( messageContent, actualContent );
+ }
+
+ @Test
+ public void process_BytesMessage() throws JMSException, IOException, URISyntaxException
+ {
+ MockBytesMessage byteMessage = new MockBytesMessage();
+
+ Message message = packer.process( byteMessage );
+
+ assertThatByteArrayHasBeenSet( message );
+
+ }
+
+ @Test
+ public void process_with_JMSMessageID() throws JMSException, IOException, URISyntaxException
+ {
+ objectMsg.setObject( messageContent );
+ objectMsg.setJMSMessageID( jmsMessageID );
+
+ Message message = packer.process( objectMsg );
+
+ final String actualContent = new String ( message.getBody().getByteArray() );
+ assertEquals ( messageContent, actualContent );
+ assertEquals ( new URI( jmsMessageID ), message.getHeader().getCall().getMessageID() );
+ }
+
+ @Test
+ public void process_with_JMSCorrelationID() throws JMSException, IOException, URISyntaxException
+ {
+ objectMsg.setObject( messageContent );
+ objectMsg.setJMSCorrelationID( jmsCorrelationID );
+
+ Message message = packer.process( objectMsg );
+
+ assertEquals ( jmsCorrelationID, message.getHeader().getCall().getRelatesTo().getFragment() );
+ }
+
+ @Test
+ public void process_with_Properties() throws JMSException, IOException, URISyntaxException
+ {
+ final String propertyKey = "myProperty";
+ final String propertyValue = "myPropertyValue";
+ objectMsg.setObject( messageContent );
+ objectMsg.setObjectProperty( propertyKey, propertyValue );
+
+ Message message = packer.process( objectMsg );
+
+ assertEquals ( propertyValue, message.getProperties().getProperty( propertyKey ) );
+ }
+
+ @Test
+ public void process_with_JMSReplyTo() throws JMSException, IOException, URISyntaxException
+ {
+ objectMsg.setObject( messageContent );
+ MockQueue jmsReplyToQueue = new MockQueue( "mockReplyToQueueName");
+ objectMsg.setJMSReplyTo( jmsReplyToQueue );
+
+ Message message = packer.process( objectMsg );
+
+ EPR replyTo = message.getHeader().getCall().getReplyTo();
+ assertTrue( replyTo instanceof JMSEpr );
+ JMSEpr jmsEpr = (JMSEpr) replyTo;
+ assertEquals ( jmsReplyToQueue.getQueueName() , jmsEpr.getDestinationName() );
+ }
+
+ /**
+ * This asserts that the JMS Message's bodies content
+ * is always set on the ESB Message object as a byte array.
+ *
+ * This is a backward compability issue and more on the reason for
+ * this can be found in this ESB User Forum thread:
+ * http://www.jboss.com/index.html?module=bb&op=viewtopic&t=113726&postdays=0&postorder=asc&start=10
+ *
+ */
+ private void assertThatByteArrayHasBeenSet( Message esbMessage )
+ {
+ assertNotNull ("byte array must always be set regardless of the type of JMS Message", esbMessage.getBody().getByteArray() );
+ }
+
+ /**
+ * Just here to get Ant to find annotated test.
+ */
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter( PackageJmsMessageContentsUnitTest.class );
+ }
+
+ private static class MockBytesMessage implements BytesMessage
+ {
+
+ public long getBodyLength() throws JMSException
+ {
+ return 0;
+ }
+
+ public boolean readBoolean() throws JMSException
+ {
+ return false;
+ }
+
+ public byte readByte() throws JMSException
+ {
+ return 0;
+ }
+
+ public int readBytes( byte[] arg0 ) throws JMSException
+ {
+ return -1;
+ }
+
+ public int readBytes( byte[] arg0, int arg1 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public char readChar() throws JMSException
+ {
+ return 0;
+ }
+
+ public double readDouble() throws JMSException
+ {
+ return 0;
+ }
+
+ public float readFloat() throws JMSException
+ {
+ return 0;
+ }
+
+ public int readInt() throws JMSException
+ {
+ return 0;
+ }
+
+ public long readLong() throws JMSException
+ {
+ return 0;
+ }
+
+ public short readShort() throws JMSException
+ {
+ return 0;
+ }
+
+ public String readUTF() throws JMSException
+ {
+ return null;
+ }
+
+ public int readUnsignedByte() throws JMSException
+ {
+ return 0;
+ }
+
+ public int readUnsignedShort() throws JMSException
+ {
+ return 0;
+ }
+
+ public void reset() throws JMSException
+ {
+ }
+
+ public void writeBoolean( boolean arg0 ) throws JMSException
+ {
+ }
+
+ public void writeByte( byte arg0 ) throws JMSException
+ {
+ }
+
+ public void writeBytes( byte[] arg0 ) throws JMSException
+ {
+ }
+
+ public void writeBytes( byte[] arg0, int arg1, int arg2 )
+ throws JMSException
+ {
+ }
+
+ public void writeChar( char arg0 ) throws JMSException
+ {
+ }
+
+ public void writeDouble( double arg0 ) throws JMSException
+ {
+ }
+
+ public void writeFloat( float arg0 ) throws JMSException
+ {
+ }
+
+ public void writeInt( int arg0 ) throws JMSException
+ {
+ }
+
+ public void writeLong( long arg0 ) throws JMSException
+ {
+ }
+
+ public void writeObject( Object arg0 ) throws JMSException
+ {
+ }
+
+ public void writeShort( short arg0 ) throws JMSException
+ {
+ }
+
+ public void writeUTF( String arg0 ) throws JMSException
+ {
+ }
+
+ public void acknowledge() throws JMSException
+ {
+ }
+
+ public void clearBody() throws JMSException
+ {
+ }
+
+ public void clearProperties() throws JMSException
+ {
+ }
+
+ public boolean getBooleanProperty( String arg0 ) throws JMSException
+ {
+ return false;
+ }
+
+ public byte getByteProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public double getDoubleProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public float getFloatProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public int getIntProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public String getJMSCorrelationID() throws JMSException
+ {
+ return null;
+ }
+
+ public byte[] getJMSCorrelationIDAsBytes() throws JMSException
+ {
+ return null;
+ }
+
+ public int getJMSDeliveryMode() throws JMSException
+ {
+ return 0;
+ }
+
+ public Destination getJMSDestination() throws JMSException
+ {
+ return null;
+ }
+
+ public long getJMSExpiration() throws JMSException
+ {
+ return 0;
+ }
+
+ public String getJMSMessageID() throws JMSException
+ {
+ return null;
+ }
+
+ public int getJMSPriority() throws JMSException
+ {
+ return 0;
+ }
+
+ public boolean getJMSRedelivered() throws JMSException
+ {
+ return false;
+ }
+
+ public Destination getJMSReplyTo() throws JMSException
+ {
+ return null;
+ }
+
+ public long getJMSTimestamp() throws JMSException
+ {
+ return 0;
+ }
+
+ public String getJMSType() throws JMSException
+ {
+ return null;
+ }
+
+ public long getLongProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public Object getObjectProperty( String arg0 ) throws JMSException
+ {
+ return null;
+ }
+
+ public Enumeration getPropertyNames() throws JMSException
+ {
+ return null;
+ }
+
+ public short getShortProperty( String arg0 ) throws JMSException
+ {
+ return 0;
+ }
+
+ public String getStringProperty( String arg0 ) throws JMSException
+ {
+ return null;
+ }
+
+ public boolean propertyExists( String arg0 ) throws JMSException
+ {
+ return false;
+ }
+
+ public void setBooleanProperty( String arg0, boolean arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setByteProperty( String arg0, byte arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setDoubleProperty( String arg0, double arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setFloatProperty( String arg0, float arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setIntProperty( String arg0, int arg1 ) throws JMSException
+ {
+ }
+
+ public void setJMSCorrelationID( String arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSCorrelationIDAsBytes( byte[] arg0 )
+ throws JMSException
+ {
+ }
+
+ public void setJMSDeliveryMode( int arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSDestination( Destination arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSExpiration( long arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSMessageID( String arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSPriority( int arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSRedelivered( boolean arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSReplyTo( Destination arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSTimestamp( long arg0 ) throws JMSException
+ {
+ }
+
+ public void setJMSType( String arg0 ) throws JMSException
+ {
+ }
+
+ public void setLongProperty( String arg0, long arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setObjectProperty( String arg0, Object arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setShortProperty( String arg0, short arg1 )
+ throws JMSException
+ {
+ }
+
+ public void setStringProperty( String arg0, String arg1 )
+ throws JMSException
+ {
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyJMSUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyJMSUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyJMSUnitTest.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.notification;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.jms.BytesMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicSubscriber;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockejb.jms.TextMessageImpl;
+
+/**
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class NotifyJMSUnitTest
+{
+ private final String messageID = "1234-junittest";
+ private MockNotifyJMS notifyJMS;
+ private org.jboss.soa.esb.message.Message message;
+
+ @Test
+ public void sendNotification() throws ConfigurationException, NotificationException, JMSException, URISyntaxException
+ {
+ notifyJMS.sendNotification( message );
+
+ assertEquals ( notifyJMS.getMessage().getJMSCorrelationID(), messageID );
+ }
+
+ @Test
+ @Ignore
+ public void addMessageProperties() throws ConfigurationException, NotificationException, JMSException, URISyntaxException
+ {
+ //TODO: add test for JIRA http://jira.jboss.com/jira/browse/JBESB-701. DanielB 2007-08-01
+
+ //add message properties ...
+ notifyJMS.sendNotification( message );
+ assertEquals ( notifyJMS.getMessage().getJMSCorrelationID(), messageID );
+ }
+
+ @Before
+ public void setup() throws ConfigurationException, URISyntaxException
+ {
+ notifyJMS = new MockNotifyJMS( new ConfigTree("") );
+ message = MessageFactory.getInstance().getMessage();
+ message.getHeader().getCall().setMessageID( new URI( messageID ) ) ;
+ }
+
+
+ private static class MockNotifyJMS extends NotifyJMS
+ {
+ private Message message;
+
+ protected MockNotifyJMS(ConfigTree p_oP) throws ConfigurationException
+ {
+ super( p_oP );
+ m_oSess = new Session[1];
+ m_oSess[0] = new MockJMSSession();
+ }
+
+ @Override
+ protected void send( Message jmsMessage, MessageProducer msgProducer ) throws JMSException { }
+
+ @Override
+ protected void sendToAll (final Message jmsMessage) throws JMSException
+ {
+ message = jmsMessage;
+ }
+
+ public Message getMessage()
+ {
+ return message;
+ }
+
+ }
+
+ private static class MockJMSSession implements Session
+ {
+ /**
+ * Creates a mockejb.jms.TextMessageImpl
+ */
+ public TextMessage createTextMessage( String text ) throws JMSException
+ {
+ return new TextMessageImpl ( text );
+ }
+ public void close() throws JMSException { }
+ public void commit() throws JMSException { }
+ public QueueBrowser createBrowser( Queue arg0 ) throws JMSException { return null; }
+ public QueueBrowser createBrowser( Queue arg0, String arg1 ) throws JMSException { return null; }
+ public BytesMessage createBytesMessage() throws JMSException { return null; }
+ public MessageConsumer createConsumer( Destination arg0 ) throws JMSException { return null; }
+ public MessageConsumer createConsumer( Destination arg0, String arg1 ) throws JMSException { return null; }
+ public MessageConsumer createConsumer( Destination arg0, String arg1, boolean arg2 ) throws JMSException { return null; }
+ public TopicSubscriber createDurableSubscriber( Topic arg0, String arg1 ) throws JMSException { return null; }
+ public TopicSubscriber createDurableSubscriber( Topic arg0, String arg1, String arg2, boolean arg3 ) throws JMSException { return null; }
+ public MapMessage createMapMessage() throws JMSException { return null; }
+ public Message createMessage() throws JMSException { return null; }
+ public ObjectMessage createObjectMessage() throws JMSException { return null; }
+ public ObjectMessage createObjectMessage( Serializable arg0 ) throws JMSException { return null; }
+ public MessageProducer createProducer( Destination arg0 ) throws JMSException { return null; }
+ public Queue createQueue( String arg0 ) throws JMSException { return null; }
+ public StreamMessage createStreamMessage() throws JMSException { return null; }
+ public TemporaryQueue createTemporaryQueue() throws JMSException { return null; }
+ public TemporaryTopic createTemporaryTopic() throws JMSException { return null; }
+ public TextMessage createTextMessage() throws JMSException { return null; }
+ public Topic createTopic( String arg0 ) throws JMSException { return null; }
+ public int getAcknowledgeMode() throws JMSException { return 0; }
+ public MessageListener getMessageListener() throws JMSException { return null; }
+ public boolean getTransacted() throws JMSException { return false; }
+ public void recover() throws JMSException { }
+ public void rollback() throws JMSException { }
+ public void run() { }
+ public void setMessageListener( MessageListener arg0 ) throws JMSException { }
+ public void unsubscribe( String arg0 ) throws JMSException { }
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetterUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/jms/DefaultJMSPropertiesSetterUnitTest.java 2007-08-01 20:55:53 UTC (rev 13941)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2006, JBoss Inc., and
+ * individual contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of individual
+ * contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.notification.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.jms.JMSException;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.notification.jms.DefaultJMSPropertiesSetter;
+import org.jboss.soa.esb.notification.jms.JMSPropertiesSetter;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockejb.jms.TextMessageImpl;
+
+/**
+ * Unit test for DefaultJMSPropertiesSetter.
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class DefaultJMSPropertiesSetterUnitTest
+{
+ @SuppressWarnings ("unused")
+ private Logger log = Logger .getLogger( DefaultJMSPropertiesSetterUnitTest.class );
+
+ private final String bodyContent = "hello";
+ private final String messageID = "1234-junittest";
+ private TextMessageImpl toJMSMessage;
+ private DefaultJMSPropertiesSetter strategy;
+ private Message fromESBMessage;
+
+ @Test
+ public void setJMSProperties_negative() throws JMSException, URISyntaxException
+ {
+ strategy.setJMSProperties( fromESBMessage, toJMSMessage );
+ assertNull (toJMSMessage.getJMSCorrelationID() );
+ }
+
+ @Test
+ public void setJMSProperties_with_set_correlationID() throws JMSException, URISyntaxException
+ {
+ fromESBMessage.getHeader().getCall().setMessageID( new URI( messageID ) ) ;
+
+ strategy.setJMSProperties( fromESBMessage, toJMSMessage );
+
+ assertEquals ( messageID, toJMSMessage.getJMSCorrelationID() );
+ }
+
+ @Test
+ public void setJMSProperties_with_set_expiration() throws JMSException, URISyntaxException
+ {
+ long expire = 1883l;
+ fromESBMessage.getProperties().setProperty( JMSPropertiesSetter.JMS_EXPIRATION, expire );
+
+ strategy.setJMSProperties( fromESBMessage, toJMSMessage );
+
+ assertEquals ( expire, toJMSMessage.getJMSExpiration() );
+ }
+
+ @Test
+ public void setJMSProperties_with_set_properties() throws JMSException, URISyntaxException
+ {
+ final String propertyKey = "myProperty";
+ final String propertyValue = "myPropertyValue";
+ fromESBMessage.getProperties().setProperty( propertyKey, propertyValue );
+
+ strategy.setJMSProperties( fromESBMessage, toJMSMessage );
+
+ assertEquals ( propertyValue, toJMSMessage.getStringProperty( propertyKey ) );
+ }
+
+ @Before
+ public void before() throws JMSException
+ {
+ toJMSMessage = new TextMessageImpl();
+ toJMSMessage.setText( bodyContent );
+ fromESBMessage = MessageFactory.getInstance().getMessage();
+ strategy = new DefaultJMSPropertiesSetter();
+ }
+
+}
More information about the jboss-svn-commits
mailing list