[jboss-svn-commits] JBL Code SVN: r12110 - in labs/jbossesb/trunk/product: core/rosetta/src/org/jboss/soa/esb/message and 13 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed May 23 21:07:14 EDT 2007
Author: kurt.stam at jboss.com
Date: 2007-05-23 21:07:14 -0400 (Wed, 23 May 2007)
New Revision: 12110
Added:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/TestPojo.java
labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorRoutingUnitTest.java
labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorUnitTest.java
labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/Order.java
labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRoutingRules.drl
labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRules.drl
labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules-XPath.drl
labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules.drl
Removed:
labs/jbossesb/trunk/product/core/services/rules/
labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules-XPath.drl
labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules.drl
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedFilter.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java
labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/deployment.xml
labs/jbossesb/trunk/product/services/jbrules/
labs/jbossesb/trunk/product/services/jbrules/build.xml
labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
labs/jbossesb/trunk/product/services/jbrules/src/main/resources/META-INF/jboss-esb.xml
labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
Log:
JBESB-500, moving jbrules into it's own .esb archive
Added: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/BusinessRulesProcessor.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/BusinessRulesProcessor.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,65 @@
+/*
+ * 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 kstam at jboss.com
+ * @since Version 4.2
+ */
+package org.jboss.soa.esb.actions;
+
+import java.util.List;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+
+public class BusinessRulesProcessor extends ContentBasedRouter
+{
+ public BusinessRulesProcessor(ConfigTree config) throws ConfigurationException, RegistryException, MessageRouterException
+ {
+ super(config);
+ }
+ /**
+ * Inspect the content of the message using a rule set
+ * Router the message to one or more destinations, using the ContentBasedRouter to figure out
+ * to which destinations it is going to be routed too.
+ *
+ * @param message
+ * @return Message
+ * @throws ActionProcessingException
+ */
+ public Message process(Message message) throws ActionProcessingException
+ {
+ try {
+ List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
+ _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message, objectList);
+ } catch (MessageRouterException mre) {
+ throw new ActionProcessingException(mre.getMessage(), mre);
+ }
+ return message;
+ }
+
+
+}
Property changes on: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/BusinessRulesProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedFilter.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedFilter.java 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedFilter.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -22,8 +22,8 @@
/**
* 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
+ * @author kstam at redhat.com
+ * @since Version 4.2
*/
package org.jboss.soa.esb.actions;
@@ -33,8 +33,6 @@
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.message.Message;
import org.jboss.soa.esb.services.registry.RegistryException;
@@ -57,24 +55,26 @@
*
* @param message
* @return Message
- * @throws MalformedEPRException
- * @throws RegistryException
- * @throws CourierException
- * @throws MessageRouterException
+ * @throws ActionProcessingException
*/
- public Message process(Message message) throws MalformedEPRException, RegistryException, CourierException, MessageRouterException
+ public Message process(Message message) throws ActionProcessingException
{
- 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));
+ try {
+ List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
+ List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message, objectList);
+ 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.debug("No destinations where found, the Message is filtered");
}
- }
- if (outgoingDestinations.size()>0) {
- MessageRouter.deliverMessages(outgoingDestinations, message);
- } else if (destinations.size() > 0) {
- log.debug("No destinations where found, the Message is filter");
+ } catch (MessageRouterException mre) {
+ throw new ActionProcessingException(mre.getMessage(), mre);
}
return message;
}
Modified: 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 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/ContentBasedRouter.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -19,12 +19,6 @@
* 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;
@@ -35,75 +29,96 @@
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.message.mapping.ObjectMapper;
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
+/**
+ * @author <a href="mailto:schifest at heuristica.com.ar">schifest at heuristica.com.ar</a>
+ * @author kstam at jboss.com
+ *
+ */
+public class ContentBasedRouter extends AbstractActionPipelineProcessor
{
public static final String ROUTE_TO_TAG = "route-to";
+ public static final String OBJECT_PATH_TAG = "object-path";
+ public static final String OBJECT_PATH = "path";
public static final String DEFAULT_CBR_CLASS = "org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter";
private Logger log = Logger.getLogger(this.getClass());
public ContentBasedRouter(ConfigTree config) throws ConfigurationException, RegistryException, MessageRouterException
{
_config = config;
- checkMyParms();
- _registry = RegistryFactory.getRegistry();
+ checkMyParms();
+ _registry = RegistryFactory.getRegistry();
_cbr = ContentBasedRouterFactory.getRouter(_cbrClass);
+ _mapper = new ObjectMapper();
}
+
+ public void initialise()
+ {
+ if (_destinations.size() < 1)
+ {
+ _logger
+ .warn("Missing or empty destination list - This action class won't have any effect");
+ }
+ }
/** Router the message to one or more destinations, using the ContentBasedRouter to figure out
* to which destinations it is going to be routed too.
*
* @param message
* @return Message
- * @throws MalformedEPRException
- * @throws RegistryException
- * @throws CourierException
- * @throws MessageRouterException
+ * @throws ActionProcessingException
*/
- public Message process(Message message) throws MalformedEPRException, RegistryException, CourierException, MessageRouterException
+ public Message process(Message message) throws ActionProcessingException
{
- 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));
+ try {
+ List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
+ List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message, objectList);
+ 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.");
+
+ MessageRouter.deliverMessage(MessagePersister.SERVICE_CATEGORY
+ , MessagePersister.SERVICE_NAME
+ , message);
}
- }
- 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.");
-
- MessageRouter.deliverMessage(MessagePersister.SERVICE_CATEGORY
- , MessagePersister.SERVICE_NAME
- , message);
+ return message;
+ } catch (MessageRouterException mre) {
+ throw new ActionProcessingException(mre.getMessage(), mre);
}
- return message;
}
/**
* @deprecated no longer needed, leaving this in here for backwards compatibility,
* use the default "process".
* */
- public Message split(Message message) throws MalformedEPRException, RegistryException, CourierException, MessageRouterException
+ public Message split(Message message) throws ActionProcessingException
{
log.warn("Depricated, please use the default 'process' method in your configuration");
return process(message);
}
-
+ /**
+ * Reading the piece of configTree specific to the CBR, and setting the configuration.
+ *
+ * @throws ConfigurationException
+ */
protected void checkMyParms() throws ConfigurationException
{
if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG)==null) {
@@ -128,27 +143,35 @@
_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.getRequiredAttribute(ListenerTagNames.DESTINATION_NAME_TAG);
- String category = curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
- String name = curr.getRequiredAttribute(ListenerTagNames.SERVICE_NAME_TAG);
- _destinations.put(key, new String[] { category, name });
- }
- catch (Exception e)
- {
- throw new ConfigurationException(
- "Problems with destination list", e);
- }
+ if (destList!=null) {
+ for (ConfigTree curr : destList) {
+ try
+ {
+ String key = curr.getRequiredAttribute(ListenerTagNames.DESTINATION_NAME_TAG);
+ String category = curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
+ String name = curr.getRequiredAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ _destinations.put(key, new String[] { category, name });
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException(
+ "Problems with destination list", e);
+ }
+ }
}
+ _messagePathList = new ArrayList<String>();
+ ConfigTree[] objectList = _config.getChildren(OBJECT_PATH_TAG);
+ if (objectList!=null) {
+ for (ConfigTree curr : objectList) {
+ try {
+ String objectPath = curr.getRequiredAttribute(OBJECT_PATH);
+ _messagePathList.add(objectPath);
+ } catch (Exception e) {
+ throw new ConfigurationException(
+ "Problems with object path list", e);
+ }
+ }
+ }
}
@@ -163,6 +186,10 @@
protected String _ruleLanguage;
protected boolean _ruleReload;
+
+ protected List <String> _messagePathList;
+
+ protected ObjectMapper _mapper;
protected Registry _registry;
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007
+ */
+package org.jboss.soa.esb.message.mapping;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Extracts objects from an ESB message and puts them into a Map, which can be used for later processsing.
+ *
+ * @author kurt.stam at jboss.com
+ *
+ */
+public class ObjectMapper
+{
+ /** Name to get the byte[] content */
+ public static String BODY_CONTENT = "BODY_CONTENT";
+ private Logger logger = Logger.getLogger(this.getClass());
+ /**
+ *
+ * body.myObject will add 'myObject', while
+ * body.myObject.mySubObject will create an entry of 'mySubObject'.
+ *
+ * in the returned List.
+ *
+ * @param message - the message
+ * @param variableMap - the key represents the query to get the object from
+ * from the message.
+ *
+ * @return List of Objects.
+ */
+ public List<Object> createObjectList (Message message,List<String> messageObjectPathList)
+ {
+ List<Object> objectList = new ArrayList<Object>();
+ if (messageObjectPathList!=null) {
+ for (String messageObjectPath: messageObjectPathList)
+ {
+ Object value = getObjectFromMessage(message, messageObjectPath);
+ if (value==null) {
+ logger.warn("The value of " + messageObjectPath + " is null");
+ } else {
+ objectList.add(value);
+ }
+ }
+ }
+ return objectList;
+ }
+ /**
+ * Extracts objects from the message, using a ESB Message Object Path. The
+ * path should follow the syntax:
+ *
+ * location.objectname.<bean>...
+ *
+ * location : one of [body, property, attachment]
+ * objectname: name of the object name, attachments can be named or numbered, so for
+ * attachments this can be a number too.
+ * <bean> : optionally you traverse a bean graph by specifying bean names;
+ *
+ * examples :
+ * property.Order, gets the property object named "Order"
+ * attachment.1, gets the first attachment Object
+ * attachment.FirstAttachment, gets the attachment named 'FirstAttachment'
+ * attachment.1.Order, calls getOrder() on the attached Object.
+ * body.BODY_CONTENT, gets the byte[] of the body.
+ * body.Order1.lineitem, obtains the object named "Order1"
+ * from the body of the message. Next it will call getLineitem() on this object.
+ *
+ * More <bean> elements can be added to the query to traverse the bean graph.
+ *
+ * @param message - an ESB Message.
+ * @param esbMessageObjectPath - path to the object.
+ * @return Object obtained from the message.
+ */
+ public Object getObjectFromMessage(Message message, String esbMessageObjectPath)
+ {
+ Object object=null;
+ String[] path = esbMessageObjectPath.split("\\.");
+ if (path.length<2) {
+ logger.error(esbMessageObjectPath + " should be of type 'location.name'");
+ return null;
+ } else {
+ String location = path[0];
+ String name = path[1];
+ if ("body".equalsIgnoreCase(location)) {
+ Body body = message.getBody();
+ object =
+ BODY_CONTENT.equals(name)
+ ? body.getByteArray()
+ : body.get(name);
+ } else if ("property".equalsIgnoreCase(location)) {
+ object = message.getProperties().getProperty(name);
+ } else if ("attachment".equalsIgnoreCase(location)) {
+ if (isNumeric(name)) {
+ int index = Integer.valueOf(name);
+ object = message.getAttachment().itemAt(index);
+ } else {
+ object = message.getAttachment().get(name);
+ }
+ } else {
+ logger.error(esbMessageObjectPath + " should start with either 'body', 'property', or 'attachment'");
+ return null;
+ }
+ }
+ //If needed traverse the bean graph.
+ if (path.length>2) object = getBean(path, object);
+ return object;
+ }
+ /**
+ * Checks to see if the name is number.
+ *
+ * @param name
+ * @return
+ */
+ private boolean isNumeric(String name) {
+ for (int i=0; i<name.length(); i++) {
+ if (!Character.isDigit(name.charAt(i))) return false;
+ }
+ return true;
+ }
+ /**
+ * Constructs the getter - get<Beanname>, and invokes the method on the Object
+ * to traverse the bean path.
+ *
+ * @param objectPath - path to the bean.
+ * @param bean - bean which graph is traversed.
+ * @return - the sought-after bean.
+ */
+ private Object getBean(String[] objectPath, Object bean)
+ {
+ for (int i=2; i<objectPath.length-1;i++) {
+ String getter = "get" + objectPath[i].substring(0, 1).toUpperCase()
+ + objectPath[i].substring(1,objectPath[i].length());
+ try {
+ Method method = bean.getClass().getMethod(getter, (Class[]) null);
+ bean = method.invoke(bean, (Object[]) null);
+ } catch (NoSuchMethodException nsm) {
+ logger.error(nsm.getMessage() + " " + getter + " on " + bean);
+ return bean;
+ } catch (InvocationTargetException ite) {
+ logger.error(ite.getMessage() + " while invoking " + getter + " on " + bean);
+ return bean;
+ } catch (IllegalAccessException iae) {
+ logger.error(iae.getMessage() + " while invoking " + getter + " on " + bean);
+ return bean;
+ }
+ }
+ return bean;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperTest.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperTest.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,133 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.message.mapping;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.Test;
+
+
+/**
+ * @author kstam
+ *
+ */
+public class MessageMapperTest {
+
+ @Test
+ public void property () {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ message.getProperties().setProperty("property1", "some object");
+ variableList.add("property.property1");
+
+ TestPojo testPojo1 = new TestPojo();
+ testPojo1.setCount(1);
+ testPojo1.setName("test1");
+ TestPojo testPojo2 = new TestPojo();
+ testPojo2.setCount(1);
+ testPojo2.setName("test2");
+ testPojo1.setTestPojo(testPojo2);
+ message.getProperties().setProperty("property2", testPojo1);
+ variableList.add("property.property2.testPojo.testPojo");
+
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object pojo1 = pojos.get(0);
+ assertTrue("some object".equals(pojo1));
+
+ Object pojo2 = pojos.get(1);
+ assertTrue(testPojo2.equals(pojo2));
+ }
+
+ @Test
+ public void attachment_hashmap() {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ message.getAttachment().put("attachment1", "some object");
+ variableList.add("attachment.attachment1");
+
+ TestPojo testPojo1 = new TestPojo();
+ testPojo1.setCount(1);
+ testPojo1.setName("test1");
+ TestPojo testPojo2 = new TestPojo();
+ testPojo2.setCount(1);
+ testPojo2.setName("test2");
+ testPojo1.setTestPojo(testPojo2);
+ message.getAttachment().put("attachment2", testPojo1);
+ variableList.add("attachment.attachment2.testPojo.testPojo");
+
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object pojo1 = pojos.get(0);
+ assertTrue("some object".equals(pojo1));
+
+ Object pojo2 = pojos.get(1);
+ assertTrue(testPojo2.equals(pojo2));
+ }
+
+ @Test
+ public void attachment_list() {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ message.getAttachment().addItem("some object");
+ variableList.add("attachment.0");
+
+ TestPojo testPojo1 = new TestPojo();
+ testPojo1.setCount(1);
+ testPojo1.setName("test1");
+ TestPojo testPojo2 = new TestPojo();
+ testPojo2.setCount(1);
+ testPojo2.setName("test2");
+ testPojo1.setTestPojo(testPojo2);
+ message.getAttachment().addItem(testPojo1);
+ variableList.add("attachment.1.testPojo.testPojo");
+
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object pojo1 = pojos.get(0);
+ assertTrue("some object".equals(pojo1));
+
+ Object pojo2 = pojos.get(1);
+ assertTrue(testPojo2.equals(pojo2));
+ }
+
+ @Test
+ public void body() {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ message.getBody().add("body1", "some object");
+ variableList.add("body.body1");
+
+ TestPojo testPojo1 = new TestPojo();
+ testPojo1.setCount(1);
+ testPojo1.setName("test1");
+ TestPojo testPojo2 = new TestPojo();
+ testPojo2.setCount(1);
+ testPojo2.setName("test2");
+ testPojo1.setTestPojo(testPojo2);
+ message.getBody().add("body2", testPojo1);
+ variableList.add("body.body2.testPojo.testPojo");
+
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object pojo1 = pojos.get(0);
+ assertTrue("some object".equals(pojo1));
+
+ Object pojo2 = pojos.get(1);
+ assertTrue(testPojo2.equals(pojo2));
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/TestPojo.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/TestPojo.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/TestPojo.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.message.mapping;
+
+import java.io.Serializable;
+
+/**
+ * @author kstam
+ *
+ */
+public class TestPojo implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ String name;
+ int count;
+ TestPojo testPojo;
+
+ public int getCount() {
+ return count;
+ }
+ public void setCount(int count) {
+ this.count = count;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public TestPojo getTestPojo() {
+ return testPojo;
+ }
+ public void setTestPojo(TestPojo testPojo) {
+ this.testPojo = testPojo;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/mapping/TestPojo.java
___________________________________________________________________
Name: svn:eol-style
+ native
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-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -49,10 +49,12 @@
* the ruleSet.
* @param message -
* Message that needs routing.
+ * @param objectList - a list with additional objects (typically pulled from the message)
+ *
* @return List of routing destinations.
*/
public abstract List<String> route (String ruleSet, String ruleLanguage,
- boolean ruleReload, Message message) throws MessageRouterException;
+ boolean ruleReload, Message message, List<Object> objectList) throws MessageRouterException;
/**
* Route a message using a certain ruleSet.
@@ -64,8 +66,10 @@
* the ruleSet.
* @param message -
* Message that needs routing.
+ * @param objectList - a list with additional objects (typically pulled from the message)
+ *
* @return List of routing destinations.
*/
public abstract List<String> route (String ruleSet, boolean ruleReload,
- Message message) throws MessageRouterException;
+ Message message, List<Object> objectList) throws MessageRouterException;
}
Modified: labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/deployment.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/deployment.xml 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/samples/quickstarts/fun_cbr/deployment.xml 2007-05-24 01:07:14 UTC (rev 12110)
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jbossesb-deployment>
- <depends>jboss.esb:deployment=jbrules-cbr.esb</depends>
+ <depends>jboss.esb:deployment=jbrules.esb</depends>
</jbossesb-deployment>
Property changes on: labs/jbossesb/trunk/product/services/jbrules
___________________________________________________________________
Name: svn:ignore
+ build
Modified: labs/jbossesb/trunk/product/services/jbrules/build.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/build.xml 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/build.xml 2007-05-24 01:07:14 UTC (rev 12110)
@@ -1,4 +1,4 @@
-<project name="jbrules-cbr" default="test" basedir=".">
+<project name="jbrules" default="test" basedir=".">
<!-- Import the base Ant build script... -->
<import file="base-project-build.xml"/>
Modified: labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -82,9 +82,9 @@
* Message that needs routing.
*/
public List<String> route (String ruleSet, boolean ruleReload,
- Message message) throws MessageRouterException
+ Message message, List<Object> objectList) throws MessageRouterException
{
- return route(ruleSet, null, ruleReload, message);
+ return route(ruleSet, null, ruleReload, message, objectList);
}
/**
@@ -101,7 +101,7 @@
*/
@SuppressWarnings("unchecked")
public List<String> route (String ruleSet, String ruleLanguage,
- boolean ruleReload, Message message) throws MessageRouterException
+ boolean ruleReload, Message message, List<Object> objectList) throws MessageRouterException
{
List<String> destinations = new ArrayList();
try {
@@ -135,6 +135,11 @@
logger.log(Priority.DEBUG,
"Obtained message=" + message + " with ruleSet=" + ruleSet);
workingMemory.setGlobal("destinations", destinations);
+ if (objectList!=null) {
+ for (Object object : objectList) {
+ workingMemory.assertObject(object);
+ }
+ }
workingMemory.assertObject(message);
logger.log(Priority.DEBUG, "Fire the JBossRules Engine");
workingMemory.fireAllRules();
Deleted: labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules-XPath.drl
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules-XPath.drl 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules-XPath.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -1,47 +0,0 @@
-#created on: Nov 8, 2006
-package com.jboss.soa.esb.routing.cbr
-
-#list any import classes here.
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageType;
-
-expander XPathLanguage.dsl
-
-#declare any global variables here
-global java.util.List destinations;
-
-rule "Routing Rule using XPATH match"
-
- when
- xpathMatch "/jbossesb"
- then
- Log : "XPath Matched";
- Destination : "XML_XPath_Destination";
-end
-
-rule "Routing Rule using XPATH equals"
-
- when
- xpathEquals "/Dave", "rocks"
- then
- Log : "XPath Equals";
- Destination : "XML_XPath_Dave_Destination";
-end
-
-rule "Routing Rule using XPATH greater than"
-
- when
- xpathGreaterThan "/price" , "1.00"
- then
- Log : "XPath Greater Then";
- Destination : "XML_XPath_GreaterThan_Destination";
-end
-
-rule "Routing Rule using XPATH less than"
-
- when
- xpathLessThan "/price", "1.00"
- then
- Log : "XPath Less Then";
- Destination : "XML_XPath_LessThan_Destination";
-end
Deleted: labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules.drl
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules.drl 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -1,29 +0,0 @@
-#created on: Oct 30, 2006
-package com.jboss.soa.esb.routing.cbr
-
-#list any import classes here.
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.format.MessageType;
-
-#declare any global variables here
-global java.util.List destinations;
-
-
-rule "Routing Rule - Serialized based message"
-
- when
- Message( type == MessageType.JAVA_SERIALIZED)
- then
- System.out.println("Serialized");
- destinations.add("serialized-destination");
-
-end
-
-rule "Routing Rule - XML based message"
-
- when
- Message( type == MessageType.JBOSS_XML)
- then
- System.out.println("JBoss_XML");
- destinations.add("xml-destination");
-end
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/services/jbrules/src/main/resources/META-INF/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/main/resources/META-INF/jboss-esb.xml 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/main/resources/META-INF/jboss-esb.xml 2007-05-24 01:07:14 UTC (rev 12110)
@@ -1,47 +1,6 @@
<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
<!--
- jbossesb internal services
+ jbossesb internal rule based services
-->
-
- <providers>
- <jms-provider name="Default-JMS-Provider" connection-factory="ConnectionFactory">
- <jms-bus busid="DeadMessageQueue">
- <jms-message-filter
- dest-type="QUEUE"
- dest-name="queue/DeadMessageQueue"
- />
- </jms-bus>
- </jms-provider>
- </providers>
-
- <services>
- <service category="JBossESB-Internal"
- name="DeadLetterService"
- description="Dead Messages can be send to this service, which is configured to store and/or
- notify" >
- <listeners>
- <jms-listener name="JMS-DLQListener"
- busidref="DeadMessageQueue"
- maxThreads="1"
- />
- </listeners>
- <actions>
- <action name="PersistAction"
- class="org.jboss.soa.esb.actions.MessagePersister" >
- <property name="classfication" value="DLQ"/>
- <property name="message-store-type" value="urn:jboss/esb/persistence/type/DATABASE"/>
- </action>
- <action name="notificationAction"
- class="org.jboss.soa.esb.actions.Notifier">
- <property name="okMethod" value="notifyOK" />
- <property name="notification-details">
- <NotificationList>
- <target class="NotifyConsole" />
- </NotificationList>
- </property>
- </action>
- </actions>
- </service>
- </services>
</jbossesb>
Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorRoutingUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorRoutingUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorRoutingUnitTest.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.services.routing.cbr;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.message.mapping.ObjectMapper;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+import org.junit.Test;
+
+/**
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class BusinessProcessorRoutingUnitTest
+{
+ @Test
+ public void discount()
+ {
+ //new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ Order order = new Order();
+ order.setQuantity(20);
+ order.setUnitPrice(new BigDecimal("20.0"));
+ message.getBody().add("Order", order);
+ //extract the order from the message, so the drl can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ ObjectMapper mapper = new ObjectMapper();
+ List<Object> objectList = mapper.createObjectList(message, messagePathList);
+ //Now send to the rules engine
+ JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
+ try {
+ List<String> destinations = jbossRulesRouter.route("JBossESBPricingRoutingRules.drl", false, message, objectList);
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject"));
+ String shippingDestination = destinations.iterator().next();
+ System.out.println(shippingDestination);
+ assertEquals("express-shipping-destination", shippingDestination);
+
+ } catch (MessageRouterException mre) {
+ System.out.println("Exception was thrown.");
+ mre.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void nodiscount()
+ {
+ //new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ Order order = new Order();
+ order.setQuantity(2);
+ order.setUnitPrice(new BigDecimal("20.0"));
+ message.getBody().add("Order", order);
+// extract the order from the message, so the drl can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ ObjectMapper mapper = new ObjectMapper();
+ List<Object> objectList = mapper.createObjectList(message, messagePathList);
+ //Now send to the rules engine
+ JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
+ try {
+ List<String> destinations = jbossRulesRouter.route("JBossESBPricingRoutingRules.drl", false, message, objectList);
+ assertEquals(order.getDiscount(),0.0);
+ assertEquals("0%",message.getBody().get("DiscountObject"));
+ String shippingDestination = destinations.iterator().next();
+ System.out.println(shippingDestination);
+ assertEquals("normal-shipping-destination", shippingDestination);
+
+ } catch (MessageRouterException mre) {
+ System.out.println("Exception was thrown.");
+ mre.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(BusinessProcessorRoutingUnitTest.class);
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorRoutingUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorUnitTest.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.services.routing.cbr;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.message.mapping.ObjectMapper;
+import org.jboss.soa.esb.services.routing.MessageRouterException;
+import org.junit.Test;
+
+/**
+ *
+ * @author kurt.stam at redhat.com
+ *
+ */
+public class BusinessProcessorUnitTest
+{
+ @Test
+ public void discount()
+ {
+ //new messages
+ Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ Order order = new Order();
+ order.setQuantity(20);
+ order.setUnitPrice(new BigDecimal("20.0"));
+ message.getBody().add("Order", order);
+// extract the order from the message, so the drl can process it
+ List<String> messagePathList = new ArrayList<String>();
+ messagePathList.add("body.Order");
+ ObjectMapper mapper = new ObjectMapper();
+ List<Object> objectList = mapper.createObjectList(message, messagePathList);
+ //Now send to the rules engine
+ JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
+ try {
+ jbossRulesRouter.route("JBossESBPricingRules.drl", false, message, objectList);
+ assertEquals(order.getDiscount(),10.0);
+ assertEquals("10%",message.getBody().get("DiscountObject"));
+
+ } catch (MessageRouterException mre) {
+ System.out.println("Exception was thrown.");
+ mre.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(BusinessProcessorUnitTest.class);
+ }
+
+}
Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/BusinessProcessorUnitTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouterUnitTest.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -28,7 +28,6 @@
import junit.framework.JUnit4TestAdapter;
-import org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.message.format.MessageType;
@@ -58,8 +57,9 @@
JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
try {
- List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message, null);
assertEquals(destinationServices.iterator().next(),"serialized-destination");
+ System.out.println(message.getBody().get("test"));
} catch (MessageRouterException mre) {
System.out.println("Exception was thrown.");
mre.printStackTrace();
@@ -83,7 +83,7 @@
JBossRulesRouter jbossRulesRouter = new JBossRulesRouter();
try {
- List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message);
+ List<String> destinationServices = jbossRulesRouter.route("JBossESBRules.drl", false, message, null);
assertEquals(destinationServices.iterator().next(),"xml-destination");
} catch (MessageRouterException mre) {
System.out.println("Exception was thrown.");
Added: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/Order.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/Order.java (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/Order.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007
+ */
+package org.jboss.internal.soa.esb.services.routing.cbr;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @author kstam
+ *
+ */
+public class Order implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private int quantity;
+ private BigDecimal unitPrice;
+ private double discount;
+ private BigDecimal totalPrice;
+
+ public double getDiscount() {
+ return discount;
+ }
+ public void setDiscount(double discount) {
+ this.discount = discount;
+ }
+ public int getQuantity() {
+ return quantity;
+ }
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+ public BigDecimal getTotalPrice() {
+ return totalPrice;
+ }
+ public void setTotalPrice(BigDecimal totalPrice) {
+ this.totalPrice = totalPrice;
+ }
+ public BigDecimal getUnitPrice() {
+ return unitPrice;
+ }
+ public void setUnitPrice(BigDecimal unitPrice) {
+ this.unitPrice = unitPrice;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/internal/soa/esb/services/routing/cbr/Order.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java 2007-05-23 21:01:55 UTC (rev 12109)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/java/org/jboss/soa/esb/services/routing/cbr/ContentBasedRoutingUnitTest.java 2007-05-24 01:07:14 UTC (rev 12110)
@@ -58,7 +58,7 @@
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message,null);
assertEquals(destinationServices.iterator().next(),"serialized-destination");
} catch (MessageRouterException e) {
e.printStackTrace();
@@ -82,7 +82,7 @@
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules.drl",false,message,null);
assertEquals(destinationServices.iterator().next(),"xml-destination");
} catch (MessageRouterException e) {
e.printStackTrace();
@@ -105,7 +105,7 @@
message.getAttachment().addItem(new String("TEST ATTACHMENT2"));
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message,null);
assertEquals(destinationServices.iterator().next(),"XML_XPath_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
@@ -122,7 +122,7 @@
message.getBody().setByteArray(("<Dave>rocks</Dave>").getBytes());
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message,null);
assertEquals(destinationServices.iterator().next(),"XML_XPath_Dave_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
@@ -139,7 +139,7 @@
message.getBody().setByteArray(("<price>1.55</price>").getBytes());
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message,null);
assertEquals(destinationServices.iterator().next(),"XML_XPath_GreaterThan_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
@@ -156,7 +156,7 @@
message.getBody().setByteArray(("<price>0.55</price>").getBytes());
ContentBasedRouter cbr = ContentBasedRouterFactory.getRouter(org.jboss.soa.esb.actions.ContentBasedRouter.DEFAULT_CBR_CLASS);
- List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message);
+ List<String> destinationServices = cbr.route("JBossESBRules-XPath.drl","XPathLanguage.dsl",false,message,null);
assertEquals(destinationServices.iterator().next(),"XML_XPath_LessThan_Destination");
} catch (MessageRouterException e) {
e.printStackTrace();
Added: labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRoutingRules.drl
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRoutingRules.drl (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRoutingRules.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,41 @@
+#created on: Oct 30, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.internal.soa.esb.services.routing.cbr.Order
+
+#declare any global variables here
+global java.util.List destinations;
+
+
+rule "Pricing Rule - low quantity"
+
+ when
+ m : Message ()
+ order : Order( quantity < 10)
+ then
+ System.out.println("low volume");
+ #we can modify the object
+ order.setDiscount(0);
+ #demonstrate that we can add a new object to the message
+ m.getBody().add("DiscountObject","0%");
+ #set the routing destination
+ destinations.add("normal-shipping-destination");
+end
+
+rule "Prioing Rule - high quantity"
+
+ when
+ m : Message ()
+ order : Order( quantity >= 10)
+ then
+ System.out.println("high volume");
+ #we can modify the object
+ order.setDiscount(10);
+ #demonstrate that we can add a new object to the message
+ m.getBody().add("DiscountObject","10%");
+ #sets the routing destination
+ destinations.add("express-shipping-destination");
+end
\ No newline at end of file
Added: labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRules.drl
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRules.drl (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBPricingRules.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,37 @@
+#created on: Oct 30, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.internal.soa.esb.services.routing.cbr.Order
+
+#declare any global variables here
+global java.util.List destinations;
+
+
+rule "Pricing Rule - low quantity"
+
+ when
+ m : Message ()
+ order : Order( quantity < 10)
+ then
+ System.out.println("low volume");
+ #we can modify the object
+ order.setDiscount(0);
+ #demonstrate that we can add a new object to the message
+ m.getBody().add("DiscountObject","0%");
+end
+
+rule "Prioing Rule - high quantity"
+
+ when
+ m : Message ()
+ order : Order( quantity >= 10)
+ then
+ System.out.println("high volume");
+ #we can modify the object
+ order.setDiscount(10);
+ #demonstrate that we can add a new object to the message
+ m.getBody().add("DiscountObject","10%");
+end
\ No newline at end of file
Copied: labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules-XPath.drl (from rev 12109, labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules-XPath.drl)
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules-XPath.drl (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules-XPath.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,47 @@
+#created on: Nov 8, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+
+expander XPathLanguage.dsl
+
+#declare any global variables here
+global java.util.List destinations;
+
+rule "Routing Rule using XPATH match"
+
+ when
+ xpathMatch "/jbossesb"
+ then
+ Log : "XPath Matched";
+ Destination : "XML_XPath_Destination";
+end
+
+rule "Routing Rule using XPATH equals"
+
+ when
+ xpathEquals "/Dave", "rocks"
+ then
+ Log : "XPath Equals";
+ Destination : "XML_XPath_Dave_Destination";
+end
+
+rule "Routing Rule using XPATH greater than"
+
+ when
+ xpathGreaterThan "/price" , "1.00"
+ then
+ Log : "XPath Greater Then";
+ Destination : "XML_XPath_GreaterThan_Destination";
+end
+
+rule "Routing Rule using XPATH less than"
+
+ when
+ xpathLessThan "/price", "1.00"
+ then
+ Log : "XPath Less Then";
+ Destination : "XML_XPath_LessThan_Destination";
+end
Copied: labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules.drl (from rev 12109, labs/jbossesb/trunk/product/services/jbrules/src/main/resources/JBossESBRules.drl)
===================================================================
--- labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules.drl (rev 0)
+++ labs/jbossesb/trunk/product/services/jbrules/src/test/resources/JBossESBRules.drl 2007-05-24 01:07:14 UTC (rev 12110)
@@ -0,0 +1,29 @@
+#created on: Oct 30, 2006
+package com.jboss.soa.esb.routing.cbr
+
+#list any import classes here.
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageType;
+
+#declare any global variables here
+global java.util.List destinations;
+
+
+rule "Routing Rule - Serialized based message"
+
+ when
+ Message( type == MessageType.JAVA_SERIALIZED)
+ then
+ System.out.println("Serialized");
+ destinations.add("serialized-destination");
+
+end
+
+rule "Routing Rule - XML based message"
+
+ when
+ Message( type == MessageType.JBOSS_XML)
+ then
+ System.out.println("JBoss_XML");
+ destinations.add("xml-destination");
+end
\ No newline at end of file
More information about the jboss-svn-commits
mailing list