[jboss-svn-commits] JBL Code SVN: r7423 - in labs/jbossesb/trunk: IDE/JBossIDE product/core/listeners/src/org/jboss/soa/esb/actions product/core/listeners/src/org/jboss/soa/esb/listeners product/core/listeners/src/org/jboss/soa/esb/listeners/message qa/junit/src/org/jboss/soa/esb/actions qa/junit/src/org/jboss/soa/esb/listeners/message
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 7 09:37:39 EST 2006
Author: kurt.stam at jboss.com
Date: 2006-11-07 09:37:27 -0500 (Tue, 07 Nov 2006)
New Revision: 7423
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueReplyListener.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTestFragment.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/juddi-unittest.properties
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.xml
Removed:
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml
Modified:
labs/jbossesb/trunk/IDE/JBossIDE/.classpath
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
Log:
Working on ReplyListener qa test
Modified: labs/jbossesb/trunk/IDE/JBossIDE/.classpath
===================================================================
--- labs/jbossesb/trunk/IDE/JBossIDE/.classpath 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/IDE/JBossIDE/.classpath 2006-11-07 14:37:27 UTC (rev 7423)
@@ -8,6 +8,7 @@
<classpathentry kind="src" path="product/core/services/rules"/>
<classpathentry kind="src" path="product/core/services/tests/src"/>
<classpathentry kind="src" path="qa/junit/src"/>
+ <classpathentry kind="lib" path="product/core/rosetta/tests/resources/conf"/>
<classpathentry kind="lib" path="product/lib/ext/activation.jar"/>
<classpathentry kind="lib" path="product/lib/ext/commons-logging.jar"/>
<classpathentry kind="lib" path="product/lib/ext/emma_ant.jar"/>
@@ -16,7 +17,6 @@
<classpathentry kind="lib" path="product/lib/ext/log4j.jar"/>
<classpathentry kind="lib" path="product/lib/ext/mail.jar"/>
<classpathentry kind="lib" path="product/lib/ext/mockejb.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="product/lib/ext/jaxr-api-1.0.jar" sourcepath="/scout"/>
<classpathentry kind="lib" path="product/lib/ext/jbossts-common.jar" sourcepath="/jbossts"/>
<classpathentry kind="lib" path="product/lib/ext/xstream-1.1.3.jar"/>
@@ -26,7 +26,6 @@
<classpathentry kind="lib" path="product/lib/ext/ejb3_embedded/hibernate-all.jar"/>
<classpathentry kind="lib" path="product/lib/ext/ejb3_embedded/jboss-ejb3-all.jar"/>
<classpathentry kind="lib" path="product/lib/ext/ejb3_embedded/thirdparty-all.jar"/>
- <classpathentry kind="lib" path="product/core/rosetta/tests/resources/conf"/>
<classpathentry kind="lib" path="product/lib/ext/juddi-embedded.jar" sourcepath="/juddi"/>
<classpathentry kind="lib" path="product/lib/ext/scout-0.7rc2-embedded.jar" sourcepath="/scout"/>
<classpathentry kind="lib" path="product/lib/ext/hsqldb.jar"/>
@@ -36,6 +35,7 @@
<classpathentry kind="lib" path="product/lib/ext/commons-pool-1.3.jar"/>
<classpathentry kind="lib" path="product/lib/ext/commons-dbcp-1.2.1.jar"/>
<classpathentry kind="lib" path="product/lib/ext/c3p0-0.9.1-pre9.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="DROOLS/JBoss Rules"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -22,22 +22,10 @@
package org.jboss.soa.esb.actions;
-import java.io.IOException;
import java.io.Serializable;
-import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Iterator;
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.ObjectMessage;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSession;
-import javax.naming.Context;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.jboss.soa.esb.addressing.EPR;
@@ -45,17 +33,15 @@
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
-import org.jboss.soa.esb.helpers.AppServerContext;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.listeners.message.CbrJmsQueueListener;
+import org.jboss.soa.esb.listeners.message.JmsQueueReplyListener;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.notification.NotificationList;
import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.services.registry.RegistryFactory;
import org.jboss.soa.esb.services.routing.MessageRouter;
-import org.jboss.soa.esb.util.Util;
-import org.xml.sax.SAXException;
/**
@@ -64,74 +50,104 @@
* @author kstam at redhat.com
*
*/
-public class CbrProxyAction
+public class CbrProxyAction implements ActionProcessor
{
-
-
private static Logger _logger = Logger.getLogger(CbrProxyAction.class);
-
- protected ConfigTree _config;
+ /** Collection of EPRS for the Content Based Router */
+ protected Collection<EPR> _eprs;
+ /** Configuration Tree */
+ protected ConfigTree _config;
- public CbrProxyAction(ConfigTree config) throws Exception
+ /**
+ * Constructor of the Content Based Router Proxy. This constructor obtains
+ * the EPRs of the Content Based Router.
+ *
+ * @param config
+ * @throws Exception
+ */
+ public CbrProxyAction(ConfigTree config) throws RegistryException
{
- _config = config;
Registry registry = RegistryFactory.getRegistry();
- String serviceCategoryName = _config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
- String serviceName = _config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ String serviceCategoryName = config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ String serviceName = config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
_eprs = registry.findEPRs(serviceCategoryName, serviceName);
- _lSleepForRetry = 500;
- }
+ }
+ /**
+ * No-Op method. This is here for notification purposes.
+ *
+ * @param message
+ * @return the same message as passed in.
+ */
public Message noOperation(Message message) { return message; }
+ /** By default this process method forwards this request to routeAndDeliver.
+ * @see routeAndDeliver(Message message).
+ *
+ * @param message - the message to be routed.
+ * @return - the same message as was passed in.
+ */
public Message process(Message message)
{
- _logger.info("Process was called.");
-
- // get a real UID into replyId
- String replyId = Long.toString(System.currentTimeMillis());
- message.getBody().add(CbrJmsQueueListener.CORRELATION_ID_TAG, replyId);
-
+ _logger.info("Process was called, using the default routeAndDeliver.");
+ return routeAndDeliver(message);
+ }
+ /**
+ * Just route.
+ *
+ * @param message
+ * @return
+ */
+ public Message route(Message message)
+ {
+ Message replyMessage=null;
+ JmsQueueReplyListener jmsQueueReplyListener = new JmsQueueReplyListener();
try {
+
for (Iterator<EPR> eprIterator=_eprs.iterator();eprIterator.hasNext();){
//Just use the first EPR in the list.
EPR epr = eprIterator.next();
Courier courier = CourierFactory.getCourier(epr);
//If not successful try the next EPR
- if (courier.deliver(message))
- {
- return getResponse(replyId,epr);
+ if (JMSEpr.class.equals(epr.getClass())) {
+ if (courier.deliver(message)) {
+ String uniqueReplySelector = jmsQueueReplyListener.setCorrelationId(message);
+ replyMessage = jmsQueueReplyListener.listen((JMSEpr)epr, uniqueReplySelector);
+ break;
+ } else {
+ _logger.warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
+ }
+ } else {
+ _logger.warn("Found a non-JMS EPR, but since we want a reply we need a JMS-EPR");
}
}
} catch (CourierException ce) {
_logger.error("Could not send to the CBR. " + ce.getLocalizedMessage(), ce);
}
- return message;
- } // ________________________________
-
- private Message getResponse(String replyId, EPR epr)
- {
- // For now, this proxy only works for a JMS epr
- if (! (epr instanceof JMSEpr))
- return null;
-
- //Create a string that has the format of a message selector
- StringBuilder sb = new StringBuilder()
- .append(CbrJmsQueueListener.CORRELATION_ID_TAG).append("='")
- .append(replyId).append("'")
- ;
- return receiveResponse((JMSEpr)epr, sb.toString(), 5000);
+ return replyMessage;
}
- public Message addDestinationListToMessage(Message message) {
- return null;
- }
-
public Message deliverToDestinations(Message message) {
+
return null;
}
- public Message route (Message message) {
- return null;
+ public Message routeAndDeliver(Message message)
+ {
+ try {
+ for (Iterator<EPR> eprIterator=_eprs.iterator();eprIterator.hasNext();){
+ //Just use the first EPR in the list.
+ EPR epr = eprIterator.next();
+ Courier courier = CourierFactory.getCourier(epr);
+ //If not successful try the next EPR
+ if (courier.deliver(message))
+ {
+ break;
+ }
+ }
+ } catch (CourierException ce) {
+ _logger.error("Could not send to the CBR. " + ce.getLocalizedMessage(), ce);
+ }
+ return message;
}
public void exceptionCallback(Message message, Throwable t)
@@ -153,113 +169,13 @@
_logger.log(Priority.INFO, destinationServices);
}
-
- private MessageConsumer getConsumer(JMSEpr epr, String selector)
- {
- _Qconn = null;
- _Qsess = null;
- _Queue = null;
-
- Exception thrown = null;
- try
- {
- Context context = AppServerContext.getServerContext(epr.getJndiType(),epr.getJndiURL());
- Object tmp = context.lookup(epr.getConnectionFactory());
- QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
-
- _Qconn = qcf.createQueueConnection();
- _Queue = (Queue) context.lookup(epr.getDestinationName());
- _Qsess = _Qconn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
- _Qconn.start();
- return _Qsess.createReceiver(_Queue, selector);
- }
- catch (URISyntaxException e) { thrown = e; }
- catch (javax.naming.NamingException e) { thrown = e; }
- catch (JMSException e) { thrown = e; }
- _logger.error("Unable to create response consumer",thrown);
- return null;
-
- } // ________________________________
-
- protected Message receiveResponse(JMSEpr epr, String selector, long millis)
- {
- MessageConsumer consumer = null;
- javax.jms.Message jmsMessage = null;
- try
- {
- consumer = getConsumer(epr, selector);
- jmsMessage = consumer.receive(millis);
- }
- catch (JMSException oJ)
- {
- for (int i1 = 0; i1 < 3; i1++)
- // try to reconnect to the queue
- try
- {
- consumer = getConsumer(epr, selector);
- jmsMessage = consumer.receive(millis);
- }
- catch (Exception e)
- {
- _logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
- _logger.error("Reconnecting to Queue", e);
- try { Thread.sleep(_lSleepForRetry); }
- catch (InterruptedException e1)
- { // Just return after logging
- _logger.error("Unexpected thread interupt exception.", e);
- break;
- }
- }
- }
- finally {cleanupJms(); }
-
- 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();
- return Util.deserialize(obj);
- }
- 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;
- }
-
- protected void cleanupJms()
- {
- if (null != _Qsess)
- try { _Qsess.close(); }
- catch (Exception e1) {/* Tried my best - Just continue */ }
- if (null != _Qconn)
- try { _Qconn.close(); }
- catch (Exception e2) {/* Tried my best - Just continue */ }
- }
-
- protected Collection<EPR> _eprs;
- protected long _lSleepForRetry;
- protected QueueConnection _Qconn = null;
- protected QueueSession _Qsess = null;
- protected Queue _Queue = null;
-
-} // ____________________________________________________________________________
+ public Serializable getErrorNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public Serializable getOkNotification(Message message) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -15,6 +15,7 @@
public static final String ACTION_ELEMENT_TAG = "action";
public static final String ACTION_CLASS_TAG = "class";
public static final String PROCESS_METHOD_TAG = "process";
+ public static final String ACTION_PROPERTY_TAG = "property";
public static final String NORMAL_COMPLETION_METHOD_TAG = "okMethod";
public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
public static final String HTTP_ROUTER_ROUTE_URL = "routeUrl";
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -19,7 +19,7 @@
* @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
* @since Version 4.0
*/
-class ActionProcessingPipeline implements Runnable
+public class ActionProcessingPipeline implements Runnable
{
/**
@@ -72,7 +72,7 @@
_currentAction = oCurr.getAttribute(attrName);
_currentClass = Class.forName(_currentAction);
Constructor oConst = _currentClass.getConstructor(new Class[] {ConfigTree.class});
- _currentProcessor = oConst.newInstance(_config);
+ _currentProcessor = oConst.newInstance(oCurr);
attrName = ListenerTagNames.PROCESS_METHOD_TAG;
String[] saMethodList = obtainAttribute(oCurr,attrName,attrName).split(",");
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -55,8 +55,6 @@
public class CbrJmsQueueListener extends JmsQueueListener
{
- public static final String CORRELATION_ID_TAG = "jmsCorrelationId";
-
private static transient Logger _logger = Logger.getLogger(CbrJmsQueueListener.class);
public CbrJmsQueueListener(EsbListenerController controller, ConfigTree config) throws ConfigurationException {
@@ -83,7 +81,6 @@
throw new ListenerInitializationException("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found.");
}
}
-
_controller.register(_config,_epr);
while (_controller.continueLooping()) {
long lwait = _controller.millisToWait();
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueReplyListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueReplyListener.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueReplyListener.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -0,0 +1,187 @@
+/*
+ * 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.message;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.URISyntaxException;
+
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSession;
+import javax.naming.Context;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.juddi.uuidgen.UUIDGenFactory;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.helpers.AppServerContext;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.Util;
+import org.xml.sax.SAXException;
+
+
+/**
+ * JMS based Reply Listener. This is a listenere which gets set up
+ *
+ * @author esteban
+ * @author kstam at redhat.com
+ *
+ */
+public class JmsQueueReplyListener
+{
+ public static final String CORRELATION_ID_TAG = "jmsCorrelationId";
+
+ private static Logger _logger = Logger.getLogger(JmsQueueReplyListener.class);
+ private static long SLEEP_FOR_RETRY = 500;
+ private static long LISTEN_TIME_OUT = 5000;
+ private QueueConnection _Qconn = null;
+ private QueueSession _Qsess = null;
+ private Queue _Queue = null;
+ /**
+ * We will be listening the same queue, but with a 'temporary' message selector
+ * based of a UUID.
+ *
+ * @param message to which we ill add the CORRELATION_ID_TAG.
+ * @return the generated unique reply selector.
+ */
+ public String setCorrelationId(Message message)
+ {
+ String uuId = UUIDGenFactory.getUUIDGen().uuidgen();
+ message.getBody().add(CORRELATION_ID_TAG, uuId);
+ String uniqueReplySelector = new StringBuilder()
+ .append(CORRELATION_ID_TAG).append("='")
+ .append(uuId).append("'").toString();
+ return uniqueReplySelector;
+ }
+ /**
+ *
+ * @param epr
+ * @param selector
+ * @return
+ */
+ private MessageConsumer getConsumer(JMSEpr epr, String selector)
+ {
+ _Qconn = null;
+ _Qsess = null;
+ _Queue = null;
+
+ Exception thrown = null;
+ try
+ {
+ Context context = AppServerContext.getServerContext(epr.getJndiType(),epr.getJndiURL());
+ Object tmp = context.lookup(epr.getConnectionFactory());
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+
+ _Qconn = qcf.createQueueConnection();
+ _Queue = (Queue) context.lookup(epr.getDestinationName());
+ _Qsess = _Qconn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
+ _Qconn.start();
+ return _Qsess.createReceiver(_Queue, selector);
+ }
+ catch (URISyntaxException e) { thrown = e; }
+ catch (javax.naming.NamingException e) { thrown = e; }
+ catch (JMSException e) { thrown = e; }
+ _logger.error("Unable to create response consumer",thrown);
+ return null;
+ }
+
+ public Message listen(JMSEpr epr, String uniqueReplySelector)
+ {
+ MessageConsumer consumer = null;
+ javax.jms.Message jmsMessage = null;
+ try
+ {
+ consumer = getConsumer(epr, uniqueReplySelector);
+ jmsMessage = consumer.receive(LISTEN_TIME_OUT); //TODO Kurt why this timeout?
+ }
+ catch (JMSException oJ)
+ {
+ for (int i1 = 0; i1 < 3; i1++)
+ // try to reconnect to the queue
+ try
+ {
+ consumer = getConsumer(epr, uniqueReplySelector);
+ jmsMessage = consumer.receive(LISTEN_TIME_OUT);
+ }
+ catch (Exception e)
+ {
+ _logger.error("JMS error on receive. Attempting JMS Destination reconnect.", oJ);
+ _logger.error("Reconnecting to Queue", e);
+ try { Thread.sleep(SLEEP_FOR_RETRY); }
+ catch (InterruptedException e1)
+ { // Just return after logging
+ _logger.error("Unexpected thread interupt exception.", e);
+ break;
+ }
+ }
+ }
+ finally {cleanupJms(); }
+
+ 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();
+ return Util.deserialize(obj);
+ }
+ 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;
+ }
+
+
+ private void cleanupJms()
+ {
+ if (null != _Qsess)
+ try { _Qsess.close(); }
+ catch (Exception e1) {/* Tried my best - Just continue */ }
+ if (null != _Qconn)
+ try { _Qconn.close(); }
+ catch (Exception e2) {/* Tried my best - Just continue */ }
+ }
+}
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -0,0 +1,182 @@
+/*
+ * 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.actions;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.EsbListenerController;
+import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.util.FileUtil;
+import org.jboss.soa.esb.util.TestUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test CbrProxyAction class. First this test brings up a (hsqldb) database, and the registry. It them
+ * brings up the Content Based Router - defined in the CbrProxyActionUnitTest.xml. It then goes on to
+ * read the CbrProxyActionUnitTestFragment.xml, on which we perform the tests.
+ *
+ * @author kurt.stam at redhat.com
+ */
+public class CbrProxyActionUnitTest
+{
+ private static Logger logger = Logger.getLogger(CbrProxyActionUnitTest.class);
+ private static EsbListenerController _proc = null;
+ private static String mDbDriver;
+ private static String mDbUrl;
+ private static String mDbUsername;
+ private static String mDbPassword;
+
+ @Test
+ public void routeAndDeliver()
+ {
+ try {
+ Message message = MessageFactory.getInstance().getMessage();
+ message.getBody().setContents("Body".getBytes());
+ @SuppressWarnings("unused")
+ ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment.xml"));
+
+ ActionProcessingPipeline chain = null;
+
+ try {
+ chain = new ActionProcessingPipeline(message,config);
+ }catch (IllegalArgumentException e){
+ e.printStackTrace();
+ } catch (ConfigurationException e){
+ e.printStackTrace();
+ }
+ new Thread(chain).start();
+
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ assertTrue(false);
+ e.printStackTrace();
+ }
+ }
+
+ @BeforeClass
+ public static void runBeforeAllTests()
+ {
+ try {
+ DOMConfigurator.configure(TestUtil.getPrefix("product") + "etc/test/resources/log4j.xml");
+ TestUtil.setESBPropertiesFileToUse("product");
+ //Set the juddi properties file in System so juddi will pick it up later and use the test values.
+ String juddiPropertiesFile = "/org/jboss/soa/esb/actions/juddi-unittest.properties";
+ System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+ //Read this properties file to get the db connection string
+ Properties props = new Properties();
+ InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+ props.load(inStream);
+ mDbDriver = props.getProperty("juddi.jdbcDriver");
+ mDbUrl = props.getProperty("juddi.jdbcUrl");
+ mDbUsername = props.getProperty("juddi.jdbcUsername");
+ mDbPassword = props.getProperty("juddi.jdbcPassword");
+
+ String database="not tested yet";
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ database = "hsqldb";
+ //Bring up hsql on default port 9001
+ HsqldbUtil.startHsqldb(TestUtil.getPrefix("product") + "build/hsqltestdb", "juddi");
+ } else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+ database = "mysql";
+ } //add and test your own database..
+
+ //Get the registry-schema create scripts
+ String sqlDir = TestUtil.getPrefix("product") + "install/jUDDI-registry/sql/" + database + "/";
+ //Drop what is there now, if exists. We want to start fresh.
+ String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+ String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+ String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+
+ try {
+ Class.forName(mDbDriver);
+ } catch (Exception e) {
+ System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ e.printStackTrace();
+ return;
+ }
+ java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+ Statement stmnt = con.createStatement();
+ System.out.println("Dropping the schema if exist");
+ stmnt.execute(sqlDropCmd);
+ System.out.println("Creating the juddi-schema");
+ stmnt.execute(sqlCreateCmd);
+ System.out.println("Adding the jbossesb publisher");
+ stmnt.execute(sqlInsertPubCmd);
+
+ //Now we can bring up the ContentBasedRouter
+ logger.info("Testing to see if we can instantiate one");
+ String deploymentConfigFile = TestUtil.getPrefix("qa")
+ + "junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml";
+ _proc = new EsbListenerController(deploymentConfigFile);
+ new Thread(_proc).start();
+ // give the listener time to register
+ Thread.sleep(5000);
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ System.out.println("We should stop testing, since we don't have a db.");
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Shutdown the database
+ * @throws Exception
+ */
+ @AfterClass
+ public static void runAfterAllTests() throws Exception
+ {
+ //Shutdown the CBR Service
+ //Increase Sleep for debugging
+ Thread.sleep(200);
+ _proc.requestEnd();
+ //Give the controller time to finish
+ Thread.sleep(2000);
+ EsbListenerController.State oS = _proc.getState();
+ System.out.println("Exit state = "+oS.toString());
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(CbrProxyActionUnitTest.class);
+ }
+}
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml 2006-11-07 14:37:27 UTC (rev 7423)
@@ -0,0 +1,17 @@
+<ContentBasedRouterTest parameterReloadSecs="180">
+ <ContentBasedRouter
+ service-category="MessageRouting"
+ service-name="ContentBasedRoutingService"
+ service-description="This CBR routs messages to different service destination based whether the messageType is XML or Serializable"
+ listenerClass="org.jboss.soa.esb.listeners.message.CbrJmsQueueListener"
+ connection-factory="ConnectionFactory"
+ destination-type="queue"
+ destination-name="queue/A"
+ jndi-type="jboss"
+ jndi-URL="localhost"
+ message-selector="service='ContentBasedRouting-SerializableOrXml'"
+ >
+ <cbr ruleSet="JBossESBRules.drl" />
+ </ContentBasedRouter>
+
+</ContentBasedRouterTest>
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTestFragment.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTestFragment.xml 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTestFragment.xml 2006-11-07 14:37:27 UTC (rev 7423)
@@ -0,0 +1,9 @@
+<CbrProxyActionTest>
+<action name="TestDefaultRouteAction"
+ processor="process"
+ class="org.jboss.soa.esb.actions.CbrProxyAction"
+ service-category="MessageRouting"
+ service-name="ContentBasedRoutingService" />
+</CbrProxyActionTest>
+
+
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/juddi-unittest.properties
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/juddi-unittest.properties 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/juddi-unittest.properties 2006-11-07 14:37:27 UTC (rev 7423)
@@ -0,0 +1,69 @@
+# jUDDI Registry Properties (used by RegistryServer)
+# see http://www.juddi.org for more information
+
+# The UDDI Operator Name
+juddi.operatorName = jUDDI.org
+
+# The i18n locale default codes
+juddi.i18n.languageCode = en
+juddi.i18n.countryCode = US
+
+# The UDDI DiscoveryURL Prefix
+juddi.discoveryURL = http://localhost:8080/juddi/uddiget.jsp?
+
+# The UDDI Operator Contact Email Address
+juddi.operatorEmailAddress = admin at juddi.org
+
+# The maximum name size and maximum number
+# of name elements allows in several of the
+# FindXxxx and SaveXxxx UDDI functions.
+juddi.maxNameLength=255
+juddi.maxNameElementsAllowed=5
+
+# The maximum number of UDDI artifacts allowed
+# per publisher. A value of '-1' indicates any
+# number of artifacts is valid (These values can be
+# overridden at the individual publisher level).
+juddi.maxBusinessesPerPublisher=25
+juddi.maxServicesPerBusiness=20
+juddi.maxBindingsPerService=10
+juddi.maxTModelsPerPublisher=100
+
+# jUDDI Authentication module to use
+juddi.auth = org.apache.juddi.auth.DefaultAuthenticator
+
+# jUDDI DataStore module currently to use
+juddi.dataStore = org.apache.juddi.datastore.jdbc.JDBCDataStore
+
+# use a dataSource (if set to false a direct
+# jdbc connection will be used.
+juddi.isUseDataSource=false
+juddi.jdbcDriver=org.hsqldb.jdbcDriver
+juddi.jdbcUrl=jdbc:hsqldb:hsql://localhost/juddi
+juddi.jdbcUsername=sa
+juddi.jdbcPassword=
+# jUDDI DataSource to use
+juddi.dataSource=java:comp/env/jdbc/juddiDB
+
+# jUDDI UUIDGen implementation to use
+juddi.uuidgen = org.apache.juddi.uuidgen.DefaultUUIDGen
+
+# jUDDI Cryptor implementation to use
+juddi.cryptor = org.apache.juddi.cryptor.DefaultCryptor
+
+# jUDDI Validator to use
+juddi.validator=org.apache.juddi.validator.DefaultValidator
+
+# jUDDI Proxy Properties (used by RegistryProxy)
+juddi.proxy.adminURL = http://localhost:8080/juddi/admin
+juddi.proxy.inquiryURL = http://localhost:8080/juddi/inquiry
+juddi.proxy.publishURL = http://localhost:8080/juddi/publish
+juddi.proxy.transportClass = org.apache.juddi.proxy.AxisTransport
+juddi.proxy.securityProvider = com.sun.net.ssl.internal.ssl.Provider
+juddi.proxy.protocolHandler = com.sun.net.ssl.internal.www.protocol
+
+# JNDI settings (used by RMITransport)
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming
+
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.java 2006-11-07 14:37:27 UTC (rev 7423)
@@ -168,7 +168,7 @@
//Now we can bring up the ContentBasedRouter
logger.info("Testing to see if we can instantiate one");
String deploymentConfigFile = TestUtil.getPrefix("qa")
- + "junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml";
+ + "junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.xml";
_proc = new EsbListenerController(deploymentConfigFile);
new Thread(_proc).start();
// give the listener time to register
Copied: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListenerTest.xml (from rev 7417, labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml)
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml 2006-11-07 13:43:31 UTC (rev 7422)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml 2006-11-07 14:37:27 UTC (rev 7423)
@@ -1,17 +0,0 @@
-<ContentBasedRouterTest parameterReloadSecs="180">
- <ContentBasedRouter
- service-category="MessageRouting"
- service-name="ContentBasedRoutingService"
- service-description="This CBR routs messages to different service destination based whether the messageType is XML or Serializable"
- listenerClass="org.jboss.soa.esb.listeners.message.CbrJmsQueueListener"
- connection-factory="ConnectionFactory"
- destination-type="queue"
- destination-name="queue/A"
- jndi-type="jboss"
- jndi-URL="localhost"
- message-selector="service='ContentBasedRouting-SerializableOrXml'"
- >
- <cbr ruleSet="JBossESBRules.drl" />
- </ContentBasedRouter>
-
-</ContentBasedRouterTest>
More information about the jboss-svn-commits
mailing list