[jboss-svn-commits] JBL Code SVN: r38267 - in labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta: src/org/jboss/soa/esb/message/mapping and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jan 8 12:57:08 EST 2013
Author: tcunning
Date: 2013-01-08 12:57:07 -0500 (Tue, 08 Jan 2013)
New Revision: 38267
Modified:
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/internal/soa/esb/notification/PropertySubstituter.java
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/PropertySubstituterUnitTest.java
Log:
JBESB-3893
Allow multiple property substitutions in the same field. Fix field to allow {} property subsitution, which is used in Notifications.
Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/internal/soa/esb/notification/PropertySubstituter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/internal/soa/esb/notification/PropertySubstituter.java 2013-01-07 22:31:01 UTC (rev 38266)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/internal/soa/esb/notification/PropertySubstituter.java 2013-01-08 17:57:07 UTC (rev 38267)
@@ -56,13 +56,37 @@
ObjectMapper om = new ObjectMapper();
if (!foundReplacement) {
try {
- Object obj = om.getObjectFromMessage(message, field);
- if (obj != null) {
- if (obj instanceof String) {
- replaced = (String) obj;
- } else if (obj instanceof URI) {
- replaced = obj.toString();
+ String expression = null;
+ int curindex = -2;
+
+ if (om.foundExpression(replaced) >= 0) {
+ while (om.foundExpression(replaced) >= curindex) {
+ expression = om.parseExpression(replaced);
+ Object obj = om.getObjectFromMessage(message, expression);
+ if (obj != null) {
+ String replacement = null;
+ if (obj instanceof String) {
+ replacement = (String) obj;
+ } else if (obj instanceof URI) {
+ replacement = obj.toString();
+ }
+ replaced = replaced.replace("{" + expression + "}", replacement);
+ curindex = om.foundExpression(replaced);
+ } else {
+ curindex = replaced.length();
+ }
+
}
+ } else {
+ Object obj = om.getObjectFromMessage(message, field);
+
+ if (obj != null) {
+ if (obj instanceof String) {
+ replaced = (String) obj;
+ } else if (obj instanceof URI) {
+ replaced = obj.toString();
+ }
+ }
}
} catch (ObjectMappingException e) {
} catch (Exception e) {
Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java 2013-01-07 22:31:01 UTC (rev 38266)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/message/mapping/ObjectMapper.java 2013-01-08 17:57:07 UTC (rev 38267)
@@ -183,6 +183,36 @@
}
return message;
}
+
+ public int foundExpression(String value) {
+ int startIndex = value.indexOf('{');
+ if (startIndex == -1) {
+ return -2;
+ }
+ int endIndex = value.indexOf('}');
+ if (endIndex == -1) {
+ return -2;
+ }
+ if (startIndex >= 0 && endIndex > 0) {
+ return startIndex;
+ } else {
+ return -2;
+ }
+ }
+
+ public String parseExpression (String value) {
+ int startIndex = value.indexOf('{');
+ if (startIndex == -1) {
+ return value;
+ }
+ int endIndex = value.indexOf('}');
+ if (endIndex == -1) {
+ return value;
+ }
+ String propName = value.substring(startIndex + 1, endIndex);
+ return propName;
+ }
+
/**
* Extracts objects from the message, using a ESB Message Object Path. The
* path should follow the syntax:
@@ -213,7 +243,7 @@
*/
public Object getObjectFromMessage(Message message, String expression)
throws ObjectMappingException
- {
+ {
Object object=null;
final String[] path = getExpressionPath(expression) ;
if (path.length == 0)
@@ -265,6 +295,7 @@
public void setObjectOnMessage(Message message, String expression, Object object)
throws ObjectMappingException
{
+
String[] path = getExpressionPath(expression) ;
if(path.length == 0)
{
Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/PropertySubstituterUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/PropertySubstituterUnitTest.java 2013-01-07 22:31:01 UTC (rev 38266)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/PropertySubstituterUnitTest.java 2013-01-08 17:57:07 UTC (rev 38267)
@@ -69,6 +69,18 @@
String result = PropertySubstituter.replaceArguments("body.filename", msg);
assertEquals("Could not find the string in the body of the message at location body.filename", result, NAME_TWO);
+
+ String resultTwo = PropertySubstituter.replaceArguments("{body.filename}", msg);
+ assertEquals("Could not find the string in the body of the message at location body.filename", resultTwo, NAME_TWO);
+
+ String resultThree = PropertySubstituter.replaceArguments("{body.filename}-{body.hashtable}", msg);
+ assertEquals("Could not find the string in the body of the message at location body.filename", resultThree, NAME_TWO + "-{body.hashtable}");
+
+
+ String resultFour = PropertySubstituter.replaceArguments("{body.filename}-{header.call.MessageID}", msg);
+ assertEquals("Could not find MessageID", resultFour, NAME_TWO + "-" + MESSAGE_ID);
+
+
msg.getBody().add("hashtable", new Hashtable());
String hashResult = PropertySubstituter.replaceArguments("body.hashtable", msg);
assertEquals(hashResult, "body.hashtable");
More information about the jboss-svn-commits
mailing list