[jboss-svn-commits] JBL Code SVN: r7308 - in labs/jbossesb/trunk: IDE/JBossIDE product/core/listeners/src/org/jboss product/core/listeners/src/org/jboss/soa/esb product/core/listeners/src/org/jboss/soa/esb/listeners product/core/listeners/src/org/jboss/soa/esb/listeners/message product/core/rosetta/src/org/jboss/internal/soa/esb product/core/rosetta/src/org/jboss/internal/soa/esb/couriers product/core/rosetta/src/org/jboss/soa/esb product/core/rosetta/src/org/jboss/soa/esb/common product/core/rosetta/src/org/jboss/soa/esb/couriers product/core/services product/core/services/rules product/core/services/src/org/jboss/soa/esb/services product/core/services/src/org/jboss/soa/esb/services/routing product/core/services/src/org/jboss/soa/esb/services/routing/cbr product/core/services/tests product/core/services/tests/src/org/jboss/soa/esb/services product/core/services/tests/src/org/jboss/soa/esb/services/routing product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr product/! install/conf product/lib/ext qa/junit/src/org/jboss/soa/esb/util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 1 20:45:08 EST 2006
Author: kurt.stam at jboss.com
Date: 2006-11-01 20:44:59 -0500 (Wed, 01 Nov 2006)
New Revision: 7308
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/Courier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierException.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
labs/jbossesb/trunk/product/core/services/rules/
labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouterException.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouterFactory.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouter.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
labs/jbossesb/trunk/product/lib/ext/commons-jci-core-1.0-406301.jar
labs/jbossesb/trunk/product/lib/ext/commons-jci-eclipse-3.2.0.666.jar
Removed:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/Courier.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierException.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
Modified:
labs/jbossesb/trunk/IDE/JBossIDE/.classpath
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
labs/jbossesb/trunk/product/core/services/build.xml
labs/jbossesb/trunk/product/core/services/tests/build.xml
labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/ListenerUtils.java
Log:
Adding Framework for Content Based Routing. Not hooked up to a config yet.
Modified: labs/jbossesb/trunk/IDE/JBossIDE/.classpath
===================================================================
--- labs/jbossesb/trunk/IDE/JBossIDE/.classpath 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/IDE/JBossIDE/.classpath 2006-11-02 01:44:59 UTC (rev 7308)
@@ -1,25 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="src" path="product/core/rosetta/tests/src"/>
<classpathentry kind="src" path="product/core/rosetta/src"/>
- <classpathentry kind="src" path="product/core/rosetta/tests/src"/>
<classpathentry kind="src" path="product/core/listeners/src"/>
<classpathentry kind="src" path="product/core/listeners/tests/src"/>
<classpathentry kind="src" path="product/core/services/src"/>
+ <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/lib/ext/activation.jar"/>
- <classpathentry kind="lib" path="product/lib/ext/commons-collections-2.0.jar"/>
<classpathentry kind="lib" path="product/lib/ext/commons-logging.jar"/>
<classpathentry kind="lib" path="product/lib/ext/emma_ant.jar"/>
<classpathentry kind="lib" path="product/lib/ext/emma.jar"/>
<classpathentry kind="lib" path="product/lib/ext/jboss-jmx.jar"/>
- <classpathentry kind="lib" path="product/lib/ext/junit.jar"/>
<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"/>
+ <classpathentry kind="lib" path="product/lib/ext/milyn-commons-0.7.jar"/>
+ <classpathentry kind="lib" path="product/lib/ext/milyn-smooks-core-0.8-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="product/lib/ext/edtftpj.jar"/>
<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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<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"/>
+ <classpathentry kind="lib" path="product/lib/ext/xbean-1.0.4.jar"/>
+ <classpathentry kind="lib" path="product/lib/ext/junit-4.1.jar"/>
+ <classpathentry kind="lib" path="product/lib/ext/commons-collections-3.2.jar"/>
+ <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="DROOLS/JBoss Rules"/>
<classpathentry kind="output" path="bin"/>
</classpath>
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-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -2,12 +2,17 @@
public class ListenerTagNames
{
- public static final String SERVICE_NAME_TAG = "service-name";
- public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
+ public static final String SERVICE_NAME_TAG = "service-name";
+ public static final String TARGET_SERVICE_NAME_TAG = "target-service-name";
- 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_ELEMENT_TAG = "action";
+ public static final String ACTION_CLASS_TAG = "class";
+ public static final String PROCESS_METHOD_TAG = "process";
public static final String NORMAL_COMPLETION_METHOD_TAG = "okMethod";
- public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
+ public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
+
+ /** Content Based Routing */
+ public static final String CBR = "cbr";
+ /** RuleSet reference (Filename) */
+ public static final String RULE_SET = "ruleSet";
}
Added: 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-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrJmsQueueListener.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,87 @@
+/*
+ * 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 org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter;
+import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouterFactory;
+
+/**
+ * Esb Message aware Content Based Router JMS queue listener.
+ * <p/> Expects an Object message whose getObject() method returns an org.jboss.soa.esb.message.Message
+ * <br/>Clones the 'static' ConfigTree with which this listener was created, and stores the cloned tree
+ * inside the Message (to enable all actions in the chain to use the configuration)
+ * <br/>Instantiates and runs a new ActionProcessingPipeline on the received esb Message (augmented with
+ * ConfigTree) that will in turn instantiate and run all action classes in the chain
+ *
+ * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
+ * @since Version 4.0
+ */
+
+public class CbrJmsQueueListener extends JmsQueueListener
+{
+ private static transient Logger _logger = Logger.getLogger(CbrJmsQueueListener.class);
+
+ public CbrJmsQueueListener(EsbListenerController controller, ConfigTree config) throws ConfigurationException {
+ super(controller, config);
+ }
+
+ /**
+ * Loops until controlling process determines
+ * <br/>Waits for JMS Object messages containing ESB messages
+ * <br/>When one is received, instantiates an action processing pipeline to process it
+ * <br/>Pipeline is started in new Thread
+ */
+ public void run()
+ {
+ _controller.register(_eprName,_epr);
+ while (_controller.continueLooping()) {
+ long lwait = _controller.millisToWait();
+ Message message = (lwait > 0 ) ? receiveEsbMessage(100) : null;
+ if (null!=message) {
+ try {
+ _logger.log(Priority.INFO, "Invoking the Content Based Router");
+ String ruleSet=null;
+ ContentBasedRouter cbr =ContentBasedRouterFactory.getRouter();
+ if (_config.getFirstChild(ListenerTagNames.CBR)!=null) {
+ ruleSet=_config.getFirstChild(ListenerTagNames.CBR).getAttribute(ListenerTagNames.RULE_SET);
+ cbr.route(ruleSet, message);
+ } else {
+ _logger.log(Priority.ERROR, "Configuration exception, could not find cbr element " +
+ " in the Content Based Routing configuration");
+ }
+ } catch (MessageRouterException mre) {
+ _logger.log(Priority.ERROR, mre.getLocalizedMessage(), mre);
+ }
+ }
+ }
+ _controller.unRegister(_eprName);
+ cleanup();
+ }
+}
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers (from rev 7283, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/couriers)
Deleted: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2006-11-01 19:03:09 UTC (rev 7283)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -1,189 +0,0 @@
-/*
- * 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.internal.soa.esb.couriers;
-
-import java.util.List;
-
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
-import javax.jms.QueueSession;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.TopicConnectionFactory;
-import javax.jms.TopicPublisher;
-import javax.jms.TopicSession;
-import javax.naming.Context;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.addressing.eprs.JMSEpr;
-import org.jboss.soa.esb.couriers.Courier;
-import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.helpers.AppServerContext;
-import org.jboss.soa.esb.helpers.KeyValuePair;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.util.Util;
-
-public class JmsCourier implements Courier
-{
- /**
- * disable default constructor
- */
- private JmsCourier() { }
- /**
- * package protected constructor - Objects of Courier should only be instantiated by the Factory
- * @param epr
- */
- public JmsCourier(JMSEpr epr) throws CourierException
- {
- _epr = epr;
- _sleepForRetries = 3000;
-
- try
- {
- _messageProperties = Util.propertiesFromSelector(_epr.getMessageSelector());
- createMessageProducer();
- }
- catch (Exception e) { throw new CourierException(e); }
-
- } //________________________________
-
- /**
- * package the ESB message in a javax.jms.ObjectMessage, and send it
- * @param message Message - the message to deliver
- * @return boolean - the result of the delivery
- * @throws CourierException - if problems were encountered
- */
- public boolean deliver(Message message) throws CourierException
- {
- if (null==message)
- return false;
- 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());
- sendMessage(msg);
- return true;
- }
- catch (JMSException e) { jmsRetry(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
- */
- protected void sendMessage(javax.jms.Message jmsMessage) throws JMSException
- {
- if (_messageProducer instanceof TopicPublisher)
- ((TopicPublisher)_messageProducer).publish(jmsMessage);
- else
- _messageProducer.send(jmsMessage);
- } //________________________________
-
- private void jmsRetry(Exception exc)
- {
- _logger.error("JMS error. Attempting JMS reconnect.", exc);
- _jmsConnection = null;
- _jmsSession = null;
- _messageProducer= null;
-
- for (int i1 = 0; i1 < 5; i1++)
- {
- // try to reconnect to the queue
- try { createMessageProducer(); }
- catch (Exception e)
- {
- _logger.error("Reconnecting to JMS", e);
- try { Thread.sleep(_sleepForRetries); }
- catch (InterruptedException e1)
- { // Just return after logging
- _logger.error("Unexpected thread interupt exception.", e);
- break;
- }
- }
- }
- }
-
- protected void createMessageProducer() throws Exception
- {
-
- String sJndiType = _epr.getJndiType();
- if (Util.isNullString(sJndiType))
- sJndiType = "jboss";
- String sJndiURL = _epr.getJndiURL();
- if (Util.isNullString(sJndiURL))
- sJndiURL = "localhost";
- Context oJndiCtx = AppServerContext.getServerContext(sJndiType,sJndiURL);
-
- String sFactoryClass = _epr.getConnectionFactory();
- if (Util.isNullString(sFactoryClass))
- sFactoryClass = "ConnectionFactory";
-
- Object tmp = oJndiCtx.lookup(sFactoryClass);
-
- String sType = _epr.getDestinationType();
- if (JMSEpr.QUEUE_TYPE.equals(sType))
- {
- javax.jms.Queue queue = (javax.jms.Queue) oJndiCtx.lookup(_epr.getDestinationName());
- QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
- QueueConnection qConn = qcf.createQueueConnection();
- QueueSession qSess = qConn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
- _jmsConnection = qConn;
- _jmsSession = qSess;
- _messageProducer = qSess.createProducer(queue);
- }
- else if(JMSEpr.TOPIC_TYPE.equals(sType))
- {
- Topic topic = (Topic) oJndiCtx.lookup(_epr.getDestinationName());
- TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
- TopicConnection tConn = tcf.createTopicConnection();
- TopicSession tSess = tConn.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
- _jmsConnection = tConn;
- _jmsSession = tSess;
- _messageProducer = tSess.createPublisher(topic);
- }
- else
- throw new CourierException("Unknown destination type");
-
- } //________________________________
-
- protected JMSEpr _epr;
- protected Logger _logger = Logger.getLogger(JmsCourier.class);
- protected String _messageSelector;
- protected Connection _jmsConnection;
- protected Session _jmsSession;
- protected MessageProducer _messageProducer;
- protected long _sleepForRetries = 3000; // milliseconds
- protected List<KeyValuePair> _messageProperties;
-}
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java (from rev 7306, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java)
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -59,8 +59,7 @@
new KeyValuePair(Environment.MSG_STORE_DB_POOL_INITIAL_SIZE,getStorePoolInitialSize()),
new KeyValuePair(Environment.MSG_STORE_DB_POOL_TEST_TABLE, getStorePoolTestTable()),
new KeyValuePair(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS,getStorePoolTimeoutMillis()),
-
-
+ new KeyValuePair(Environment.ROUTER_CBR_CLASS, getContentBasedRouterImplementationClass())
};
public static String dump()
@@ -270,4 +269,13 @@
String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE).getProperty(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS);
return property;
}
+
+ public static String getContentBasedRouterImplementationClass()
+ {
+ String property = ModulePropertyManager.getPropertyManager(ModulePropertyManager.ROUTER_MODULE).getProperty(Environment.ROUTER_CBR_CLASS);
+ return property;
+ }
+
+
+
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Environment.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -70,15 +70,18 @@
*/
public static final String REGISTRY_PASSWORD = "org.jboss.soa.esb.registry.password";
/**
- * The Registry Scout Transport Class defines which communication protocol Scout should use to communicate
+ * The Registry Scout Transport Class property defines which communication protocol Scout should use to communicate
* with the UDDI registry. Note that this parameter is Scout specific.
*/
public static final String REGISTRY_SCOUT_TRANSPORT_CLASS = "org.jboss.soa.esb.scout.proxy.transportClass";
-
/**
* Property that holds directory to use with the helper EPRManager class.
*/
public static final String REGISTRY_FILE_HELPER_DIR = "org.jboss.soa.esb.registry.file.directory";
+ /**
+ * The Content Based Router class property declares which CBR Implementation should be used.
+ */
+ public static final String ROUTER_CBR_CLASS = "org.jboss.soa.esb.routing.cbrClass";
/*
* Connection specific properties
*/
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/Factory.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,58 @@
+/*
+ * 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.common;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+/**
+ * Base class to find a class on the classpath.
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public abstract class Factory
+{
+ private static Logger logger = Logger.getLogger(Factory.class);
+ /**
+ * Loads the class with the given name.
+ * @param className - the className to be found
+ * @return - the class
+ * @throws ClassNotFoundException
+ */
+ protected static Class getClassForName(String className) throws ClassNotFoundException
+ {
+ Class clazz = null;
+ try {
+ logger.log(Priority.DEBUG, "Using the Context ClassLoader");
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ clazz = Class.forName(className, true, contextClassLoader);
+ } catch (ClassNotFoundException classNotFound) {
+ if (logger.isDebugEnabled()) {
+ logger.log(Priority.WARN, "The Contect ClassLoader could not find the class.");
+ logger.log(Priority.WARN, "Using the System ClassLoader");
+ }
+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+ clazz = Class.forName(className, true, systemClassLoader);
+ }
+ return clazz;
+ }
+}
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -86,6 +86,8 @@
public static final String TRANSPORTS_MODULE = "transports";
public static final String DBSTORE_MODULE = "dbstore";
+
+ public static final String ROUTER_MODULE = "messagerouting";
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers (from rev 7283, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers)
Deleted: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/Courier.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java 2006-11-01 19:03:09 UTC (rev 7283)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/Courier.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -1,36 +0,0 @@
-/*
- * 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.couriers;
-
-import org.jboss.soa.esb.message.Message;
-
-public interface Courier
-{
-/**
- * try to deliver an ESB message
- * @param message Message - the message to deliver
- * @return boolean - the result of the delivery
- * @throws CourierException - if problems were encountered
- */
- public abstract boolean deliver(Message message) throws CourierException;
-}
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/Courier.java (from rev 7306, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/Courier.java)
Deleted: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierException.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java 2006-11-01 19:03:09 UTC (rev 7283)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierException.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -1,55 +0,0 @@
-/*
- * 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.couriers;
-
-import org.jboss.soa.esb.BaseException;
-
-/**
- * Dispatch Exception.
- * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
- * @since Version 4.0
- */
-public class CourierException extends BaseException
-{
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Construct an exception instance.
- * @param message Exception message.
- */
- public CourierException(String message) { super(message); }
-
- /**
- * Construct an exception instance.
- * @param message Exception message.
- * @param cause Exception cause.
- */
- public CourierException(String message, Throwable cause) { super(message, cause); }
-
- /**
- * Construct an exception instance.
- * @param cause Exception cause.
- */
- public CourierException(Throwable cause) { super(cause); }
-}
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierException.java (from rev 7306, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierException.java)
Deleted: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java 2006-11-01 19:03:09 UTC (rev 7283)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -1,47 +0,0 @@
-/*
- * 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.couriers;
-
-import org.jboss.internal.soa.esb.couriers.JmsCourier;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.eprs.JMSEpr;
-
-public class CourierFactory
-{
- // private default constructor
- private CourierFactory() {}
-
- public static CourierFactory getInstance(Object obj)
- {
- return _instance;
- }
-
- public static Courier getCourier(EPR epr) throws CourierException
- {
- if (epr instanceof JMSEpr)
- return new JmsCourier((JMSEpr)epr);
- throw new CourierException("Unknown EPR type");
- }
-
- private static final CourierFactory _instance = new CourierFactory();
-}
Copied: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierFactory.java (from rev 7306, labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/couriers/CourierFactory.java)
Modified: labs/jbossesb/trunk/product/core/services/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/services/build.xml 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/build.xml 2006-11-02 01:44:59 UTC (rev 7308)
@@ -31,6 +31,7 @@
<path id="org.jboss.esb.services.base.classpath">
<fileset dir="${org.jboss.esb.ext.lib.dir}" includes="*.jar" excludes="jbossall-client.jar"/>
<fileset dir="${org.jboss.esb.ejb3.lib.dir}" includes="*.jar,*.zip"/>
+ <pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
</path>
<!-- =================================================================== -->
Added: labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl
===================================================================
--- labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,29 @@
+#created on: Oct 30, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+
+#declare any global variables here
+global java.util.List destinationServices;
+
+
+rule "Routing Rule - Serialized based message"
+
+ when
+ Message( type == MessageType.JAVA_SERIALIZED)
+ then
+ System.out.println("Serialized");
+ destinationServices.add("test_category:Serialized_ServiceDestination");
+
+end
+
+rule "Routing Rule - XML based message"
+
+ when
+ Message( type == MessageType.JBOSS_XML)
+ then
+ System.out.println("JBoss_XML");
+ destinationServices.add("test_category:JBOSS_XMLDestination");
+end
\ No newline at end of file
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,42 @@
+/*
+ * 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.services.routing;
+
+import java.util.List;
+
+import org.jboss.soa.esb.message.Message;
+/**
+ * Generic Message Router Interface.
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public interface MessageRouter
+{
+ /**
+ * Routes the message to the next destination.
+ *
+ * @param message
+ * @return List of Strings containing the services to which the message was routed.
+ */
+ public List<String> route(Message message);
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouterException.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouterException.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouterException.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,29 @@
+/*
+ * Created on Jul 15, 2004
+ *
+ */
+package org.jboss.soa.esb.services.routing;
+
+/**
+ * @author gerry
+ *
+ * <p>Created: Jul 15, 2004</p>
+ */
+public class MessageRouterException extends Exception {
+ private static final long serialVersionUID = 1L;
+ public final static String STORE = "Failed to store. ";
+ public final static String DELETE = "Failed to delete. ";
+ public final static String FETCH = "Failed to fetch. ";
+
+ public MessageRouterException(){
+ super();
+ }
+
+ public MessageRouterException (String msg){
+ super(msg);
+ }
+
+ public MessageRouterException (String msg, Throwable cause){
+ super (msg, cause);
+ }
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.services.routing.cbr;
+
+import java.util.List;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.routing.MessageRouter;
+
+/**
+ * Content Based Router Interface.
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public interface ContentBasedRouter extends MessageRouter {
+ /**
+ * Route a message using a certain ruleSet.
+ *
+ * @param ruleSet - String reference to a file which contains a ruleSet.
+ * @param message - Message that needs routing.
+ * @return
+ */
+ public List<String> route(String ruleSet, Message message);
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouterFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouterFactory.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouterFactory.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,56 @@
+/*
+* 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.services.routing.cbr;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.common.Factory;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+/**
+ * Returns an instance of the Registry.
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class ContentBasedRouterFactory extends Factory
+{
+ private static Logger logger = Logger.getLogger(ContentBasedRouterFactory.class);
+
+ public static ContentBasedRouter getRouter() throws MessageRouterException
+ {
+ ContentBasedRouter cbr = null;
+ String className = Configuration.getContentBasedRouterImplementationClass();
+ logger.log(Priority.INFO, "Going to load " + className);
+ try {
+ // instruct class loader to load the Content Based Router Implementation
+ Class cbrClass = getClassForName(className);
+ // Try to get an instance of the CBR
+ cbr = (ContentBasedRouter) cbrClass.newInstance();
+ } catch (ClassNotFoundException cnfex) {
+ throw new MessageRouterException("Content Based Router Implementation=" + className + " not found", cnfex);
+ } catch (Exception e) {
+ throw new MessageRouterException(className + " invokation problem. " + e.getLocalizedMessage(), e);
+ }
+ return cbr;
+ }
+}
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouter.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,134 @@
+package org.jboss.soa.esb.services.routing.cbr;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.WorkingMemory;
+import org.drools.compiler.PackageBuilder;
+import org.drools.rule.Package;
+import org.jboss.soa.esb.addressing.EPR;
+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.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+
+
+public class JBossRulesRouter implements ContentBasedRouter
+{
+ private static Map<String,WorkingMemory> workingMemories=new HashMap<String,WorkingMemory>();
+ private static Logger logger = Logger.getLogger(JBossRulesRouter.class);
+
+ /**
+ * Constructor.
+ * @param ruleSet String
+ * @throws MessageRouterException
+ */
+ public JBossRulesRouter()
+ {
+ super();
+ }
+
+ public List<String> route(Message message){
+ logger.log(Priority.ERROR, "Do not use, this is not implemented");
+ //Route to /dev/null?
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<String> route(String ruleSet, Message message)
+ {
+ List<String> destinationServices = new ArrayList<String>();
+ try {
+ if (!workingMemories.containsKey(ruleSet)) {
+ logger.log(Priority.INFO, "Reading ruleSet from file=" + ruleSet);
+ RuleBase ruleBase = readRuleBase(ruleSet);
+ WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ workingMemories.put(ruleSet, workingMemory);
+ }
+ logger.log(Priority.DEBUG, "Obtained message=" + message + " with ruleSet=" + ruleSet);
+ WorkingMemory workingMemory = workingMemories.get(ruleSet);
+ workingMemory.setGlobal("destinationServices", destinationServices);
+ workingMemory.assertObject(message);
+ logger.log(Priority.INFO, "Fire the rules engine");
+ workingMemory.fireAllRules();
+ //Now route there, later we will implement an option to place a callback.
+ destinationServices = (List) workingMemory.getGlobal("destinationServices");
+ logger.log(Priority.DEBUG, "Destination Services List: " + destinationServices);
+ for (Iterator<String> i=destinationServices.iterator();i.hasNext();) {
+ String destinationService = i.next();
+ String[] strArray = destinationService.split(":");
+ String category = strArray[0];
+ String serviceName = strArray[1];
+ boolean isSent=false;
+ try {
+ Registry registry = RegistryFactory.getRegistry();
+ logger.log(Priority.INFO, "Looking for EPRs for category=" + category +
+ " and serviceName=" + serviceName);
+ Collection<EPR> eprs = registry.findEPRs(category, serviceName);
+ for (Iterator<EPR> eprIter=eprs.iterator();eprIter.hasNext();) {
+ EPR epr = eprs.iterator().next();
+ logger.log(Priority.INFO, "Message=" + message + " -> Destination=" + destinationService);
+ try {
+ //Give the message to the courier
+ Courier courier = CourierFactory.getCourier(epr);
+ courier.deliver(message);
+ isSent=true;
+ break;
+ } catch (CourierException ce) {
+ logger.log(Priority.ERROR, "Could not send using epr:" + epr);
+ //if there are more eprs in the collection is will try the next one.
+ }
+ }
+ if (isSent==false) {
+ logger.log(Priority.ERROR, "Could not find any valid EPRs. Message is not routed");
+ //Route to /dev/null?
+ }
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, "Could not obtain an EPR from the Registry. Message is not routed" + re.getLocalizedMessage(), re);
+ //Route to /dev/null?
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Priority.ERROR, e.getMessage() + ". Message is not routed", e);
+ //Route to /dev/null?
+ }
+ return destinationServices;
+ }
+
+ /**
+ * Reading the rules from a file, we may want to allow other ways to
+ * set the rule.
+ */
+ private static RuleBase readRuleBase(String rulesFile) throws Exception
+ {
+ //read in the rules
+ InputStream inputStream = JBossRulesRouter.class.getResourceAsStream( "/" + rulesFile );
+ Reader source = new InputStreamReader(inputStream);
+ PackageBuilder builder = new PackageBuilder();
+ //this wil parse and compile in one step
+ //NOTE: There are 2 methods here, the one argument one is for normal DRL.
+ builder.addPackageFromDrl( source );;
+ //get the compiled package (which is serializable)
+ Package pkg = builder.getPackage();
+ //add the package to a rulebase (deploy the rule package).
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage(pkg);
+ return ruleBase;
+ }
+
+}
Modified: labs/jbossesb/trunk/product/core/services/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/build.xml 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/tests/build.xml 2006-11-02 01:44:59 UTC (rev 7308)
@@ -23,7 +23,8 @@
<path id="org.jboss.esb.tests.base.classpath">
<fileset dir="../${org.jboss.esb.ext.lib.dir}"
- includes="*.jar" excludes="jbossall-client.jar"/>
+ includes="*.jar" excludes="jbossall-client.jar"/>
+ <pathelement location="${basedir}/../rules"/>
<pathelement location="${org.jboss.esb.module.classes.dir}"/>
<pathelement location="${org.jboss.esb.internal.dest}/classes/rosetta"/>
<pathelement location="${org.jboss.esb.ejb3_conf.tests.src.dir}"/>
Added: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,108 @@
+/*
+ * 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.services.routing.cbr;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class ContentBasedRoutingUnitTest
+{
+ @Test
+ public void routeSerializedMessage()
+ {
+ try {
+ //new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ //set some properties inside the Message
+ message.getProperties().setProperty("prop1", "val1");
+ message.getProperties().setProperty("prop2", "val2");
+ //set the body inside the Message
+ message.getBody().setContents(("TEST BODY").getBytes());
+ //set some object attachments inside the Message
+ message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+
+ ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
+ List<String> destinationServices = cbr.route("JBossESBRules.drl",message);
+ assertEquals(destinationServices.iterator().next(),"test_category:Serialized_ServiceDestination");
+ } catch (MessageRouterException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void routeXMLMessage()
+ {
+ try {
+ //add new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ //set some properties inside the Message
+ message.getProperties().setProperty("prop1", "val1");
+ message.getProperties().setProperty("prop2", "val2");
+ //set the body inside the Message
+ message.getBody().setContents(("TEST BODY").getBytes());
+ //set some object attachments inside the Message
+ message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+
+ ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
+ List<String> destinationServices = cbr.route("JBossESBRules.drl",message);
+ assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XMLDestination");
+ } catch (MessageRouterException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @BeforeClass
+ public static void runBeforeAllTests() throws Exception
+ {
+ try {
+ TestUtil.setESBPropertiesFileToUse();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("We should stop testing, since we don't any config properties");
+ assertTrue(false);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(ContentBasedRoutingUnitTest.class);
+ }
+
+}
Added: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -0,0 +1,84 @@
+/*
+ * 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.services.routing.cbr;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.junit.Test;
+
+/**
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class JBossRulesRouterUnitTest
+{
+ @Test
+ public void routeSerializedMessage()
+ {
+ //new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ //set some properties inside the Message
+ message.getProperties().setProperty("prop1", "val1");
+ message.getProperties().setProperty("prop2", "val2");
+ //set the body inside the Message
+ message.getBody().setContents(("TEST BODY").getBytes());
+ //set some object attachments inside the Message
+ message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+
+ JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", message);
+ assertEquals(destinationServices.iterator().next(),"test_category:Serialized_ServiceDestination");
+ }
+
+ @Test
+ public void routeXMLMessage()
+ {
+ //add new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ //set some properties inside the Message
+ message.getProperties().setProperty("prop1", "val1");
+ message.getProperties().setProperty("prop2", "val2");
+ //set the body inside the Message
+ message.getBody().setContents(("TEST BODY").getBytes());
+ //set some object attachments inside the Message
+ message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
+ message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+
+ JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", message);
+ assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XMLDestination");
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(JBossRulesRouterUnitTest.class);
+ }
+
+}
Modified: labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-11-02 01:44:59 UTC (rev 7308)
@@ -69,6 +69,8 @@
<property name="org.jboss.soa.esb.persistence.db.pool.test.table" value="pooltest"/>
<!-- # of milliseconds to timeout waiting for a connection from pool -->
<property name="org.jboss.soa.esb.persistence.db.pool.timeout.millis" value="5000"/>
-
+ </properties>
+ <properties name="messagerouting">
+ <property name="org.jboss.soa.esb.routing.cbrClass" value="org.jboss.soa.esb.services.routing.cbr.JBossRulesRouter"/>
</properties>
</esb>
Added: labs/jbossesb/trunk/product/lib/ext/commons-jci-core-1.0-406301.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/commons-jci-core-1.0-406301.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/lib/ext/commons-jci-eclipse-3.2.0.666.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/commons-jci-eclipse-3.2.0.666.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/ListenerUtils.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/ListenerUtils.java 2006-11-02 01:43:03 UTC (rev 7307)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/util/ListenerUtils.java 2006-11-02 01:44:59 UTC (rev 7308)
@@ -90,6 +90,7 @@
* @param paramName Input config paramName.
* @return The file handle for the new "fixed up" config.
*/
+ @SuppressWarnings("unused") //I take it this will be used in the near future?
private static File fixUpConfig(String paramName) throws ParamRepositoryException, IOException {
ParamFileRepository repos = (ParamFileRepository)ParamRepositoryFactory.getInstance();
String configXml = repos.get(paramName);
More information about the jboss-svn-commits
mailing list