[jboss-svn-commits] JBL Code SVN: r14319 - in labs/jbossesb/trunk: product/docs/services and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 16 13:58:45 EDT 2007
Author: kurt.stam at jboss.com
Date: 2007-08-16 13:58:45 -0400 (Thu, 16 Aug 2007)
New Revision: 14319
Added:
labs/jbossesb/trunk/product/lib/ext/mvel14-1.2rc1.jar
Removed:
labs/jbossesb/trunk/product/services/jbrules/lib/ext/mvel14-1.2rc1.jar
Modified:
labs/jbossesb/trunk/
labs/jbossesb/trunk/product/docs/services/ContentBasedRouting.odt
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperUnitTest.java
Log:
JBESB-841 part 1. adding the use of MVEL for mapping between esb and drools.
Property changes on: labs/jbossesb/trunk
___________________________________________________________________
Name: svn:ignore
- .settings
.classpath
.project
bin
.packaging
build
junit
ObjectToFileWriter.tst
+ .settings
.classpath
.project
bin
.packaging
build
junit
ObjectToFileWriter.tst
null
Modified: labs/jbossesb/trunk/product/docs/services/ContentBasedRouting.odt
===================================================================
(Binary files differ)
Added: labs/jbossesb/trunk/product/lib/ext/mvel14-1.2rc1.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/mvel14-1.2rc1.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java 2007-08-16 17:46:47 UTC (rev 14318)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java 2007-08-16 17:58:45 UTC (rev 14319)
@@ -19,14 +19,15 @@
*/
package org.jboss.soa.esb.message.mapping;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.message.Body;
import org.jboss.soa.esb.message.Message;
+import org.mvel.MVEL;
/**
* Extracts objects from an ESB message and puts them into a Map, which can be used for later processsing.
@@ -62,7 +63,19 @@
if (value==null) {
logger.warn("The value of " + messageObjectPath + " is null");
} else {
- objectList.add(value);
+ if (value instanceof Collection) {
+ Collection valuesList = (Collection) value;
+ for (Object object : valuesList) {
+ objectList.add(object);
+ }
+ } else if (value instanceof Map) {
+ Map valuesMap = (Map) value;
+ for (Object object : valuesMap.entrySet()) {
+ objectList.add(object);
+ }
+ } else {
+ objectList.add(value);
+ }
}
}
}
@@ -110,7 +123,7 @@
BODY_CONTENT.equals(name)
? body.getByteArray()
: body.get(name);
- } else if ("property".equalsIgnoreCase(location)) {
+ } else if ("properties".equalsIgnoreCase(location)) {
object = message.getProperties().getProperty(name);
} else if ("attachment".equalsIgnoreCase(location)) {
if (isNumeric(name)) {
@@ -119,13 +132,19 @@
} else {
object = message.getAttachment().get(name);
}
+ } else if ("header".equalsIgnoreCase(location)) {
+ object = message.getHeader().getCall();
} else {
- logger.error(esbMessageObjectPath + " should start with either 'body', 'property', or 'attachment'");
+ logger.error(esbMessageObjectPath + " should start with one of [header,body,properties,attachment]");
return null;
}
}
- //If needed traverse the bean graph.
- if (path.length>2) object = getBean(path, object);
+ //If needed use MVEL for evaluation of the rest of the path
+ if (path.length>2) {
+ int beginIndex = esbMessageObjectPath.indexOf(".",esbMessageObjectPath.indexOf(".")+1)+1;
+ String expression = esbMessageObjectPath.substring(beginIndex);
+ object = MVEL.getProperty(expression, object);
+ }
return object;
}
/**
@@ -140,33 +159,4 @@
}
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;
- }
}
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperUnitTest.java 2007-08-16 17:46:47 UTC (rev 14318)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/mapping/MessageMapperUnitTest.java 2007-08-16 17:58:45 UTC (rev 14319)
@@ -3,11 +3,15 @@
*/
package org.jboss.soa.esb.message.mapping;
+import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import junit.framework.TestCase;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -18,13 +22,35 @@
*/
public class MessageMapperUnitTest extends TestCase {
+ public void testHeader() throws URISyntaxException {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ EPR eprTo = new FileEpr("testTo");
+ message.getHeader().getCall().setTo(eprTo);
+
+ EPR eprFrom = new FileEpr("testFrom");
+ message.getHeader().getCall().setFrom(eprFrom);
+
+ variableList.add("header.call.to");
+ variableList.add("header.call.from");
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object object1 = pojos.get(0);
+ assertTrue(object1.equals(eprTo));
+
+ Object object2 = pojos.get(1);
+ assertTrue(object2.equals(eprFrom));
+
+ }
public void testProperty () {
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");
+ variableList.add("properties.property1");
TestPojo testPojo1 = new TestPojo();
testPojo1.setCount(1);
@@ -34,7 +60,7 @@
testPojo2.setName("test2");
testPojo1.setTestPojo(testPojo2);
message.getProperties().setProperty("property2", testPojo1);
- variableList.add("property.property2.testPojo.testPojo");
+ variableList.add("properties.property2.testPojo");
List<Object> pojos=mapper.createObjectList(message, variableList);
@@ -45,6 +71,36 @@
assertTrue(testPojo2.equals(pojo2));
}
+ public void testProperty_flatten () {
+ ObjectMapper mapper = new ObjectMapper();
+ Message message = MessageFactory.getInstance().getMessage();
+ List<String> variableList = new ArrayList<String>();
+
+ Collection<TestPojo> allPojos = new ArrayList<TestPojo>();
+
+ TestPojo testPojo1 = new TestPojo();
+ testPojo1.setCount(1);
+ testPojo1.setName("test1");
+
+ TestPojo testPojo2 = new TestPojo();
+ testPojo2.setCount(1);
+ testPojo2.setName("test2");
+
+ allPojos.add(testPojo1);
+ allPojos.add(testPojo2);
+
+ message.getProperties().setProperty("allThePojos", allPojos);
+ variableList.add("properties.allThePojos");
+
+ List<Object> pojos=mapper.createObjectList(message, variableList);
+
+ Object pojo1 = pojos.get(0);
+ assertTrue(testPojo1.equals(pojo1));
+
+ Object pojo2 = pojos.get(1);
+ assertTrue(testPojo2.equals(pojo2));
+ }
+
public void testAttachment_hashmap() {
ObjectMapper mapper = new ObjectMapper();
Message message = MessageFactory.getInstance().getMessage();
@@ -61,7 +117,7 @@
testPojo2.setName("test2");
testPojo1.setTestPojo(testPojo2);
message.getAttachment().put("attachment2", testPojo1);
- variableList.add("attachment.attachment2.testPojo.testPojo");
+ variableList.add("attachment.attachment2.testPojo");
List<Object> pojos=mapper.createObjectList(message, variableList);
@@ -88,7 +144,7 @@
testPojo2.setName("test2");
testPojo1.setTestPojo(testPojo2);
message.getAttachment().addItem(testPojo1);
- variableList.add("attachment.1.testPojo.testPojo");
+ variableList.add("attachment.1.testPojo");
List<Object> pojos=mapper.createObjectList(message, variableList);
@@ -115,7 +171,7 @@
testPojo2.setName("test2");
testPojo1.setTestPojo(testPojo2);
message.getBody().add("body2", testPojo1);
- variableList.add("body.body2.testPojo.testPojo");
+ variableList.add("body.body2.testPojo");
List<Object> pojos=mapper.createObjectList(message, variableList);
@@ -125,4 +181,5 @@
Object pojo2 = pojos.get(1);
assertTrue(testPojo2.equals(pojo2));
}
+
}
Deleted: labs/jbossesb/trunk/product/services/jbrules/lib/ext/mvel14-1.2rc1.jar
===================================================================
(Binary files differ)
More information about the jboss-svn-commits
mailing list