[jboss-svn-commits] JBL Code SVN: r15484 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/internal/soa/esb/couriers and 15 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 1 13:09:53 EDT 2007
Author: tfennelly
Date: 2007-10-01 13:09:53 -0400 (Mon, 01 Oct 2007)
New Revision: 15484
Added:
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerIntegrationTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/JMSUtil.java
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/README.html
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/build.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/deployment.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/client-console.png
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/esb-console.png
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbm-queue-service.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbmq-queue-service.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jboss-esb.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/lib/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/log4j.xml
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/MessageAugmentor.java
labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/TargetServiceAction.java
Removed:
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerUnitTest.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/assertion/AssertArgument.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/ESBConfigUtil.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1059
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/assertion/AssertArgument.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/assertion/AssertArgument.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/assertion/AssertArgument.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -20,6 +20,9 @@
package org.jboss.internal.soa.esb.assertion;
+import java.util.Collection;
+import java.util.Map;
+
/**
* Argument assertion utilities.
* <p/>
@@ -67,4 +70,30 @@
+ "' arg in method call.");
}
}
+
+ /**
+ * Assert that the argument is neither null nor empty.
+ * @param arg Argument.
+ * @param argName Argument name.
+ * @throws IllegalArgumentException Argument is null or empty.
+ */
+ public static void isNotNullAndNotEmpty(Collection arg, String argName) throws IllegalArgumentException {
+ if (arg == null || arg.isEmpty()) {
+ throw new IllegalArgumentException("null or empty '" + argName
+ + "' arg in method call.");
+ }
+ }
+
+ /**
+ * Assert that the argument is neither null nor empty.
+ * @param arg Argument.
+ * @param argName Argument name.
+ * @throws IllegalArgumentException Argument is null or empty.
+ */
+ public static void isNotNullAndNotEmpty(Map arg, String argName) throws IllegalArgumentException {
+ if (arg == null || arg.isEmpty()) {
+ throw new IllegalArgumentException("null or empty '" + argName
+ + "' arg in method call.");
+ }
+ }
}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -22,25 +22,6 @@
package org.jboss.internal.soa.esb.couriers;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.URISyntaxException;
-import java.util.List;
-import java.util.Properties;
-
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPool;
@@ -62,502 +43,537 @@
import org.jboss.soa.esb.util.Util;
import org.xml.sax.SAXException;
-public class JmsCourier implements PickUpOnlyCourier, DeliverOnlyCourier
-{
- /**
- * package protected constructor - Objects of Courier should only be
- * instantiated by the Factory
- *
- * @param epr
- */
- JmsCourier (JMSEpr epr) throws CourierException
- {
- this(epr, false);
- }
+import javax.jms.*;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Properties;
- /**
- * package protected constructor - Objects of Courier should only be
- * instantiated by the Factory
- *
- * @param epr
- */
- JmsCourier (JMSEpr epr, boolean isReceiver) throws CourierException
- {
- _isReceiver = isReceiver;
- _epr = epr;
- _sleepForRetries = 3000;
+public class JmsCourier implements PickUpOnlyCourier, DeliverOnlyCourier {
+ /**
+ * package protected constructor - Objects of Courier should only be
+ * instantiated by the Factory
+ *
+ * @param epr
+ */
+ public JmsCourier(JMSEpr epr) throws CourierException {
+ this(epr, false);
+ }
- if (!_isReceiver)
- try
- {
- _messageProperties = Util.propertiesFromSelector(_epr
- .getMessageSelector());
- }
- catch (Exception e)
- {
- throw new CourierException(e);
- }
+ /**
+ * package protected constructor - Objects of Courier should only be
+ * instantiated by the Factory
+ *
+ * @param epr
+ */
+ public JmsCourier(JMSEpr epr, boolean isReceiver) throws CourierException {
+ _isReceiver = isReceiver;
+ _epr = epr;
+ _sleepForRetries = 3000;
- } // ________________________________
+ if (!_isReceiver) {
+ try {
+ _messageProperties = Util.propertiesFromSelector(_epr
+ .getMessageSelector());
+ }
+ catch (Exception e) {
+ throw new CourierException(e);
+ }
+ }
+ } // ________________________________
- public void cleanup ()
- {
- if (null != _messageProducer) try
- {
- _messageProducer.close();
- }
- catch (JMSException e)
- {
- _logger.debug(e.getMessage(), e);
- }
+ public void cleanup() {
+ synchronized(this) {
+ if (_messageProducer != null) {
+ try {
+ _messageProducer.close();
+ } catch (Exception e) {
+ _logger.debug(e.getMessage(), e);
+ } finally {
+ _messageProducer = null;
+ closeSession();
+ }
+ }
- if (null != _messageConsumer) try
- {
- _messageConsumer.close();
- }
- catch (JMSException e)
- {
- _logger.debug(e.getMessage(), e);
- }
+ if (_messageConsumer != null) {
+ try {
+ _messageConsumer.close();
+ } catch (JMSException e) {
+ _logger.debug(e.getMessage(), e);
+ } finally {
+ _messageConsumer = null;
+ closeSession();
+ }
+ }
+ }
+ } // ________________________________
- if (null != _jmsSession)
- {
- _pool.closeSession(_jmsSession);
- }
+ private void closeSession() {
+ synchronized(this) {
+ if (jmsSession != null) {
+ try {
+ _pool.closeSession(jmsSession);
+ } finally {
+ jmsSession = null;
+ }
+ }
+ }
+ }
- _messageProducer = null;
- _messageConsumer = null;
- _jmsSession = null;
- } // ________________________________
+ public Session getJmsSession() throws CourierException {
+ if(jmsSession == null) {
+ synchronized(this) {
+ if(jmsSession == null) {
+ String sType;
- /**
- * package the ESB message in a javax.jms.ObjectMessage, and send it
- *
- * @param message
- * Message - the message to deliverAsync
- * @return boolean - the result of the delivery
- * @throws CourierException -
- * if problems were encountered
- */
- public boolean deliver (Message message) throws CourierException
- {
- if (_isReceiver)
- throw new CourierException("This is a read-only Courier");
-
- if (null == message) return false;
- if (null == _messageProducer) try
- {
- createMessageProducer();
- }
- catch (Exception e)
- {
- throw new CourierException(e);
- }
-
- while (null != _messageProducer)
- {
- try
- {
- // obtain Serializable version of arg0 and package it in a jms
- // ObjectMessage
- ObjectMessage msg = _jmsSession.createObjectMessage(Util
- .serialize(message));
- for (KeyValuePair kvp : _messageProperties)
- msg.setStringProperty(kvp.getKey(), kvp.getValue());
- setJMSProperties( message, msg );
- sendMessage(msg);
- return true;
- }
- catch (JMSException e)
- {
- jmsConnectRetry(e);
- }
- catch (Exception e)
- {
- throw new CourierException(e);
- }
- }
- return false;
- } // ________________________________
-
-
+ try {
+ sType = _epr.getDestinationType();
+ } catch (URISyntaxException e) {
+ throw new CourierException("EPR.getDestinationType failed.", e);
+ }
- /**
- * send/publish a javax.jms.ObjectMessage (that will contain the serialized
- * ESB Message)
- *
- * @param jmsMessage
- */
- private void sendMessage (javax.jms.Message jmsMessage) throws JMSException, URISyntaxException
- {
+ try {
+ if (JMSEpr.QUEUE_TYPE.equals(sType)) {
+ jmsSession = _pool.getQueueSession();
+ } else {
+ jmsSession = _pool.getTopicSession();
+ }
+ } catch (NamingException e) {
+ throw new CourierException("Failed to get JMS Session from pool.", e);
+ } catch (JMSException e) {
+ throw new CourierException("Failed to get JMS Session from pool.", e);
+ } catch (ConnectionException e) {
+ throw new CourierException("Failed to get JMS Session from pool.", e);
+ }
+ }
+ }
+ }
+
+ return jmsSession;
+ }
+
+ /**
+ * package the ESB message in a javax.jms.ObjectMessage, and send it
+ *
+ * @param message Message - the message to deliverAsync
+ * @return boolean - the result of the delivery
+ * @throws CourierException -
+ * if problems were encountered
+ */
+ public boolean deliver(org.jboss.soa.esb.message.Message message) throws CourierException {
+ ObjectMessage msg;
+
+ if (null == message) {
+ return false;
+ }
+
+ if (_messageProducer == null) {
+ createMessageProducer();
+ }
+
+ // Create the JMS message from the serialized ESB message...
+ try {
+ msg = getJmsSession().createObjectMessage(Util.serialize(message));
+ } catch (JMSException e) {
+ throw new CourierException("Failed to serialize ESB Message.", e);
+ } catch (ParserConfigurationException e) {
+ throw new CourierException("Failed to serialize ESB Message.", e);
+ } catch (IOException e) {
+ throw new CourierException("Failed to serialize ESB Message.", e);
+ }
+
+ // Set the JMS message from the ESB message...
+ try {
+ setJMSProperties(message, msg);
+ } catch (JMSException e) {
+ throw new CourierException("Failed to set JMS Message properties from ESB Message properties.", e);
+ }
+
+ return deliver(msg);
+ }
+
+ /**
+ * Send the JMS message.
+ *
+ * @param message Message - the message to deliverAsync
+ * @return boolean - the result of the delivery
+ * @throws CourierException -
+ * if problems were encountered
+ */
+ public boolean deliver(javax.jms.Message message) throws CourierException {
+ if (_isReceiver) {
+ throw new CourierException("This is a read-only Courier");
+ }
+
+ if (null == message) {
+ return false;
+ }
+
+ if (_messageProducer == null) {
+ createMessageProducer();
+ }
+
+ while (null != _messageProducer) {
+ try {
+ for (KeyValuePair kvp : _messageProperties) {
+ String key = kvp.getKey();
+ if(message.getStringProperty(key) == null) {
+ message.setStringProperty(key, kvp.getValue());
+ }
+ }
+ sendMessage(message);
+ return true;
+ }
+ catch (JMSException e) {
+ jmsConnectRetry(e);
+ }
+ catch (Exception e) {
+ throw new CourierException(e);
+ }
+ }
+ return false;
+ } // ________________________________
+
+
+ /**
+ * send/publish a javax.jms.ObjectMessage (that will contain the serialized
+ * ESB Message)
+ *
+ * @param jmsMessage
+ */
+ private void sendMessage(javax.jms.Message jmsMessage) throws JMSException, URISyntaxException {
String sType = _epr.getDestinationType();
- if (JMSEpr.TOPIC_TYPE.equals(sType)) {
+ if (JMSEpr.TOPIC_TYPE.equals(sType)) {
((TopicPublisher) _messageProducer).publish(jmsMessage);
} else {
- _messageProducer.send(jmsMessage);
+ _messageProducer.send(jmsMessage);
}
-
- } // ________________________________
- private void jmsConnectRetry (Exception exc)
- {
- _logger.debug("JMS error. Attempting JMS reconnect.", exc);
- _jmsSession = null;
- _messageProducer = null;
- _messageConsumer = null;
+ } // ________________________________
- final int maxRetry = 5 ; // TODO Magic number here!!!
- for (int i1 = 0; i1 < maxRetry; i1++)
- {
- // try to reconnect to the queue
- try
- {
- if (_isReceiver) createMessageConsumer();
- else
- createMessageProducer();
- break ;
- }
- catch (Exception e)
- {
- if (i1 < maxRetry-1)
- {
- try
- {
- Thread.sleep(_sleepForRetries);
- }
- catch (InterruptedException e1)
- { // Just return after logging
- _logger.debug("Unexpected thread interupt exception.", e);
- break;
- }
- }
- else
- {
- _logger.debug("Failed to reconnect to JMS", e);
- }
- }
- }
- } // ________________________________
+ private void jmsConnectRetry(Exception exc) {
+ _logger.debug("JMS error. Attempting JMS reconnect.", exc);
- private void createMessageProducer () throws CourierException,
- MalformedEPRException
- {
+ synchronized(this) {
+ cleanup();
+
+ final int maxRetry = 5; // TODO Magic number here!!!
+ for (int i1 = 0; i1 < maxRetry; i1++) {
+ // try to reconnect to the queue
+ try {
+ if (_isReceiver) createMessageConsumer();
+ else
+ createMessageProducer();
+ break;
+ }
+ catch (Exception e) {
+ if (i1 < maxRetry - 1) {
+ try {
+ Thread.sleep(_sleepForRetries);
+ }
+ catch (InterruptedException e1) { // Just return after logging
+ _logger.debug("Unexpected thread interupt exception.", e);
+ break;
+ }
+ } else {
+ _logger.debug("Failed to reconnect to JMS", e);
+ }
+ }
+ }
+ }
+ } // ________________________________
+
+ private void createMessageProducer() throws CourierException {
Context oJndiCtx = null;
- try
- {
- oJndiCtx = NamingContext.getServerContext(_epr.getJndiEnvironment());
- String sFactoryClass = _epr.getConnectionFactory();
- if (Util.isNullString(sFactoryClass))
- sFactoryClass = "ConnectionFactory";
+ if (_messageProducer == null) {
+ synchronized(this) {
+ if (_messageProducer == null) {
+ try {
+ oJndiCtx = NamingContext.getServerContext(_epr.getJndiEnvironment());
- String sType = _epr.getDestinationType();
- _pool = JmsConnectionPoolContainer.getPool(_epr.getJndiEnvironment(), sFactoryClass, sType);
-
- if (JMSEpr.QUEUE_TYPE.equals(sType)) {
- QueueSession qSess = _pool.getQueueSession();
- _jmsSession = qSess;
- javax.jms.Queue queue = null;
- try {
- queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
- .getDestinationName());
- } catch (NamingException ne) {
- try {
- oJndiCtx = NamingContext.getFreshServerContext(_epr.getJndiEnvironment());
- queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
- .getDestinationName());
- } catch (NamingException nex) {
- //ActiveMQ
- queue = qSess.createQueue(_epr.getDestinationName());
+ String sFactoryClass = _epr.getConnectionFactory();
+ if (Util.isNullString(sFactoryClass))
+ sFactoryClass = "ConnectionFactory";
+
+ String sType = _epr.getDestinationType();
+ _pool = JmsConnectionPoolContainer.getPool(_epr.getJndiEnvironment(), sFactoryClass, sType);
+
+ if (JMSEpr.QUEUE_TYPE.equals(sType)) {
+ QueueSession qSess = (QueueSession) getJmsSession();
+ javax.jms.Queue queue = null;
+ try {
+ queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
+ .getDestinationName());
+ } catch (NamingException ne) {
+ try {
+ oJndiCtx = NamingContext.getFreshServerContext(_epr.getJndiEnvironment());
+ queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
+ .getDestinationName());
+ } catch (NamingException nex) {
+ //ActiveMQ
+ queue = qSess.createQueue(_epr.getDestinationName());
+ }
+ }
+ _messageProducer = qSess.createSender(queue);
+ } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
+ TopicSession tSess = (TopicSession) getJmsSession();
+ Topic topic = null;
+ try {
+ topic = (Topic) oJndiCtx.lookup(_epr
+ .getDestinationName());
+ }
+ catch (NamingException ne) {
+ topic = tSess.createTopic(_epr.getDestinationName());
+ }
+ _messageProducer = tSess.createPublisher(topic);
+ } else {
+ throw new CourierException("Unknown destination type");
+ }
}
- }
- _messageProducer = qSess.createSender(queue);
- } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
- TopicSession tSess = _pool.getTopicSession();
- _jmsSession = tSess;
- Topic topic = null;
- try
- {
- topic = (Topic) oJndiCtx.lookup(_epr
- .getDestinationName());
- }
- catch (NamingException ne)
- {
- topic = tSess.createTopic(_epr.getDestinationName());
- }
- _messageProducer = tSess.createPublisher(topic);
- } else {
- throw new CourierException("Unknown destination type");
+ catch (ConnectionException vex) {
+ throw new CourierException(vex);
+ }
+ catch (JMSException ex) {
+ _logger.debug("Error from JMS system.", ex);
+
+ throw new CourierException(ex);
+ }
+ catch (URISyntaxException ex) {
+ throw new CourierException(ex);
+ }
+ }
}
- }
- catch (ConnectionException vex)
- {
- throw new CourierException(vex);
}
- catch (JMSException ex)
- {
- _logger.debug("Error from JMS system.", ex);
-
- throw new CourierException(ex);
- }
- catch (NamingException ex)
- {
- _logger.debug("JMX lookup error.", ex);
-
- throw new CourierException(ex);
- }
- catch (URISyntaxException ex)
- {
- throw new MalformedEPRException(ex);
- }
- } // ________________________________
+ } // ________________________________
- public Message pickup (long millis) throws CourierException, CourierTimeoutException
- {
- if (!_isReceiver)
- throw new CourierException("This is an outgoing-only Courier");
- if (millis < 1)
- throw new IllegalArgumentException("Timeout millis must be > 0");
- if (null == _messageConsumer) try
- {
- createMessageConsumer();
- }
- catch (Exception e)
- {
- try
- {
- Thread.sleep(1000); // TODO magic number
- }
- catch (InterruptedException eI)
- {/* OK do nothing */
- }
- throw new CourierException("Unable to create Message Consumer", e);
- }
-
- javax.jms.Message jmsMessage = null;
- while (null != _messageConsumer)
- {
- try
- {
- jmsMessage = _messageConsumer.receive(millis);
- break;
- }
- catch (JMSException e)
- {
- jmsConnectRetry(e);
- }
- catch (Exception e)
- {
- throw new CourierException(e);
- }
- }
- if (null == jmsMessage) return null;
-
- if (!(jmsMessage instanceof ObjectMessage))
- {
- _logger.error("Unsupported JMS message type: " + jmsMessage
- .getClass().getName());
- return null;
- }
- try
- {
- Serializable obj = (Serializable) ((ObjectMessage) jmsMessage)
- .getObject();
-
- Message msg = Util.deserialize(obj);
- setPropertiesFromJMSMessage( jmsMessage, msg );
-
- /*
- * If this is fault message, then throw an exception with the contents. With the
- * exception of user-defined exceptions, faults will have nothing in the body, properties etc.
- */
-
- if (Type.isFaultMessage(msg))
- Factory.createExceptionFromFault(msg);
-
- return msg;
- }
- catch (JMSException e1)
- {
- _logger.error("Failed to read Serialized Object from JMS message.",
- e1);
- return null;
- }
- catch (ClassCastException e2)
- {
- _logger
- .error(
- "Object in JMS message is not a org.jboss.soa.esb.message.Message",
- e2);
- }
- catch (IOException e3)
- {
- _logger.error("Object in JMS message is not a Serializeable", e3);
- }
- catch (ParserConfigurationException e4)
- {
- _logger.error("Object in JMS message has invalid XML", e4);
- }
- catch (SAXException e5)
- {
- _logger.error("Object in JMS message has invalid XML", e5);
- }
- return null;
- } // ________________________________
-
- /**
- * 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;
- }
-
- /**
- * Set the {@link ESBPropertiesSetter} to be used
- *
- * @param esbPropertiesStrategy the strategy to be used
- */
- public void setEsbPropertiesStrategy( ESBPropertiesSetter esbPropertiesStrategy )
- {
- this.esbPropertiesStrategy = esbPropertiesStrategy;
- }
-
- /**
- * 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, javax.jms.Message toJMSMessage ) throws JMSException {
- jmsPropertiesStrategy.setJMSProperties( fromESBMessage, toJMSMessage );
- }
-
- /**
- * 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 );
- }
+ public Message pickup(long millis) throws CourierException, CourierTimeoutException {
+ javax.jms.Message jmsMessage = pickupPayload(millis);
- private void createMessageConsumer () throws CourierException, ConfigurationException, MalformedEPRException
- {
+ if(jmsMessage == null) {
+ return null;
+ }
+
+ if (!(jmsMessage instanceof ObjectMessage)) {
+ _logger.error("Unsupported JMS message type: " + jmsMessage.getClass().getName());
+ return null;
+ }
+ try {
+ Serializable obj = (Serializable) ((ObjectMessage) jmsMessage)
+ .getObject();
+
+ Message msg = Util.deserialize(obj);
+ setPropertiesFromJMSMessage(jmsMessage, msg);
+
+ /*
+ * If this is fault message, then throw an exception with the contents. With the
+ * exception of user-defined exceptions, faults will have nothing in the body, properties etc.
+ */
+
+ if (Type.isFaultMessage(msg))
+ Factory.createExceptionFromFault(msg);
+
+ return msg;
+ }
+ catch (JMSException e1) {
+ _logger.error("Failed to read Serialized Object from JMS message.",
+ e1);
+ return null;
+ }
+ catch (ClassCastException e2) {
+ _logger
+ .error(
+ "Object in JMS message is not a org.jboss.soa.esb.message.Message",
+ e2);
+ }
+ catch (IOException e3) {
+ _logger.error("Object in JMS message is not a Serializeable", e3);
+ }
+ catch (ParserConfigurationException e4) {
+ _logger.error("Object in JMS message has invalid XML", e4);
+ }
+ catch (SAXException e5) {
+ _logger.error("Object in JMS message has invalid XML", e5);
+ }
+ return null;
+ }
+
+ public javax.jms.Message pickupPayload(long millis) throws CourierException, CourierTimeoutException {
+ if (!_isReceiver)
+ throw new CourierException("This is an outgoing-only Courier");
+ if (millis < 1)
+ throw new IllegalArgumentException("Timeout millis must be > 0");
+ if (null == _messageConsumer) try {
+ createMessageConsumer();
+ }
+ catch (Exception e) {
+ try {
+ Thread.sleep(1000); // TODO magic number
+ }
+ catch (InterruptedException eI) {/* OK do nothing */
+ }
+ throw new CourierException("Unable to create Message Consumer", e);
+ }
+
+ javax.jms.Message jmsMessage = null;
+ while (null != _messageConsumer) {
+ try {
+ jmsMessage = _messageConsumer.receive(millis);
+ break;
+ }
+ catch (JMSException e) {
+ jmsConnectRetry(e);
+ }
+ catch (Exception e) {
+ throw new CourierException(e);
+ }
+ }
+ return jmsMessage;
+ } // ________________________________
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Set the {@link ESBPropertiesSetter} to be used
+ *
+ * @param esbPropertiesStrategy the strategy to be used
+ */
+ public void setEsbPropertiesStrategy(ESBPropertiesSetter esbPropertiesStrategy) {
+ this.esbPropertiesStrategy = esbPropertiesStrategy;
+ }
+
+ /**
+ * 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, javax.jms.Message toJMSMessage) throws JMSException {
+ jmsPropertiesStrategy.setJMSProperties(fromESBMessage, toJMSMessage);
+ }
+
+ /**
+ * 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);
+ }
+
+ private void createMessageConsumer() throws CourierException, ConfigurationException, MalformedEPRException {
Context oJndiCtx = null;
- boolean success = false ;
- try
- {
- Properties environment = _epr.getJndiEnvironment();
- oJndiCtx = NamingContext.getServerContext(environment);
- if (null == oJndiCtx)
- throw new ConfigurationException(
- "Unable fo obtain jndi context");
-
- String sFactoryClass = _epr.getConnectionFactory();
- if (Util.isNullString(sFactoryClass))
- sFactoryClass = "ConnectionFactory";
-
- String sType = _epr.getDestinationType();
- _pool = JmsConnectionPoolContainer.getPool(environment, sFactoryClass, sType);
-
- if (JMSEpr.QUEUE_TYPE.equals(sType)) {
- QueueSession qSess = _pool.getQueueSession();
- _jmsSession = qSess;
- javax.jms.Queue queue = null;
- try {
- queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
- .getDestinationName());
- } catch (NamingException ne) {
+
+ if (_messageConsumer == null) {
+ synchronized(this) {
+ if (_messageConsumer == null) {
+ boolean success = false;
try {
- oJndiCtx = NamingContext.getFreshServerContext(environment);
- queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
- .getDestinationName());
- } catch (NamingException nex) {
- //ActiveMQ
- queue = qSess.createQueue(_epr.getDestinationName());
+ Properties environment = _epr.getJndiEnvironment();
+ oJndiCtx = NamingContext.getServerContext(environment);
+ if (null == oJndiCtx)
+ throw new ConfigurationException(
+ "Unable fo obtain jndi context");
+
+ String sFactoryClass = _epr.getConnectionFactory();
+ if (Util.isNullString(sFactoryClass))
+ sFactoryClass = "ConnectionFactory";
+
+ String sType = _epr.getDestinationType();
+ _pool = JmsConnectionPoolContainer.getPool(environment, sFactoryClass, sType);
+
+ if (JMSEpr.QUEUE_TYPE.equals(sType)) {
+ QueueSession qSess = (QueueSession) getJmsSession();
+ javax.jms.Queue queue = null;
+ try {
+ queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
+ .getDestinationName());
+ } catch (NamingException ne) {
+ try {
+ oJndiCtx = NamingContext.getFreshServerContext(environment);
+ queue = (javax.jms.Queue) oJndiCtx.lookup(_epr
+ .getDestinationName());
+ } catch (NamingException nex) {
+ //ActiveMQ
+ queue = qSess.createQueue(_epr.getDestinationName());
+ }
+ }
+ _messageConsumer = qSess.createReceiver(queue, _epr.getMessageSelector());
+ } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
+ TopicSession tSess = (TopicSession) getJmsSession();
+ Topic topic = tSess.createTopic(_epr.getDestinationName());
+ _messageConsumer = tSess.createConsumer(topic, _epr
+ .getMessageSelector());
+ } else {
+ throw new CourierException("Unknown destination type");
+ }
+ success = true;
}
- }
- _messageConsumer = qSess.createReceiver(queue, _epr.getMessageSelector());
- } else if (JMSEpr.TOPIC_TYPE.equals(sType)) {
- TopicSession tSess = _pool.getTopicSession();
- _jmsSession = tSess;
- Topic topic = tSess.createTopic(_epr.getDestinationName());
- _messageConsumer = tSess.createConsumer(topic, _epr
- .getMessageSelector());
- } else {
- throw new CourierException("Unknown destination type");
- }
- success = true ;
- }
- catch (ConnectionException cex)
- {
- throw new CourierException(cex);
- }
- catch (JMSException ex)
- {
- _logger.debug("Error from JMS system.", ex);
-
- throw new CourierException(ex);
- }
- catch (NamingException ex)
- {
- throw new ConfigurationException(ex);
- }
- catch (URISyntaxException ex)
- {
- throw new MalformedEPRException(ex);
- }
- finally
- {
- if (!success)
- {
- if (_jmsSession != null)
- {
- _pool.closeSession(_jmsSession) ;
- _jmsSession = null ;
+ catch (ConnectionException cex) {
+ throw new CourierException(cex);
+ }
+ catch (JMSException ex) {
+ _logger.debug("Error from JMS system.", ex);
+
+ throw new CourierException(ex);
+ }
+ catch (URISyntaxException ex) {
+ throw new MalformedEPRException(ex);
+ }
+ finally {
+ if (!success) {
+ closeSession();
}
- _pool = null ;
}
}
- } // ________________________________
+ }
+ }
+ } // ________________________________
- long _sleepForRetries = 3000; // milliseconds
+ long _sleepForRetries = 3000; // milliseconds
- protected boolean _isReceiver;
+ protected boolean _isReceiver;
- protected JMSEpr _epr;
+ protected JMSEpr _epr;
- protected Logger _logger = Logger.getLogger(JmsCourier.class);
+ protected Logger _logger = Logger.getLogger(JmsCourier.class);
- protected String _messageSelector;
+ protected String _messageSelector;
- protected Session _jmsSession;
+ protected volatile Session jmsSession;
- protected MessageProducer _messageProducer;
+ protected volatile MessageProducer _messageProducer;
- protected MessageConsumer _messageConsumer;
+ protected volatile MessageConsumer _messageConsumer;
- protected List<KeyValuePair> _messageProperties;
-
+ protected List<KeyValuePair> _messageProperties;
+
protected JmsConnectionPool _pool;
-
+
/**
* Strategy for setting JMSProperties
*/
private JMSPropertiesSetter jmsPropertiesStrategy = new DefaultJMSPropertiesSetter();
-
+
/**
- * Strategy for setting JMS Properties on the ESB Message object created
- * by the process method.
+ * Strategy for setting JMS Properties on the ESB Message object created
+ * by the process method.
*/
private ESBPropertiesSetter esbPropertiesStrategy = new DefaultESBPropertiesSetter();
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -318,6 +318,14 @@
properties.put(extension.getTag(), extension.getValue());
}
}
+
+ if(!properties.containsKey(Context.INITIAL_CONTEXT_FACTORY)) {
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ }
+ if(!properties.containsKey(Context.PROVIDER_URL)) {
+ properties.setProperty(Context.PROVIDER_URL, "localhost");
+ }
+
return properties;
}
Copied: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerIntegrationTest.java (from rev 15471, labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerUnitTest.java)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerIntegrationTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerIntegrationTest.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.lifecycle;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.listeners.config.Configuration;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class EsbLifecycleListenerIntegrationTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ MockRegistry.install();
+ }
+
+ protected void tearDown() throws Exception {
+ MockRegistry.uninstall();
+ }
+
+ public void test() throws ManagedLifecycleException {
+ String config = new String(StreamUtils.readStream(getClass().getResourceAsStream("config-01.xml")));
+ ManagedLifecycleController controller = Configuration.create(config);
+
+ controller.start();
+ controller.stop();
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerIntegrationTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerUnitTest.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/lifecycle/EsbLifecycleListenerUnitTest.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006, JBoss Inc.
- */
-package org.jboss.soa.esb.listeners.lifecycle;
-
-import junit.framework.TestCase;
-
-import org.jboss.internal.soa.esb.services.registry.MockRegistry;
-import org.jboss.internal.soa.esb.util.StreamUtils;
-import org.jboss.soa.esb.listeners.config.Configuration;
-
-/**
- * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
- */
-public class EsbLifecycleListenerUnitTest extends TestCase {
-
- protected void setUp() throws Exception {
- MockRegistry.install();
- }
-
- protected void tearDown() throws Exception {
- MockRegistry.uninstall();
- }
-
- public void test() throws ManagedLifecycleException {
- String config = new String(StreamUtils.readStream(getClass().getResourceAsStream("config-01.xml")));
- ManagedLifecycleController controller = Configuration.create(config);
-
- controller.start();
- controller.stop();
- }
-}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -108,14 +108,17 @@
notifyQueues = new NotifyQueues(rootEl);
} catch (Exception e) {
- log.error(e);
+ e.printStackTrace();
+ fail("Test setup failed: " + e.getMessage());
}
}
@After
public void tearDown() throws Exception {
- notifyQueues.release();
- MockContextFactory.revertSetAsInitial();
+ if(notifyQueues != null) {
+ notifyQueues.release();
+ }
+ MockContextFactory.revertSetAsInitial();
}
@Test
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/ESBConfigUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/ESBConfigUtil.java 2007-10-01 15:39:45 UTC (rev 15483)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/ESBConfigUtil.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -26,6 +26,9 @@
import junit.framework.TestCase;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
import org.jboss.soa.esb.dom.YADOMUtil;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.config.Generator;
@@ -39,6 +42,8 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import javax.jms.JMSException;
+
/**
* Utility class for working with the ESB configuration.
*
@@ -121,10 +126,22 @@
public void startController() throws ParamRepositoryException, ConfigurationException, ManagedLifecycleException, SAXException {
ConfigTree listenerConfigTree = ConfigTree.fromElement(listenerConfig.getDocumentElement());
ConfigTree gatewayConfigTree = ConfigTree.fromElement(gatewayConfig.getDocumentElement());
+
+ MockCourierFactory.install();
+ MockRegistry.install();
+
controller = ConfigurationController.startController(generator.getModel(), listenerConfigTree, gatewayConfigTree);
}
public void stopController() {
- ConfigurationController.stopController(controller);
+ try {
+ ConfigurationController.stopController(controller);
+ } finally {
+ try {
+ MockRegistry.uninstall();
+ } finally {
+ MockCourierFactory.uninstall();
+ }
+ }
}
}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/JMSUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/JMSUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/JMSUtil.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,177 @@
+package org.jboss.soa.esb.testutils;
+
+import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.couriers.JmsCourier;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.JMSException;
+import javax.naming.Context;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+
+/**
+ * JMS Client utilities.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JMSUtil {
+
+ private static Logger logger = Logger.getLogger(JMSUtil.class);
+
+ /**
+ * Receive a message on the specified JMS Queue.
+ * @param queue The JMS Queue name.
+ */
+ public static javax.jms.Message receiveMessageOnQueue(String queue, long timeout) {
+ AssertArgument.isNotNullAndNotEmpty(queue, "queue");
+
+ JMSEpr epr = new JMSEpr(JMSEpr.QUEUE_TYPE, queue, "ConnectionFactory");
+ return receiveMessage(epr, timeout);
+ }
+
+ /**
+ * Receive a message on the specified JMS Topic.
+ * @param topic The JMS Topic name.
+ */
+ public static javax.jms.Message receiveMessageOnTopic(String topic, long timeout) {
+ AssertArgument.isNotNullAndNotEmpty(topic, "topic");
+
+ JMSEpr epr = new JMSEpr(JMSEpr.TOPIC_TYPE, topic, "ConnectionFactory");
+ return receiveMessage(epr, timeout);
+ }
+
+ /**
+ * Send the supplied message to the specified JMS Queue.
+ * @param message The message to send.
+ * @param queue The JMS Queue name.
+ * @param properties A property set for the JMS Message. Can be null.
+ */
+ public static void sendMessageToQueue(Serializable message, String queue, KeyValuePair[] properties) {
+ AssertArgument.isNotNull(message, "message");
+ AssertArgument.isNotNullAndNotEmpty(queue, "queue");
+
+ JMSEpr epr = new JMSEpr(JMSEpr.QUEUE_TYPE, queue, "ConnectionFactory");
+ deliverMessage(message, epr, properties);
+ }
+
+ /**
+ * Send the supplied message to the specified JMS Topic.
+ * @param message The message to send.
+ * @param topic The JMS Topic name.
+ * @param properties A property set for the JMS Message. Can be null.
+ */
+ public static void sendMessageToTopic(Serializable message, String topic, KeyValuePair[] properties) {
+ AssertArgument.isNotNull(message, "message");
+ AssertArgument.isNotNullAndNotEmpty(topic, "topic");
+
+ JMSEpr epr = new JMSEpr(JMSEpr.TOPIC_TYPE, topic, "ConnectionFactory");
+ deliverMessage(message, epr, properties);
+ }
+
+ private static Message receiveMessage(JMSEpr epr, long timeout) {
+ JmsCourier courier = null;
+
+ addJndiExtensions(epr);
+
+ try {
+ courier = new JmsCourier(epr, true);
+ } catch (CourierException e) {
+ throw new RuntimeException("Failed to create pickup courier for epr '" + epr + "': " + e.getMessage());
+ }
+
+ try {
+ return courier.pickupPayload(timeout);
+ } catch (CourierException e) {
+ throw new RuntimeException("Failed to pickup message on JMS epr '" + epr + "': " + e.getMessage());
+ } catch (CourierTimeoutException e) {
+ throw new RuntimeException("Failed to pickup message on JMS epr '" + epr + "': " + e.getMessage());
+ }
+ }
+
+ private static void deliverMessage(Serializable message, JMSEpr epr, KeyValuePair[] properties) {
+ String destType = null;
+ String destName = null;
+ JmsCourier courier = null;
+ ObjectMessage jmsMessage = null;
+
+ addJndiExtensions(epr);
+
+ try {
+ destType = epr.getDestinationType();
+ destName = epr.getDestinationName();
+ } catch (URISyntaxException e) {
+ // An exception on a getter method??? That's an interesting/new approach!!
+ throw new RuntimeException("Totally unexpected exception from a getter method: " + e.getMessage());
+ }
+
+ try {
+ courier = new JmsCourier(epr);
+ } catch (CourierException e) {
+ throw new RuntimeException("Failed to create JMSCourier to JMS " + destType + " '" + destName + "': " + e.getMessage());
+ }
+
+ try {
+ try {
+ jmsMessage = courier.getJmsSession().createObjectMessage(message);
+ } catch (CourierException e) {
+ throw new RuntimeException("Failed to get JMS Session for sending to JMS " + destType + " '" + destName + "': " + e.getMessage());
+ } catch (JMSException e) {
+ throw new RuntimeException("Failed to create JMS Message for sending to JMS " + destType + " '" + destName + "': " + e.getMessage());
+ }
+
+ if(properties != null) {
+ try {
+ setStringProperties(jmsMessage, properties);
+ } catch (JMSException e) {
+ throw new RuntimeException("Failed to set properties on the JMS Message to JMS " + destType + " '" + destName + "': " + e.getMessage());
+ }
+ }
+
+ try {
+ courier.deliver(jmsMessage);
+ } catch (CourierException e) {
+ throw new RuntimeException("Failed to deliver JMS Message to JMS " + destType + " '" + destName + "': " + e.getMessage());
+ }
+ } finally {
+ courier.cleanup();
+ }
+ }
+
+ private static void addJndiExtensions(JMSEpr epr) {
+ epr.getAddr().addExtension(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ epr.getAddr().addExtension(Context.PROVIDER_URL, "localhost");
+ }
+
+ private static void setStringProperties(Message msg, KeyValuePair[] properties) throws JMSException {
+ if(properties == null) {
+ return;
+ }
+
+ for(KeyValuePair property : properties) {
+ msg.setStringProperty(property.getKey(), property.getValue());
+ }
+ }
+
+ public static void main(String[] args) {
+ if(args.length < 3) {
+ throw new RuntimeException("Invalid arg list. 3 args expected. arg1: destName, arg2: destType (queue/topic), arg3: message");
+ }
+
+ String destName = args[0];
+ String destType = args[1];
+ String message = args[2];
+
+ if(destType.equals("queue")) {
+ sendMessageToQueue(message, destName, null);
+ } else if(destType.equals("topic")) {
+ sendMessageToTopic(message, destName, null);
+ } else {
+ throw new RuntimeException("Invalid 2nd arg value for destType. Must be one of 'queue' or 'topic'.");
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/testutils/JMSUtil.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/README.html
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/README.html (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/README.html 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,46 @@
+<html>
+ <head>
+ <title>JBossESB - JMS Topic Quickstart</title>
+ </head>
+ <body>
+ <h2>Overview</h2>
+ This sample demonstrates how to configure a pair of Services to receive a message
+ from the same JMS Topic via configurations of the <jms-listener> as a
+ "topic" based gateway.
+ <p/>
+ This quickstart simply sends a message to a JMS topic, on which service "MyService1"
+ and "MyService2" are listening. Both of these services then send a message to
+ "MyService3".
+<pre>
+ - -> MyService1 -> - |
+ | |
+ -> - "quickstart-topic" -| |- - - MyService3
+ | |
+ - -> MyService2 -> - |
+</pre>
+
+ <h2>Prerequisits</h2>
+ Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
+ and a more detailed descripton of the different ways to run the quickstarts.
+
+ <h2>To Run</h2>
+ <ol>
+ <li>In a command terminal window in this folder ("Window1"), type 'ant deploy'.</li>
+ <li>Open another command terminal window in this folder ("Window2"), type
+ 'ant runtest'.
+ </li>
+ <li>Check "Window1" and "Window2" for output.</li>
+ <li>To undeploy, type 'ant undeploy' in "Window1".</li>
+ </ol>
+
+ "Window1" should contain ESB Server side logging from the quickstart. The last 4 logs are the
+ logs of interest, showing the message being "processed" by MyService1 and MyService2, which forward
+ the messages on to MyService3.
+ <p/>
+ <img src="images/esb-console.png" />
+ <p/>
+ "Window2" should contain Client side logging from the quickstart.
+ <p/>
+ <img src="images/client-console.png" />
+ </body>
+</html>
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/build.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/build.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,20 @@
+<project name="Quickstart_jms_topic" default="deploy" basedir=".">
+
+ <description>
+ ${ant.project.name}
+ ${line.separator}
+ </description>
+
+ <!-- Import the base Ant build script... -->
+ <import file="../conf/base-build.xml"/>
+
+ <target name="runtest" depends="compile" description="Send a message to the JMS Topic">
+ <java fork="yes" classname="org.jboss.soa.esb.testutils.JMSUtil" failonerror="true"
+ classpathref="exec-classpath">
+ <arg value="quickstart_jmstopic_topic"/>
+ <arg value="topic"/>
+ <arg value="Hello"/>
+ </java>
+ </target>
+
+</project>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/build.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/deployment.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/deployment.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/deployment.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,8 @@
+<jbossesb-deployment>
+ <depends>jboss.messaging.destination:service=Topic,name=quickstart_jmstopic_topic</depends>
+ <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_s1</depends>
+ <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_s2</depends>
+ <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_response_gtw</depends>
+ <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_response_srv</depends>
+ <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_testnotify</depends>
+</jbossesb-deployment>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/deployment.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/client-console.png
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/client-console.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/esb-console.png
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/images/esb-console.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbm-queue-service.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbm-queue-service.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbm-queue-service.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+
+ <mbean code="org.jboss.jms.server.destination.TopicService"
+ name="jboss.messaging.destination:service=Topic,name=quickstart_jmstopic_topic"
+ xmbean-dd="xmdesc/Topic-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.esb.qa.junit.destination:service=Queue,name=quickstart_jmstopic_queue_s1"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.esb.qa.junit.destination:service=Queue,name=quickstart_jmstopic_queue_s2"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.esb.qa.junit.destination:service=Queue,name=quickstart_jmstopic_queue_response_gtw"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.esb.qa.junit.destination:service=Queue,name=quickstart_jmstopic_queue_response_srv"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.esb.qa.junit.destination:service=Queue,name=quickstart_jmstopic_queue_testnotify"
+ xmbean-dd="xmdesc/Queue-xmbean.xml">
+ <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+ <depends>jboss.messaging:service=PostOffice</depends>
+ </mbean>
+
+</server>
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbm-queue-service.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbmq-queue-service.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbmq-queue-service.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbmq-queue-service.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+
+ <mbean code="org.jboss.mq.server.jmx.Topic"
+ name="jboss.messaging.destination:service=Topic,name=quickstart_jmstopic_topic">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_s1">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_s2">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_response_gtw">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_response_srv">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_jmstopic_queue_testnotify">
+ <depends optional-attribute-name="DestinationManager">
+ jboss.mq:service=DestinationManager
+ </depends>
+ </mbean>
+
+</server>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jbmq-queue-service.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jboss-esb.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jboss-esb.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,80 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb
+ xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
+ parameterReloadSecs="5">
+
+ <!--
+ - -> MyService1 -> - |
+ | |
+ -> - "quickstart-topic" -| |- - - MyService3
+ | |
+ - -> MyService2 -> - |
+ -->
+
+
+ <providers>
+ <jms-provider name="JMS" connection-factory="ConnectionFactory"
+ jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+ jndi-URL="localhost">
+
+ <jms-bus busid="quickstart-topic">
+ <jms-message-filter dest-type="TOPIC" dest-name="topic/quickstart_jmstopic_topic"/>
+ </jms-bus>
+
+ <jms-bus busid="quickstart-queue-s1">
+ <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_jmstopic_queue_s1"/>
+ </jms-bus>
+ <jms-bus busid="quickstart-queue-s2">
+ <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_jmstopic_queue_s2"/>
+ </jms-bus>
+
+ <jms-bus busid="quickstart-queue-response-gtw">
+ <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_jmstopic_queue_response_gtw"/>
+ </jms-bus>
+ <jms-bus busid="quickstart-queue-response-srv">
+ <jms-message-filter dest-type="QUEUE" dest-name="queue/quickstart_jmstopic_queue_response_srv"/>
+ </jms-bus>
+ </jms-provider>
+ </providers>
+
+ <services>
+
+ <service category="MyServiceCategory" name="MyService1" description="Topic receiver 1">
+ <listeners>
+ <jms-listener name="JMS-Gateway" busidref="quickstart-topic" is-gateway="true"/>
+ <jms-listener name="JMS-ESBListener" busidref="quickstart-queue-s1"/>
+ </listeners>
+ <actions>
+ <action name="augmentor" class="org.jboss.soa.esb.samples.quickstart.jmstopic.MessageAugmentor">
+ <property name="addition" value="Service1-Received"/>
+ <property name="target" value="MyServiceCategory:MyService3"/>
+ </action>
+ </actions>
+ </service>
+
+ <service category="MyServiceCategory" name="MyService2" description="Topic receiver 2">
+ <listeners>
+ <jms-listener name="JMS-Gateway" busidref="quickstart-topic" is-gateway="true"/>
+ <jms-listener name="JMS-ESBListener" busidref="quickstart-queue-s2"/>
+ </listeners>
+ <actions>
+ <action name="augmentor" class="org.jboss.soa.esb.samples.quickstart.jmstopic.MessageAugmentor">
+ <property name="addition" value="Service2-Received"/>
+ <property name="target" value="MyServiceCategory:MyService3"/>
+ </action>
+ </actions>
+ </service>
+
+ <service category="MyServiceCategory" name="MyService3" description="Target Service">
+ <listeners>
+ <jms-listener name="JMS-Gateway" busidref="quickstart-queue-response-gtw" is-gateway="true"/>
+ <jms-listener name="JMS-ESBListener" busidref="quickstart-queue-response-srv"/>
+ </listeners>
+ <actions>
+ <action name="target" class="org.jboss.soa.esb.samples.quickstart.jmstopic.TargetServiceAction" />
+ </actions>
+ </service>
+
+ </services>
+
+</jbossesb>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/jboss-esb.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/log4j.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/log4j.xml (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/log4j.xml 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml,v 1.26.2.5 2005/09/15 09:31:02 dimitris Exp $ -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!-- ================================= -->
+ <!-- Preserve messages in a local file -->
+ <!-- ================================= -->
+
+ <!-- A size based file rolling appender -->
+ <appender name="FILE" class="org.jboss.logging.appender.RollingFileAppender">
+ <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
+ <param name="File" value="./listener.log"/>
+ <param name="Append" value="false"/>
+ <param name="MaxFileSize" value="500KB"/>
+ <param name="MaxBackupIndex" value="1"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d %-5p [%t][%c] %m%n"/>
+ </layout>
+ </appender>
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+ <!-- ================ -->
+
+ <category name="org.jboss">
+ <priority value="WARN"/>
+ </category>
+ <category name="org.jboss.soa.esb">
+ <priority value="ERROR"/>
+ </category>
+ <category name="org.jboss.internal.soa.esb">
+ <priority value="ERROR"/>
+ </category>
+ <category name="org.apache">
+ <priority value="ERROR"/>
+ </category>
+ <category name="quickstart">
+ <priority value="INFO"/>
+ </category>
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="FILE"/>
+ </root>
+
+</log4j:configuration>
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/log4j.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/MessageAugmentor.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/MessageAugmentor.java (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/MessageAugmentor.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.samples.quickstart.jmstopic;
+
+import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.Service;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.message.Message;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MessageAugmentor extends AbstractActionPipelineProcessor {
+
+ private String addition;
+ private Service targetService;
+
+ public MessageAugmentor(ConfigTree config) throws ConfigurationException {
+ addition = config.getRequiredAttribute("addition");
+ String target = config.getRequiredAttribute("target");
+ String[] targetTokens = target.split(":");
+
+ if(targetTokens.length != 2) {
+ throw new ConfigurationException("Action not configured properly - 'target' service property must be in format 'category:name'.");
+ }
+
+ targetService = new Service(targetTokens[0], targetTokens[1]);
+ }
+
+ public Message process(final Message message) throws ActionProcessingException {
+ message.getProperties().setProperty("addition", addition);
+
+ System.out.println("Received message on Topic. Sending '" + addition + "' to " + targetService);
+
+ try {
+ getInvoker().deliverAsync(message);
+ } catch (MessageDeliverException e) {
+ throw new ActionProcessingException("Failed to deliver message: " + e.getMessage());
+ }
+
+ return message;
+ }
+
+ private ServiceInvoker getInvoker() throws ActionProcessingException {
+ try {
+ return new ServiceInvoker(targetService);
+ } catch (MessageDeliverException e) {
+ throw new ActionProcessingException("Failed to create ServiceInvoker: " + e.getMessage());
+ }
+ }
+}
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/MessageAugmentor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/TargetServiceAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/TargetServiceAction.java (rev 0)
+++ labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/TargetServiceAction.java 2007-10-01 17:09:53 UTC (rev 15484)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.samples.quickstart.jmstopic;
+
+import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.apache.log4j.Logger;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class TargetServiceAction extends AbstractActionPipelineProcessor {
+
+ private static Logger logger = Logger.getLogger(TargetServiceAction.class);
+
+ public TargetServiceAction(ConfigTree config) {
+ }
+
+ public Message process(final Message message) throws ActionProcessingException {
+ String addition = (String) message.getProperties().getProperty("addition");
+
+ System.out.println("MyService3 Received message: '" + addition + "'");
+
+ return message;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/jms_topic/src/org/jboss/soa/esb/samples/quickstart/jmstopic/TargetServiceAction.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list