You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/03/01 09:13:15 UTC

camel git commit: CAMEL-10789: Fixed indexing with simple expression when using a nested function in the index.

Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 8d356854a -> 44e2aa04f


CAMEL-10789: Fixed indexing with simple expression when using a nested function in the index.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/44e2aa04
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/44e2aa04
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/44e2aa04

Branch: refs/heads/camel-2.18.x
Commit: 44e2aa04f7417d145ee78db30f44b9bad30ecb7f
Parents: 8d35685
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 1 10:08:24 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 1 10:13:07 2017 +0100

----------------------------------------------------------------------
 .../apache/camel/language/bean/BeanExpression.java   |  9 ++++++++-
 .../org/apache/camel/language/simple/SimpleTest.java | 15 +++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/44e2aa04/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java b/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
index 031f556..eaa7607 100644
--- a/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
@@ -31,6 +31,7 @@ import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.component.bean.ConstantBeanHolder;
 import org.apache.camel.component.bean.ConstantTypeBeanHolder;
 import org.apache.camel.component.bean.RegistryBean;
+import org.apache.camel.language.simple.SimpleLanguage;
 import org.apache.camel.util.KeyValueHolder;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.OgnlHelper;
@@ -331,7 +332,13 @@ public class BeanExpression implements Expression, Predicate {
 
                 // if there was a key then we need to lookup using the key
                 if (key != null) {
-                    result = lookupResult(resultExchange, key, result, nullSafe, ognlPath, holder.getBean());
+                    // if key is a nested simple expression then re-evaluate that again
+                    if (SimpleLanguage.hasSimpleFunction(key)) {
+                        key = SimpleLanguage.expression(key).evaluate(exchange, String.class);
+                    }
+                    if (key != null) {
+                        result = lookupResult(resultExchange, key, result, nullSafe, ognlPath, holder.getBean());
+                    }
                 }
 
                 // check null safe for null results

http://git-wip-us.apache.org/repos/asf/camel/blob/44e2aa04/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 2bf3e3a..6e6985d 100644
--- a/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ b/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -1663,6 +1663,21 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression(exp, "456");
     }
 
+    public void testListIndexByNestedFunction() throws Exception {
+        List<String> alist = new ArrayList<>();
+        alist.add("1");
+        alist.add("99");
+        exchange.getIn().setHeader("ITEMS", alist);
+        exchange.getIn().setHeader("TOTAL_LOOPS", alist.size());
+
+        String exp = "${header.ITEMS[${exchangeProperty.CamelLoopIndex}]}";
+
+        exchange.setProperty(Exchange.LOOP_INDEX, 0);
+        assertExpression(exp, "1");
+        exchange.setProperty(Exchange.LOOP_INDEX, 1);
+        assertExpression(exp, "99");
+    }
+
     protected String getLanguageName() {
         return "simple";
     }