[jboss-svn-commits] JBL Code SVN: r9030 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/actions and 17 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 25 23:30:23 EST 2007
Author: kurt.stam at jboss.com
Date: 2007-01-25 23:30:23 -0500 (Thu, 25 Jan 2007)
New Revision: 9030
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml
Removed:
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/message/CbrListener.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/listeners/message/CbrListenerTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml
Modified:
labs/jbossesb/trunk/product/console/
labs/jbossesb/trunk/product/console/build.properties
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
labs/jbossesb/trunk/product/core/services/rules/JBossESBRules-XPath.drl
labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl
labs/jbossesb/trunk/product/core/services/rules/XPathLanguage.dsl
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
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/cbr/ContentBasedRouter.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
labs/jbossesb/trunk/product/install/build.xml
labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/jbossesb.xml
labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/MyESBRules-XPath.drl
labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/XPathLanguage.dsl
labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/jbossesb.xml
labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/readme.txt
labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules-XPath.drl
labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules.drl
labs/jbossesb/trunk/product/samples/quickstarts/static_router/
labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple/
Log:
Changing the CBR into an action. This fixes all the error handling and reduces complexity.
Pulling the service references out of the rules and into the configuration.
Property changes on: labs/jbossesb/trunk/product/console
___________________________________________________________________
Name: svn:ignore
- TESTS-TestSuites.xml
+ TESTS-TestSuites.xml
build
Modified: labs/jbossesb/trunk/product/console/build.properties
===================================================================
--- labs/jbossesb/trunk/product/console/build.properties 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/console/build.properties 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,4 +1,4 @@
-deploy.dir=H:/jboss-4.0.4.GA/server/default/deploy
+deploy.dir=/jboss-4.0.5.GA/server/default/deploy
db.host=localhost
db.port=5432
Deleted: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,343 +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.actions;
-
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.addressing.Call;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-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.couriers.CourierTimeoutException;
-import org.jboss.soa.esb.couriers.CourierUtil;
-import org.jboss.soa.esb.couriers.TwoWayCourier;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.listeners.ListenerUtil;
-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.services.routing.MessageRouterException;
-
-/**
- * Action proxy to call the Content Based Router.
- *
- * @author kstam at redhat.com
- *
- */
-public class CbrProxyAction
-{
- private static Logger _logger = Logger.getLogger(CbrProxyAction.class);
-
- /** Collection of EPRS for the Content Based Router */
- protected Collection<EPR> _eprs;
-
- /** Configuration Tree */
- protected ConfigTree _config;
-
- /** Default 1 minute Listener Timeout in millis */
- final private static long DEFAULT_REPLY_LISTENER_TIMEOUT = 60000;
-
- /** replyListenerTimout */
- private long _replyListenerTimeout = DEFAULT_REPLY_LISTENER_TIMEOUT;
-
- /** replyToEPR */
- private EPR _repliesToMe;
-
- /**
- * Constructor of the Content Based Router Proxy. This constructor obtains
- * the EPRs of the Content Based Router.
- *
- * @param config
- * @throws RegistryException
- */
- public CbrProxyAction(ConfigTree config) throws RegistryException
- {
- _config = config;
- ConfigTree replyElement = _config
- .getFirstChild(ListenerTagNames.REPLY_TO_EPR_TAG);
- if (null != replyElement)
- {
- try
- {
- _repliesToMe = ListenerUtil.assembleEpr(replyElement);
- }
- catch (ConfigurationException e)
- {
- _logger.fatal("Invalid " + ListenerTagNames.REPLY_TO_EPR_TAG
- + " element");
- }
- }
- Registry registry = RegistryFactory.getRegistry();
- String serviceCategoryName = config
- .getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
- String serviceName = config
- .getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
- _eprs = registry.findEPRs(serviceCategoryName, serviceName);
- if (config.getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG) != null)
- {
- try
- {
- _replyListenerTimeout = Long
- .parseLong(config
- .getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG));
- }
- catch (NumberFormatException nfe)
- {
- _logger
- .error(
- "Could not parse "
- + config
- .getAttribute(ListenerTagNames.REPLY_LISTENER_TIMEOUT_TAG)
- + " to long.", nfe);
- }
- }
- }
-
- /**
- * 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, using the default routeAndDeliver.");
- return routeAndDeliver(message);
- }
-
- /**
- * Just route. The routing returns the message with a Collection of
- * destinationService names.
- *
- * @param message
- * @return message, a collection of service destinations is added to the
- * message.
- */
- public Message route(Message message) throws MessageRouterException
- {
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES,
- Boolean.FALSE);
- Message replyMessage = null;
- try
- {
-
- for (Iterator<EPR> eprIterator = _eprs.iterator(); eprIterator
- .hasNext();)
- {
- try
- {
- // Just use the first EPR in the list.
- EPR epr = eprIterator.next();
- TwoWayCourier courier = CourierFactory
- .getCourier(epr, null);
- EPR replyEpr = getReplyToEpr(epr);
- if (message.getHeader().getCall() == null)
- {
- Call call = new Call();
- message.getHeader().setCall(call);
- }
- message.getHeader().getCall().setReplyTo(replyEpr);
- // If not successful try the next EPR
- if (courier.deliver(message))
- {
- courier.setReplyToEpr(replyEpr);
- try
- {
- // wait for the reply.
- replyMessage = courier
- .pickup(_replyListenerTimeout);
- }
- catch (CourierTimeoutException e)
- {
- throw new MessageRouterException(e
- .getLocalizedMessage(), e);
- }
- // if we get here we were successful so we can break
- // from the loop and reply.
- break;
- }
- else
- {
- _logger
- .warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
- }
- }
- catch (MalformedEPRException e)
- {
- _logger.warn("Malformed EPR.");
- // Let's be optimistic and try to see if there is another
- // epr.
- continue;
- }
- catch (URISyntaxException e)
- {
- _logger.warn(e.getLocalizedMessage(), e);
- // Let's be optimistic and try to see if there is another
- // epr.
- continue;
- }
- }
- }
- catch (CourierException ce)
- {
- _logger.error("Could not send to the CBR. "
- + ce.getLocalizedMessage(), ce);
-
- throw new MessageRouterException(ce);
- }
- return replyMessage;
- }
-
- /**
- * Builds a temporary EPR to which we can reply to.
- *
- * @param epr -
- * the toEPR
- * @return
- * @throws URISyntaxException
- */
- private EPR getReplyToEpr(EPR toEpr) throws URISyntaxException,
- CourierException, MalformedEPRException
- {
- EPR replyToEpr = CourierUtil.getTemporaryReplyToEpr(toEpr);
- return replyToEpr;
- }
-
- EPR newReplyToEpr() throws URISyntaxException, CourierException, MalformedEPRException
- {
- EPR replyToEpr = CourierUtil.getTemporaryReplyToEpr(_repliesToMe);
- return replyToEpr;
- }
-
- /**
- * Do *not* route, just deliver. Pulls the destinationServices from the
- * message and deliver the message to the destination(s).
- *
- * @param message
- * @return the message that was passed in.
- */
- @SuppressWarnings("unchecked")
- public Message deliver(Message message)
- {
- Collection<String> destinationServices = (Collection) message
- .getProperties().getProperty(
- MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
- if (destinationServices != null)
- {
- // TODO there is no error handling for CBR.
-
- // TODO Remove the property from the message?
- MessageRouter.deliverMessages(destinationServices, message);
- }
- else
- {
- _logger
- .error("No destination services were found, the message was not delivered");
- }
- return message;
- }
-
- /**
- * Route and Deliver to the destination Services.
- *
- * @param message -
- * to be routed and delivered
- * @return message - same message is returned
- */
- 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; // we were successful so we are done
- }
- }
- }
- catch (MalformedEPRException e)
- {
- // TODO better error handling
-
- _logger.error("Could not send to the CBR because of malformed EPR.");
- }
- catch (CourierException ce)
- {
- _logger.error("Could not send to the CBR. "
- + ce.getLocalizedMessage(), ce);
- }
- return message;
- }
-
- public void exceptionCallback(Message message, Throwable t)
- {
- String sMsg = new StringBuilder(
- " ExceptionTrower.exceptionCallback CALLED ").append(message)
- .toString();
- _logger.fatal(sMsg, t);
- @SuppressWarnings("unused")
- NotificationList nl = ActionUtils.getNotifyList(_config, "err");
- // Here you can send notifications to everybody
- }
-
- public void okMethod(Message message)
- {
- Collection destinationServices = (Collection) message.getProperties()
- .getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
- // Do something with the callBack info
- _logger.log(Priority.INFO, destinationServices);
-
- }
-
-}
\ No newline at end of file
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+
+/**
+ * Routes the Message argument to a fixed list of services ([category,name])
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @since Version 4.0
+ */
+package org.jboss.soa.esb.actions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.CourierException;
+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.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.services.routing.MessageRouterException;
+import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouterFactory;
+
+public class ContentBasedRouter
+{
+ public static final String ROUTE_TO_TAG = "route-to";
+ private Logger log = Logger.getLogger(this.getClass());
+
+ private ContentBasedRouter()
+ {
+ }
+
+ public ContentBasedRouter(ConfigTree config) throws ConfigurationException, RegistryException, MessageRouterException
+ {
+ _config = config;
+ checkMyParms();
+ _registry = RegistryFactory.getRegistry();
+ _cbr = ContentBasedRouterFactory.getRouter();
+ } // ________________________________
+
+ public Message process(Message message) throws MalformedEPRException, RegistryException, CourierException, MessageRouterException
+ {
+ //Call call = message.getHeader().getCall();
+ //if (null == call || null == call.getMessageID())
+ // throw new IllegalArgumentException("Null message ID");
+
+ List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message);
+ Collection<String[]> outgoingDestinations = new ArrayList<String[]>();
+ for (String destination : destinations) {
+ if (_destinations.containsKey(destination)) {
+ outgoingDestinations.add(_destinations.get(destination));
+ }
+ }
+ if (outgoingDestinations.size()>0) {
+ MessageRouter.deliverMessages(outgoingDestinations, message);
+ } else if (destinations.size() > 0) {
+ log.error("The rule destination(s) " + destinations
+ + " are not in found in the destination names in the configuration "
+ + _destinations.keySet() + ". Please fix your configuration.");
+ }
+
+ return message;
+ } // ________________________________
+
+ protected void checkMyParms() throws ConfigurationException
+ {
+ if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG)==null) {
+ _logger.error("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found in " + _config.getName() + ".");
+ throw new ConfigurationException("Required attribute" + ListenerTagNames.RULE_SET_TAG + " not found.");
+ } else {
+ _ruleSet =_config.getAttribute(ListenerTagNames.RULE_SET_TAG);
+ if (_ruleSet==null) {
+ throw new ConfigurationException("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found.");
+ }
+ _ruleLanguage =_config.getAttribute(ListenerTagNames.RULE_LANGUAGE_TAG);
+ String ruleReload = _config.getAttribute(ListenerTagNames.RULE_RELOAD_TAG);
+ if (ruleReload!=null && "true".equals(ruleReload)) {
+ _ruleReload = true;
+ }
+ }
+ _destinations = new HashMap<String, String[]>();
+ ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
+
+ if (null == destList || destList.length < 1)
+ {
+ _logger
+ .warn("Missing or empty destination list - This action class won't have any effect");
+ return;
+ }
+ for (ConfigTree curr : destList) {
+ try
+ {
+ String key = curr.getAttribute(ListenerTagNames.DESTINATION_NAME_TAG, null);
+ String category = curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
+ String name = curr.getAttribute(ListenerTagNames.SERVICE_NAME_TAG, null);
+ _destinations.put(key, new String[] { category, name });
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(
+ "Problems with destination list", e);
+ }
+ }
+
+ } // ________________________________
+
+ protected ConfigTree _config;
+
+ protected Map<String, String[]> _destinations;
+
+ private String _ruleSet;
+
+ private String _ruleLanguage;
+
+ private boolean _ruleReload;
+
+ protected Registry _registry;
+
+ private org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter _cbr;
+
+ protected static Logger _logger = Logger.getLogger(ContentBasedRouter.class);
+
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/StaticRouter.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -27,30 +27,25 @@
*/
package org.jboss.soa.esb.actions;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.Call;
-import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.couriers.CourierFactory;
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.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.services.routing.MessageRouterException;
public class StaticRouter
{
- public static final String DESTINATION_LIST_TAG = "destinations";
-
public static final String ROUTE_TO_TAG = "route-to";
private StaticRouter()
@@ -72,30 +67,13 @@
if (null == call || null == call.getMessageID())
throw new IllegalArgumentException("Null message ID");
- for (String[] curr : _destinations)
- {
- EPR epr = _registry.findEPR(curr[0], curr[1]);
- if (epr instanceof FileEpr)
- {
- FileEpr fpr = (FileEpr) epr;
- FileEpr newEpr = new FileEpr(fpr.getURL());
- newEpr.setPostDelete(false);
- newEpr.setPostDirectory(fpr.getURL().getFile());
- newEpr.setPostSuffix(fpr.getInputSuffix());
- epr = newEpr;
- }
- CourierFactory.getCourier(epr).deliver(message);
- }
+ MessageRouter.deliverMessages(_destinations, message);
return message;
}
- catch (MalformedURLException ex)
+ catch (MessageRouterException ex)
{
throw new MalformedEPRException(ex);
- }
- catch (URISyntaxException ex)
- {
- throw new MalformedEPRException(ex);
- }
+ }
} // ________________________________
protected void checkMyParms() throws ConfigurationException
@@ -104,8 +82,7 @@
ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
if (null == destList || destList.length < 1)
{
- _logger
- .warn("Missing or empty destination list - This action class won't have any effect");
+ _logger.warn("Missing or empty destination list - This action class won't have any effect");
return;
}
for (ConfigTree curr : destList)
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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerTagNames.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -61,7 +61,8 @@
public static final String EXCEPTION_METHOD_TAG = "exceptionMethod";
public static final String HTTP_ROUTER_ROUTE_URL = "routeUrl";
-
+ /** Routing */
+ public static final String DESTINATION_NAME_TAG = "destination-name";
/** Content Based Routing */
/** RuleSet reference (Filename) */
public static final String RULE_SET_TAG = "ruleSet";
Deleted: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrListener.java 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/CbrListener.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,143 +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.listeners.message;
-
-import java.util.Collection;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.couriers.CourierException;
-import org.jboss.soa.esb.couriers.CourierFactory;
-import org.jboss.soa.esb.couriers.CourierTimeoutException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerManager;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.routing.MessageRouter;
-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 listener.
- * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
- * @since Version 4.0
- */
-
-public class CbrListener extends MessageAwareListener
-{
- protected static transient Logger _logger = Logger.getLogger(CbrListener.class);
- protected ContentBasedRouter _cbr;
- protected String _ruleSet;
- protected String _ruleLanguage;
- protected boolean _ruleReload;
-
- public CbrListener(ListenerManager controller, ConfigTree config) throws ConfigurationException
- {
- super(controller, config);
- }
-
- protected void checkMyParms() throws ConfigurationException
- {
- super.checkMyParms();
- if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG)==null) {
- _logger.error("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found in " + _config.getName() + ".");
- throw new ConfigurationException("Required attribute" + ListenerTagNames.RULE_SET_TAG + " not found.");
- } else {
- _ruleSet =_config.getAttribute(ListenerTagNames.RULE_SET_TAG);
- if (_ruleSet==null) {
- throw new ConfigurationException("Required attribute " + ListenerTagNames.RULE_SET_TAG + " not found.");
- }
- _ruleLanguage =_config.getAttribute(ListenerTagNames.RULE_LANGUAGE_TAG);
- String ruleReload = _config.getAttribute(ListenerTagNames.RULE_RELOAD_TAG);
- if (ruleReload!=null && "true".equals(ruleReload)) {
- _ruleReload = true;
- }
- }
-
- } // ________________________________
-
- @Override
- public boolean initializeRun()
- {
- if (!super.initializeRun())
- return false;
-
- try
- {
- _cbr =ContentBasedRouterFactory.getRouter();
- }
- catch (MessageRouterException e)
- {
- return false;
- }
- return true;
- } //________________________________
-
- @Override
- public void waitForEventAndProcess(long maxWaitMillis)
- {
- Message message = null;
- try { message = (maxWaitMillis > 0 ) ? _pickUpCourier.pickup(maxWaitMillis) : null; }
- catch (CourierTimeoutException e) { return; }
- catch (CourierException e)
- {
- _logger.error(e);
- return;
- }
-
- if (null!=message)
- {
- try
- {
- if (null!=message) {
- _logger.log(Priority.DEBUG, "Sending message to the Content Based Router.");
- Collection<String> destinationServices = _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message);
- if (Boolean.FALSE.equals(message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES))) {
- message.getProperties().setProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST, destinationServices);
- try {
- _logger.debug("Replying to caller");
- if (message.getHeader().getCall()!=null && message.getHeader().getCall().getReplyTo()!=null) {
- EPR replyTo = message.getHeader().getCall().getReplyTo();
- CourierFactory.getCourier(replyTo).deliver(message);
- } else {
- _logger.log(Priority.ERROR, "Unable to reply to caller. Could not optain replyTo EPR.");
- }
- } catch (CourierException ce) {
- _logger.log(Priority.ERROR, "Unable to reply to caller. "+ ce.getLocalizedMessage(), ce);
- }
- }
- }
- }
- catch (Exception e)
- {
- _logger.error(e);
- return;
- }
- }
-
- } //________________________________
-
-}
Modified: labs/jbossesb/trunk/product/core/services/rules/JBossESBRules-XPath.drl
===================================================================
--- labs/jbossesb/trunk/product/core/services/rules/JBossESBRules-XPath.drl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/rules/JBossESBRules-XPath.drl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -8,7 +8,7 @@
expander XPathLanguage.dsl
#declare any global variables here
-global java.util.List destinationServices;
+global java.util.List destinations;
rule "Routing Rule using XPATH match"
@@ -16,7 +16,7 @@
xpathMatch "/jbossesb"
then
Log : "XPath Matched";
- Destination : "test_category:JBOSS_XML_XPath_Destination";
+ Destination : "XML_XPath_Destination";
end
rule "Routing Rule using XPATH equals"
@@ -25,7 +25,7 @@
xpathEquals "/Dave", "rocks"
then
Log : "XPath Equals";
- Destination : "test_category:JBOSS_XML_XPath_Dave_Destination";
+ Destination : "XML_XPath_Dave_Destination";
end
rule "Routing Rule using XPATH greater than"
@@ -34,7 +34,7 @@
xpathGreaterThan "/price" , "1.00"
then
Log : "XPath Greater Then";
- Destination : "test_category:JBOSS_XML_XPath_GreaterThan_Destination";
+ Destination : "XML_XPath_GreaterThan_Destination";
end
rule "Routing Rule using XPATH less than"
@@ -43,5 +43,5 @@
xpathLessThan "/price", "1.00"
then
Log : "XPath Less Then";
- Destination : "test_category:JBOSS_XML_XPath_LessThan_Destination";
+ Destination : "XML_XPath_LessThan_Destination";
end
Modified: labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl
===================================================================
--- labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/rules/JBossESBRules.drl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -6,7 +6,7 @@
import org.jboss.soa.esb.message.format.MessageType;
#declare any global variables here
-global java.util.List destinationServices;
+global java.util.List destinations;
rule "Routing Rule - Serialized based message"
@@ -15,7 +15,7 @@
Message( type == MessageType.JAVA_SERIALIZED)
then
System.out.println("Serialized");
- destinationServices.add("test_category:Serialized_ServiceDestination");
+ destinations.add("serialized-destination");
end
@@ -25,5 +25,5 @@
Message( type == MessageType.JBOSS_XML)
then
System.out.println("JBoss_XML");
- destinationServices.add("test_category:JBOSS_XMLDestination");
+ destinations.add("xml-destination");
end
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/services/rules/XPathLanguage.dsl
===================================================================
--- labs/jbossesb/trunk/product/core/services/rules/XPathLanguage.dsl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/rules/XPathLanguage.dsl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -4,4 +4,4 @@
[when]xpathGreaterThan "{xpath}", "{value}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentGreaterThan(msg, "{xpath}", "{value}") )
[when]xpathLessThan "{xpath}", "{value}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentLessThan(msg, "{xpath}", "{value}") )
[then]Log : "{message}"=System.out.println("{message}");
-[then]Destination : "{message}"=destinationServices.add("{message}");
+[then]Destination : "{message}"=destinations.add("{message}");
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -40,7 +40,7 @@
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.rule.Package;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
import org.jboss.soa.esb.services.routing.cbr.CBRException;
import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter;
@@ -60,17 +60,15 @@
private static Logger logger = Logger.getLogger(JBossRulesRouter.class);
/**
- * Route the message, where the routing rules are supplied as part of the
- * message itself. We don't support this yet, as I don't see the need right
- * now. However when the need arises, this is were it goes.
+ * Route the message with a reference to the ruleSets supplied in the message.
+ * Not implemented.
*
- * @param message -
- * Message that needs routing.
+ * @param message - Message that needs routing.
*/
public List<String> route (Message message)
+ throws MessageRouterException
{
- logger.log(Priority.ERROR, "Do not use, this is not implemented");
- // Route to /dev/null?
+ logger.error("Not implemented");
return null;
}
@@ -83,7 +81,7 @@
* Message that needs routing.
*/
public List<String> route (String ruleSet, boolean ruleReload,
- Message message)
+ Message message) throws MessageRouterException
{
return route(ruleSet, null, ruleReload, message);
}
@@ -102,63 +100,53 @@
*/
@SuppressWarnings("unchecked")
public List<String> route (String ruleSet, String ruleLanguage,
- boolean ruleReload, Message message)
+ boolean ruleReload, Message message) throws MessageRouterException
{
- List<String> destinationServices = new ArrayList<String>();
- try
- {
- String newRuleSet = null;
- boolean isRulesChanged = false;
-
- if (ruleReload)
- {
- String currentRuleSet = ruleSets.get(ruleSet);
- newRuleSet = getRules(ruleSet, ruleLanguage);
- if (currentRuleSet == null || !currentRuleSet
- .equals(newRuleSet))
- {
- isRulesChanged = true;
- }
- }
- RuleBase ruleBase = ruleBases.get(ruleSet);
- if (ruleBase == null || isRulesChanged)
- {
- logger.log(Priority.INFO,
- "Reading ruleSet from file=" + ruleSet);
- ruleBase = readRuleBase(ruleSet, ruleLanguage);
- if (ruleBase != null) ruleBases.put(ruleSet, ruleBase);
- if (newRuleSet == null)
- {
- newRuleSet = getRules(ruleSet, ruleLanguage);
- }
- if (ruleSet != null) ruleSets.put(ruleSet, newRuleSet);
- }
- WorkingMemory workingMemory = ruleBase.newWorkingMemory();
- logger.log(Priority.DEBUG,
- "Obtained message=" + message + " with ruleSet=" + ruleSet);
- workingMemory.setGlobal("destinationServices", destinationServices);
- workingMemory.assertObject(message);
- logger.log(Priority.INFO, "Fire the JBossRules Engine");
- workingMemory.fireAllRules();
- destinationServices = (List) workingMemory
- .getGlobal("destinationServices"); // is this needed?
- logger.log(Priority.DEBUG,
- "Destination Services List: " + destinationServices);
- Boolean isDeliverMessages = (Boolean) message.getProperties()
- .getProperty(MessageRouter.DELIVER_MESSAGES);
- // Deliver the message to their desitinations unless told not to.
- if (!Boolean.FALSE.equals(isDeliverMessages))
- {
- deliverMessages(destinationServices, message);
- }
- }
- catch (Exception e)
- {
- logger.log(Priority.ERROR,
- e.toString() + ". Message is not routed.", e);
- // Route to /dev/null?
- }
- return destinationServices;
+ List<String> destinations = new ArrayList();
+ try {
+ String newRuleSet = null;
+ boolean isRulesChanged = false;
+
+ if (ruleReload)
+ {
+ String currentRuleSet = ruleSets.get(ruleSet);
+ newRuleSet = getRules(ruleSet, ruleLanguage);
+ if (currentRuleSet == null || !currentRuleSet
+ .equals(newRuleSet))
+ {
+ isRulesChanged = true;
+ }
+ }
+ RuleBase ruleBase = ruleBases.get(ruleSet);
+ if (ruleBase == null || isRulesChanged)
+ {
+ logger.log(Priority.DEBUG,
+ "Reading ruleSet from file=" + ruleSet);
+ ruleBase = readRuleBase(ruleSet, ruleLanguage);
+ if (ruleBase != null) ruleBases.put(ruleSet, ruleBase);
+ if (newRuleSet == null)
+ {
+ newRuleSet = getRules(ruleSet, ruleLanguage);
+ }
+ if (ruleSet != null) ruleSets.put(ruleSet, newRuleSet);
+ }
+ WorkingMemory workingMemory = ruleBase.newWorkingMemory();
+ logger.log(Priority.DEBUG,
+ "Obtained message=" + message + " with ruleSet=" + ruleSet);
+ workingMemory.setGlobal("destinations", destinations);
+ workingMemory.assertObject(message);
+ logger.log(Priority.DEBUG, "Fire the JBossRules Engine");
+ workingMemory.fireAllRules();
+ logger.log(Priority.DEBUG,
+ "Outgoing Destinations: " + destinations);
+ return destinations;
+ } catch (IOException ioe) {
+ throw new MessageRouterException("Could not read the rules. " + ioe.getMessage(), ioe);
+ } catch (DroolsParserException dpe) {
+ throw new MessageRouterException("Could not parse the rules. " + dpe.getMessage(), dpe);
+ } catch (CBRException cbre) {
+ throw new MessageRouterException("Could not parse the rules. " + cbre.getMessage(), cbre);
+ }
}
/**
@@ -206,18 +194,14 @@
// get the compiled package (which is serializable)
Package pkg = builder.getPackage();
// add the package to a rulebase (deploy the rule package).
-
try
{
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
-
return ruleBase;
+ } catch (Exception ex) {
+ throw new CBRException(ex.getMessage(), ex);
}
- catch (Exception ex)
- {
- throw new CBRException(ex);
- }
}
}
Modified: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -21,6 +21,8 @@
*/
package org.jboss.soa.esb.services.routing;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -29,6 +31,7 @@
import org.apache.log4j.Priority;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
@@ -47,10 +50,8 @@
{
private static Logger logger = Logger.getLogger(MessageRouter.class);
- public static String ROUTING_DESTINATION_SERVICE_LIST = "routing.destinationServiceList";
+
- public static String DELIVER_MESSAGES = "routing.deliverMessages";
-
/**
* Routes the message to the next destination.
*
@@ -58,7 +59,8 @@
* @return List of Strings containing the services to which the message was
* routed.
*/
- public abstract List<String> route(Message message);
+ public abstract List<String> route(Message message)
+ throws MessageRouterException;
/**
* Sends the message on to the service with the name(s) we just obtained
@@ -69,65 +71,73 @@
* @param message -
* the message that needs routing and delivery
*/
-
- // TODO handle failures?
-
public synchronized static void deliverMessages(
- Collection<String> destinationServices, Message message)
+ Collection<String[]> destinations, Message message) throws MessageRouterException
{
- for (Iterator<String> i = destinationServices.iterator(); i.hasNext();)
+ for (Iterator<String[]> i = destinations.iterator(); i.hasNext();)
{
- String destinationService = i.next();
- String[] strArray = destinationService.split(":");
- String category = strArray[0];
- String serviceName = strArray[1];
+ String[] destination = (String[]) i.next();
+ String category = destination[0];
+ String serviceName = destination[1];
boolean isSent = false;
+ Exception lastException = null;
try
{
Registry registry = RegistryFactory.getRegistry();
- logger.log(Priority.INFO, "Looking for EPRs for category="
+ logger.log(Priority.DEBUG, "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);
+ logger.log(Priority.DEBUG, "Message=" + message
+ + " -> Destination=" + destinations);
try
{
+ //TODO I think the following if block should be part of
+ //the FileEpr construction?
+ if (epr instanceof FileEpr) {
+ try {
+ FileEpr fileEpr = (FileEpr) epr;
+ FileEpr newEpr = new FileEpr(fileEpr.getURL());
+ newEpr.setPostDelete(false);
+ newEpr.setPostDirectory(fileEpr.getURL().getFile());
+ newEpr.setPostSuffix(fileEpr.getInputSuffix());
+ epr = newEpr;
+ } catch (URISyntaxException usex) {
+ logger.log(Priority.ERROR, "Malformed epr while setting :"
+ + epr, usex);
+ } catch (MalformedURLException muex) {
+ logger.log(Priority.ERROR, "Malformed epr:"
+ + epr, muex);
+ }
+ }
// Give the message to the courier
Courier courier = CourierFactory.getCourier(epr);
courier.deliver(message);
isSent = true;
break;
- }
- catch (MalformedEPRException ex)
- {
- logger.log(Priority.ERROR, "Malformed epr:"
- + epr);
- }
- 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.
- }
+ } catch (MalformedEPRException ex) {
+ logger.log(Priority.ERROR, "Malformed epr:" + epr);
+ lastException = ex;
+ } catch (CourierException ce) {
+ logger.log(Priority.ERROR, "Could not send using epr:"
+ + epr, ce);
+ lastException = ce;
+ // 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?
+ logger.log(Priority.ERROR, "Could not find any valid EPRs. Message is not routed.", lastException);
+ throw new MessageRouterException("Message Could not be delivered. ", lastException);
}
- }
- catch (RegistryException re)
- {
- logger.log(Priority.ERROR,
- "Could not obtain an EPR from the Registry. Message is not routed. "
+ } 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?
+ throw new MessageRouterException("Message Could not be delivered due to issues with the Registry. "
+ + re.getMessage(), re);
}
}
}
Modified: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -25,6 +25,7 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
/**
* Content Based Router Interface.
@@ -51,7 +52,7 @@
* @return List of routing destinations.
*/
public abstract List<String> route (String ruleSet, String ruleLanguage,
- boolean ruleReload, Message message);
+ boolean ruleReload, Message message) throws MessageRouterException;
/**
* Route a message using a certain ruleSet.
@@ -66,5 +67,5 @@
* @return List of routing destinations.
*/
public abstract List<String> route (String ruleSet, boolean ruleReload,
- Message message);
+ Message message) throws MessageRouterException;
}
Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -22,6 +22,7 @@
package org.jboss.internal.soa.esb.services.routing.cbr;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -31,7 +32,7 @@
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.MessageRouter;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -58,9 +59,14 @@
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
- List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
- assertEquals(destinationServices.iterator().next(),"test_category:Serialized_ServiceDestination");
+ try {
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
+ assertEquals(destinationServices.iterator().next(),"serialized-destination");
+ } catch (MessageRouterException mre) {
+ System.out.println("Exception was thrown.");
+ mre.printStackTrace();
+ assertTrue(false);
+ }
}
@Test
@@ -78,9 +84,14 @@
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
- List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XMLDestination");
+ try {
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
+ assertEquals(destinationServices.iterator().next(),"xml-destination");
+ } catch (MessageRouterException mre) {
+ System.out.println("Exception was thrown.");
+ mre.printStackTrace();
+ assertTrue(false);
+ }
}
@BeforeClass
Modified: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -32,7 +32,6 @@
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.MessageRouter;
import org.jboss.soa.esb.services.routing.MessageRouterException;
import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
import org.junit.BeforeClass;
@@ -58,11 +57,10 @@
//set some object attachments inside the Message
message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:Serialized_ServiceDestination");
+ assertEquals(destinationServices.iterator().next(),"serialized-destination");
} catch (MessageRouterException e) {
e.printStackTrace();
assertTrue(false);
@@ -83,11 +81,10 @@
//set some object attachments inside the Message
message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
-
+
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XMLDestination");
+ assertEquals(destinationServices.iterator().next(),"xml-destination");
} catch (MessageRouterException e) {
e.printStackTrace();
}
@@ -107,11 +104,10 @@
//set some object attachments inside the Message
message.getAttachment().addItem(new String("TEST ATTACHMENT1"));
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
-
+
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XML_XPath_Destination");
+ assertEquals(destinationServices.iterator().next(),"XML_XPath_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
}
@@ -125,11 +121,10 @@
Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
//set the body inside the Message
message.getBody().setContents(("<Dave>rocks</Dave>").getBytes());
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XML_XPath_Dave_Destination");
+ assertEquals(destinationServices.iterator().next(),"XML_XPath_Dave_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
}
@@ -143,11 +138,10 @@
Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
//set the body inside the Message
message.getBody().setContents(("<price>1.55</price>").getBytes());
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
-
+
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XML_XPath_GreaterThan_Destination");
+ assertEquals(destinationServices.iterator().next(),"XML_XPath_GreaterThan_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
}
@@ -161,11 +155,10 @@
Message message = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
//set the body inside the Message
message.getBody().setContents(("<price>0.55</price>").getBytes());
- message.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES, Boolean.FALSE);
-
+
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter();
List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
- assertEquals(destinationServices.iterator().next(),"test_category:JBOSS_XML_XPath_LessThan_Destination");
+ assertEquals(destinationServices.iterator().next(),"XML_XPath_LessThan_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
}
Modified: labs/jbossesb/trunk/product/install/build.xml
===================================================================
--- labs/jbossesb/trunk/product/install/build.xml 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/install/build.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -122,7 +122,7 @@
<delete file="${org.jboss.esb.appserver.home}/server/${org.jboss.esb.appserver.config}/deploy/jbossesb-dependencies.sar/smooks-cdr.lst" />
</target>
- <target name="jboss.sar.registry.deploy" description="Deploys the scout/jUDDI Registry to the jbossesb-dependencies.sar">
+ <target name="jboss.sar.registry.deploy" description="Deploys the jUDDI Registry to the jbossesb-dependencies.sar">
<echo>Deploy the jUDDI Registry to jbossesb-dependencies.sar</echo>
<echo>This tasks will only succeed if you already have an existing jbossesb-dependencies.sar</echo>
<copy todir="${org.jboss.esb.appserver.home}/server/${org.jboss.esb.appserver.config}/deploy/jbossesb-dependencies.sar">
@@ -130,8 +130,8 @@
</copy>
</target>
- <target name="jboss.sar.registry.undeploy" description="Undeploys the scout/jUDDI Registry from the jbossesb-dependencies.sar">
- <echo>Deleting the scout/jUDDI Registry from jbossesb-dependencies.sar</echo>
+ <target name="jboss.sar.registry.undeploy" description="Undeploys the jUDDI Registry from the jbossesb-dependencies.sar">
+ <echo>Deleting the jUDDI Registry from jbossesb-dependencies.sar</echo>
<delete>
<fileset dir="${org.jboss.esb.appserver.home}/server/${org.jboss.esb.appserver.config}/deploy/jbossesb-dependencies.sar"
includes="juddi-1.0-SNAPSHOT.jar,juddi-client-1.0-SNAPSHOT.jar"/>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/jbossesb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/jbossesb.xml 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/jbossesb.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -47,17 +47,25 @@
category="Fun_CBRServices_ESB"
name="FunCBRService_ESB"
description="ESB Listener - for the native clients"
- is-gateway="false"
- service-class="org.jboss.soa.esb.listeners.message.CbrListener">
+ is-gateway="false">
<listeners>
<jms-listener name="XPathContentBasedRouter"
busidref="quickstartEsbChannel"
- maxThreads="1">
- <property name="ruleSet" value="MyESBRules-XPath.drl"/>
- <property name="ruleLanguage" value="XPathLanguage.dsl"/>
- <property name="ruleReload" value="true"/>
+ maxThreads="1">
</jms-listener>
- </listeners>
+ </listeners>
+ <actions>
+ <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
+ <property name="ruleSet" value="MyESBRules-XPath.drl"/>
+ <property name="ruleLanguage" value="XPathLanguage.dsl"/>
+ <property name="ruleReload" value="true"/>
+ <property name="destinations">
+ <route-to destination-name="blue" service-category="BlueTeam" service-name="GoBlue" />
+ <route-to destination-name="red" service-category="RedTeam" service-name="GoRed" />
+ <route-to destination-name="green" service-category="GreenTeam" service-name="GoGreen" />
+ </property>
+ </action>
+ </actions>
</service>
<!-- Blue -->
Modified: labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/MyESBRules-XPath.drl
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/MyESBRules-XPath.drl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/MyESBRules-XPath.drl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -8,14 +8,14 @@
expander XPathLanguage.dsl
#declare any global variables here
-global java.util.List destinationServices;
+global java.util.List destinations;
rule "Blue Routing Rule using XPATH"
when
xpathEquals "/Order/@statusCode", "0"
then
Log : "Blue Team";
- Destination : "BlueTeam:GoBlue";
+ Destination : "blue";
end
rule "Red Routing Rule using XPATH"
@@ -23,7 +23,7 @@
xpathEquals "/Order/@statusCode", "1"
then
Log : "Red Team";
- Destination : "RedTeam:GoRed";
+ Destination : "red";
end
rule "Green Routing Rule using XPATH"
@@ -31,5 +31,5 @@
xpathEquals "/Order/@statusCode", "2"
then
Log : "Green Team";
- Destination : "GreenTeam:GoGreen";
+ Destination : "green";
end
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/XPathLanguage.dsl
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/XPathLanguage.dsl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/src/services/rules/XPathLanguage.dsl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -4,4 +4,4 @@
[when]xpathGreaterThan "{xpath}", "{value}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentGreaterThan(msg, "{xpath}", "{value}") )
[when]xpathLessThan "{xpath}", "{value}"=msg : Message( type == MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentLessThan(msg, "{xpath}", "{value}") )
[then]Log : "{message}"=System.out.println("{message}");
-[then]Destination : "{message}"=destinationServices.add("{message}");
+[then]Destination : "{message}"=destinations.add("{message}");
Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/jbossesb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/jbossesb.xml 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/jbossesb.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -56,17 +56,24 @@
category="MyFirstCBRServicesESB"
name="FirstCBRServiceESB"
description="ESB Listener"
- is-gateway="false"
- service-class="org.jboss.soa.esb.listeners.message.CbrListener">
+ is-gateway="false">
<listeners>
<jms-listener name="XPathContentBasedRouter"
busidref="quickstartEsbChannel"
- maxThreads="1">
- <property name="ruleSet" value="MyESBRules-XPath.drl"/>
- <property name="ruleLanguage" value="XPathLanguage.dsl"/>
- <property name="ruleReload" value="true"/>
+ maxThreads="1">
</jms-listener>
- </listeners>
+ </listeners>
+ <actions>
+ <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
+ <property name="ruleSet" value="MyESBRules-XPath.drl"/>
+ <property name="ruleLanguage" value="XPathLanguage.dsl"/>
+ <property name="ruleReload" value="true"/>
+ <property name="destinations">
+ <route-to destination-name="express" service-category="ExpressShipping" service-name="ExpressShippingService"/>
+ <route-to destination-name="normal" service-category="NormalShipping" service-name="NormalShippingService"/>
+ </property>
+ </action>
+ </actions>
</service>
<!-- Normal Shipping -->
Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/readme.txt 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/readme.txt 2007-01-26 04:30:23 UTC (rev 9030)
@@ -42,6 +42,8 @@
XPathLanguage.dsl lives in core\services\rules\XPathLanguage.dsl and ships as jbossesb-rules.jar
* MyESBRules-XPath.drl routes to the appropriate destination service via this command
- Destination : "ExpressShipping:ExpressShippingService";
+ Destination : "express";
+
+ In the jbossesb.xml the "express" destination is related to:
"ExpressShipping" is the service-category (found in esb-config.xml)
- "ExpressShippingService" is the service-name (also found in the esb-config.xml)
\ No newline at end of file
+ "ExpressShippingService" is the service-name (also found in the jbossesb.xml)
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules-XPath.drl
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules-XPath.drl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules-XPath.drl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -8,7 +8,7 @@
expander XPathLanguage.dsl
#declare any global variables here
-global java.util.List destinationServices;
+global java.util.List destinations;
rule "Routing Rule using XPATH"
@@ -18,7 +18,7 @@
Log : "EXPRESS";
Log : "EXPRESS";
Log : "Really It's EXPRESS Shipping";
- Destination : "ExpressShipping:ExpressShippingService";
+ Destination : "express";
end
@@ -29,5 +29,5 @@
Log : "NORMAL";
Log : "NORMAL";
Log : "Really It's NORMAL Shipping";
- Destination : "NormalShipping:NormalShippingService";
+ Destination : "normal";
end
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules.drl
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules.drl 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/product/samples/quickstarts/simple_cbr/src/services/rules/MyESBRules.drl 2007-01-26 04:30:23 UTC (rev 9030)
@@ -6,7 +6,7 @@
import org.jboss.soa.esb.message.format.MessageType;
#declare any global variables here
-global java.util.List destinationServices;
+global java.util.List destinations;
rule "Routing Rule - Serialized based message"
@@ -15,7 +15,7 @@
Message( type == MessageType.JAVA_SERIALIZED)
then
System.out.println("Serialized");
- destinationServices.add("Serialized_ServiceDestinationCat:Serialized_ServiceDestination");
+ destinations.add("serialized");
end
@@ -25,5 +25,5 @@
Message( type == MessageType.JBOSS_XML)
then
System.out.println("JBoss_XML");
- destinationServices.add("CBRContent:ContentBasedRoutingService");
+ destinations.add("xml");
end
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/static_router
___________________________________________________________________
Name: svn:ignore
+ build
listener.log.*
Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/transform_XML2XML_simple
___________________________________________________________________
Name: svn:ignore
+ build
Deleted: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,193 +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.actions;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.InputStream;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.Collection;
-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.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerManager;
-import org.jboss.soa.esb.listeners.ListenerUtil;
-import org.jboss.soa.esb.listeners.State;
-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.routing.MessageRouter;
-import org.jboss.soa.esb.testutils.FileUtil;
-import org.jboss.soa.esb.testutils.HsqldbUtil;
-import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
-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 ListenerManager _proc = null;
- private static String mDbDriver;
- private static String mDbUrl;
- private static String mDbUsername;
- private static String mDbPassword;
-
- @Test
- public void route() throws Exception
- {
- Message message = MessageFactory.getInstance().getMessage();
- message.getBody().setContents("Body".getBytes());
- ConfigTree config = ConfigTree.fromInputStream(getClass().getResourceAsStream("CbrProxyActionUnitTestFragment.xml"));
-
- ActionProcessingPipeline chain = null;
-
- try {
- chain = new ActionProcessingPipeline(message,config);
- }catch (IllegalArgumentException e){
- e.printStackTrace();
- fail(e.toString());
- } catch (ConfigurationException e){
- e.printStackTrace();
- fail(e.toString());
- }
- Thread t = new Thread(chain);
- t.start();
-
- // Wait for processing to complte...
- chain.waitUntilComplete();
-
- //The message coming should have the Collection of destinationServices as a property.
- Collection destinationServices = (Collection) chain.getMessage().getProperties().getProperty(MessageRouter.ROUTING_DESTINATION_SERVICE_LIST);
- assertNotNull("Destination service list is null", destinationServices);
- String firstDestination = (String) destinationServices.iterator().next();
- logger.info("Destination=" + firstDestination);
- assertEquals("test_category:JBOSS_XMLDestination",firstDestination);
- }
-
-
-
- @BeforeClass
- public static void runBeforeAllTests()
- {
- try {
- DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product","../product") + "etc/test/resources/log4j.xml");
- TestEnvironmentUtil.setESBPropertiesFileToUse("product","../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/services/registry/juddi-qatest.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(TestEnvironmentUtil.getUserDir("product","../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 = TestEnvironmentUtil.getUserDir("product","../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 = TestEnvironmentUtil.getUserDir("qa")
- + "junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml";
- _proc = ListenerUtil.launchManager(deploymentConfigFile, true);
- _proc.waitUntilReady();
-
- } catch (Throwable e) {
- e.printStackTrace();
- System.out.println("We should stop testing, since we don't have a db.");
- fail(e.toString());
- }
- }
-
- /**
- * 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);
- 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);
- }
-}
Deleted: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTest.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,57 +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.
- */
- -->
-
- <!-- for activemq use:
- jndi-context-factory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
- jndi-URL="tcp://localhost:61616" -->
-
- <!-- for mq series use:
- jndi-context-factory="com.ibm.mq.jms.context.WMQInitialContextFactory"
- jndi-URL="dev37:1414/SYSTEM.DEF.SVRCONN" -->
-
- <!-- for jbossmq use:
- jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
- jndi-URL="localhost" -->
-
-<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.CbrListener"
- ruleSet="JBossESBRules.drl"
- >
- <EPR
- protocol="jms"
- connection-factory="ConnectionFactory"
- destination-type="queue"
- destination-name="queue/A"
- jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
- jndi-URL="localhost"
- message-selector="service='ContentBasedRouting-SerializableOrXml'"
- />
-
- </ContentBasedRouter>
-
-</ContentBasedRouterTest>
Deleted: 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 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/CbrProxyActionUnitTestFragment.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,34 +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.
- */
- -->
-
-<CbrProxyActionTest>
-<action name="TestDefaultRouteAction"
- process="route"
- 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/ContentBasedRouterTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.java (rev 0)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -0,0 +1,276 @@
+/*
+ * 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.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+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.listeners.StandAloneBootStrapper;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+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.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Testing the Content Based Router.
+ *
+ * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ * @since Version 4.0
+ *
+ */
+public class ContentBasedRouterTest
+{
+ private static Logger logger = Logger.getLogger(ContentBasedRouterTest.class);
+
+ private static StandAloneBootStrapper _boot = null;
+
+ private static String mDbDriver;
+
+ private static String mDbUrl;
+
+ private static String mDbUsername;
+
+ private static String mDbPassword;
+
+ private static final String SERVICE_CATEGORY_NAME = "MessageRouting";
+
+ private static final String SERVICE_NAME = "ContentBasedRouterService";
+
+ /**
+ * Testing the Content Based Router.
+ */
+ @Test
+ public void sendMessages()
+ {
+ try
+ {
+ sendMessage("First Message");
+ // The second time the rulesEngine should be primed.
+ sendMessage("Second Message");
+ }
+ catch (RegistryException re)
+ {
+ re.printStackTrace();
+ assertTrue(false);
+ }
+ catch (CourierException ce)
+ {
+ ce.printStackTrace();
+ assertTrue(false);
+ }
+ catch (MalformedEPRException me)
+ {
+ me.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Sends a message to the CbrJmsQueueListener.
+ *
+ * @param body -
+ * a String containing the body of the message.
+ * @throws RegistryException
+ * @throws CourierException
+ * @throws MalformedEPRException
+ */
+
+ private static void sendMessage(String body) throws RegistryException, CourierException, MalformedEPRException
+ {
+ Message msg = MessageFactory.getInstance().getMessage();
+ msg.getBody().setContents(body.getBytes());
+
+ Registry registry = RegistryFactory.getRegistry();
+ Collection<EPR> eprs = registry.findEPRs(SERVICE_CATEGORY_NAME,
+ SERVICE_NAME);
+ 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);
+ courier.deliver(msg);
+ break;
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(ContentBasedRouterTest.class);
+ }
+
+ @BeforeClass
+ public static void runBeforeAllTests()
+ {
+ try
+ {
+ DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product",
+ "../product")
+ + "etc/test/resources/log4j.xml");
+ TestEnvironmentUtil.setESBPropertiesFileToUse("product",
+ "../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/services/registry/juddi-qatest.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(TestEnvironmentUtil.getUserDir(
+ "product", "../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 = TestEnvironmentUtil.getUserDir("product",
+ "../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
+ String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa")
+ + "junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml";
+ String validationFileName = TestEnvironmentUtil.getUserDir(
+ "product", "../product")
+ + "etc/schemas/xml/jbossesb-1.0.xsd";
+ // Make sure this file exists
+ File validationFile = new File(validationFileName);
+ if (!validationFile.exists())
+ {
+ System.err.println("Validation file "
+ + validationFile.getAbsolutePath() + " does not exist");
+ assertTrue(false);
+ }
+ _boot = new StandAloneBootStrapper(deploymentConfigFile,
+ validationFileName);
+
+ logger
+ .info("Testing to see if we can instantiate and start ListenerManager");
+ }
+ 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
+ {
+ // Increase Sleep for debugging
+ _boot.requestEnd();
+ // Give the esb time to finish
+ Thread.sleep(2000);
+ // Cleaning up the generated files
+ String listenerConfigFile = TestEnvironmentUtil.getUserDir("qa")
+ + "junit/src/org/jboss/soa/esb/actions/jbossesb-listener.xml";
+ File listenerFile = new File(listenerConfigFile);
+ if (listenerFile.exists())
+ listenerFile.delete();
+ String gatewayConfigFile = TestEnvironmentUtil.getUserDir("qa")
+ + "junit/src/org/jboss/soa/esb/actions/jbossesb-gateway.xml";
+ File gatewayFile = new File(gatewayConfigFile);
+ if (gatewayFile.exists())
+ gatewayFile.delete();
+
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+ {
+ HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+ }
+ }
+
+}
Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml (rev 0)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -0,0 +1,60 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.xsd"
+parameterReloadSecs="10">
+
+ <!-- for activemq use:
+ jndi-context-factory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ jndi-URL="tcp://localhost:61616" -->
+
+ <!-- for mq series use:
+ jndi-context-factory="com.ibm.mq.jms.context.WMQInitialContextFactory"
+ jndi-URL="dev37:1414/SYSTEM.DEF.SVRCONN" -->
+
+ <!-- for jbossmq use:
+ jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+ jndi-URL="localhost" -->
+
+
+ <providers>
+ <jms-provider name="localhost"
+ connection-factory="ConnectionFactory"
+ jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
+ jndi-URL="localhost" >
+
+ <jms-bus busid="QueueA">
+ <jms-message-filter
+ dest-type="QUEUE"
+ dest-name="queue/A"
+ selector="service='CBRouting-SerializableOrXml'"
+ />
+ </jms-bus>
+ </jms-provider>
+ </providers>
+ <services>
+ <service
+ category="MessageRouting"
+ name="ContentBasedRoutingService"
+ description="CBR Listener"
+ is-gateway="false">
+ <listeners>
+ <jms-listener name="XPathContentBasedRouter"
+ busidref="QueueA"
+ maxThreads="1">
+ </jms-listener>
+ </listeners>
+ <actions>
+ <action name="print-before" class="org.jboss.soa.esb.actions.SystemPrintln">
+ <property name="message" value="Hello Content Based Router" />
+ </action>
+ <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
+ <property name="ruleSet" value="JBossESBRules.drl"/>
+ <property name="ruleReload" value="true"/>
+ <property name="destinations">
+ <route-to destination-name="xml-destination-nodelivery" service-category="category01" service-name="jbossesbtest1" />
+ <route-to destination-name="serialized-destination-nodelivery" service-category="category02" service-name="jbossesbtest2" />
+ </property>
+ </action>
+ </actions>
+ </service>
+ </services>
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/actions/ContentBasedRouterTest.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.java 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,278 +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.listeners.message;
-
-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.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.MalformedEPRException;
-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.listeners.StandAloneBootStrapper;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageFactory;
-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.testutils.FileUtil;
-import org.jboss.soa.esb.testutils.HsqldbUtil;
-import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- * Testing the Content Based Router.
- *
- * @author <a href="mailto:kurt.stam at redhat.com">Kurt Stam</a>
- * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
- * @since Version 4.0
- *
- */
-public class CbrListenerTest
-{
- private static Logger logger = Logger.getLogger(CbrListenerTest.class);
-
- private static StandAloneBootStrapper _boot = null;
-
- private static String mDbDriver;
-
- private static String mDbUrl;
-
- private static String mDbUsername;
-
- private static String mDbPassword;
-
- private static final String SERVICE_CATEGORY_NAME = "MessageRouting";
-
- private static final String SERVICE_NAME = "ContentBasedRouterService";
-
- /**
- * Testing the Content Based Router.
- */
- @Test
- public void sendMessages()
- {
- try
- {
- sendMessage("First Message");
- // The second time the rulesEngine should be primed.
- sendMessage("Second Message");
- }
- catch (RegistryException re)
- {
- re.printStackTrace();
- assertTrue(false);
- }
- catch (CourierException ce)
- {
- ce.printStackTrace();
- assertTrue(false);
- }
- catch (MalformedEPRException me)
- {
- me.printStackTrace();
- assertTrue(false);
- }
- }
-
- /**
- * Sends a message to the CbrJmsQueueListener.
- *
- * @param body -
- * a String containing the body of the message.
- * @throws RegistryException
- * @throws CourierException
- * @throws MalformedEPRException
- */
-
- private static void sendMessage(String body) throws RegistryException, CourierException, MalformedEPRException
- {
- Message msg = MessageFactory.getInstance().getMessage();
- msg.getBody().setContents(body.getBytes());
- msg.getProperties().setProperty(MessageRouter.DELIVER_MESSAGES,
- Boolean.FALSE);
- Registry registry = RegistryFactory.getRegistry();
- Collection<EPR> eprs = registry.findEPRs(SERVICE_CATEGORY_NAME,
- SERVICE_NAME);
- 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);
- courier.deliver(msg);
- break;
- }
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(CbrListenerTest.class);
- }
-
- @BeforeClass
- public static void runBeforeAllTests()
- {
- try
- {
- DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product",
- "../product")
- + "etc/test/resources/log4j.xml");
- TestEnvironmentUtil.setESBPropertiesFileToUse("product",
- "../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/services/registry/juddi-qatest.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(TestEnvironmentUtil.getUserDir(
- "product", "../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 = TestEnvironmentUtil.getUserDir("product",
- "../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
- String deploymentConfigFile = TestEnvironmentUtil.getUserDir("qa")
- + "junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml";
- String validationFileName = TestEnvironmentUtil.getUserDir(
- "product", "../product")
- + "etc/schemas/xml/jbossesb-1.0.xsd";
- // Make sure this file exists
- File validationFile = new File(validationFileName);
- if (!validationFile.exists())
- {
- System.err.println("Validation file "
- + validationFile.getAbsolutePath() + " does not exist");
- assertTrue(false);
- }
- _boot = new StandAloneBootStrapper(deploymentConfigFile,
- validationFileName);
-
- logger
- .info("Testing to see if we can instantiate and start ListenerManager");
- }
- 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
- {
- // Increase Sleep for debugging
- _boot.requestEnd();
- // Give the esb time to finish
- Thread.sleep(2000);
- // Cleaning up the generated files
- String listenerConfigFile = TestEnvironmentUtil.getUserDir("qa")
- + "junit/src/org/jboss/soa/esb/listeners/message/jbossesb-listener.xml";
- File listenerFile = new File(listenerConfigFile);
- if (listenerFile.exists())
- listenerFile.delete();
- String gatewayConfigFile = TestEnvironmentUtil.getUserDir("qa")
- + "junit/src/org/jboss/soa/esb/listeners/message/jbossesb-gateway.xml";
- File gatewayFile = new File(gatewayConfigFile);
- if (gatewayFile.exists())
- gatewayFile.delete();
-
- if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
- {
- HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
- }
- }
-
-}
Deleted: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml 2007-01-25 23:59:22 UTC (rev 9029)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/message/CbrListenerTest.xml 2007-01-26 04:30:23 UTC (rev 9030)
@@ -1,37 +0,0 @@
-<?xml version = "1.0" encoding = "UTF-8"?>
-<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.xsd"
-parameterReloadSecs="10">
-
- <providers>
- <jms-provider name="localhost"
- connection-factory="ConnectionFactory"
- jndi-context-factory="org.jnp.interfaces.NamingContextFactory"
- jndi-URL="localhost" >
-
- <jms-bus busid="QueueA">
- <jms-message-filter
- dest-type="QUEUE"
- dest-name="queue/A"
- selector="service='CBRouting-SerializableOrXml'"
- />
- </jms-bus>
- </jms-provider>
- </providers>
- <services>
- <service
- category="MessageRouting"
- name="ContentBasedRoutingService"
- description="CBR Listener"
- is-gateway="false"
- service-class="org.jboss.soa.esb.listeners.message.CbrListener">
- <listeners>
- <jms-listener name="XPathContentBasedRouter"
- busidref="QueueA"
- maxThreads="1">
- <property name="ruleSet" value="JBossESBRules.drl"/>
- <property name="ruleReload" value="true"/>
- </jms-listener>
- </listeners>
- </service>
- </services>
-</jbossesb>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list