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/01/05 12:04:24 UTC

[1/4] camel git commit: CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.

Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 94b4e6fcd -> 432ff7657
  refs/heads/master 3c7439670 -> efc735119


CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.


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

Branch: refs/heads/master
Commit: b2c6fcc4ab9679f413e92ecfe6226e78f5f8b067
Parents: 3c74396
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 5 11:49:51 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 13:02:00 2017 +0100

----------------------------------------------------------------------
 .../language/simple/ast/SimpleFunctionStart.java   | 13 ++++++++++++-
 .../apache/camel/language/simple/SimpleTest.java   | 17 +++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b2c6fcc4/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
index 24ab4d8..e505548 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
@@ -35,6 +35,12 @@ public class SimpleFunctionStart extends BaseSimpleNode implements BlockStart {
         this.block = new CompositeNodes(token);
     }
 
+    public boolean lazyEval(SimpleNode child) {
+        String text = child.toString();
+        // don't lazy evaluate nested type references as they are static
+        return !text.startsWith("${type:");
+    }
+
     @Override
     public String toString() {
         // output a nice toString so it makes debugging easier as we can see the entire block
@@ -68,12 +74,17 @@ public class SimpleFunctionStart extends BaseSimpleNode implements BlockStart {
 
                 // we need to concat the block so we have the expression
                 for (SimpleNode child : block.getChildren()) {
+                    // whether a nested function should be lazy evaluated or not
+                    boolean lazy = true;
+                    if (child instanceof SimpleFunctionStart) {
+                        lazy = ((SimpleFunctionStart) child).lazyEval(child);
+                    }
                     if (child instanceof LiteralNode) {
                         String text = ((LiteralNode) child).getText();
                         sb.append(text);
                         quoteEmbeddedFunctions |= ((LiteralNode) child).quoteEmbeddedNodes();
                     // if its quoted literal then embed that as text
-                    } else if (child instanceof SingleQuoteStart || child instanceof DoubleQuoteStart) {
+                    } else if (!lazy || child instanceof SingleQuoteStart || child instanceof DoubleQuoteStart) {
                         try {
                             // pass in null when we evaluate the nested expressions
                             Expression nested = child.createExpression(null);

http://git-wip-us.apache.org/repos/asf/camel/blob/b2c6fcc4/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 357a903..4293284 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
@@ -1574,7 +1574,7 @@ public class SimpleTest extends LanguageTestSupport {
         int max = 10;
         int iterations = 30;
         int i = 0;
-        for (i = 0; i < iterations; i++) {
+/*        for (i = 0; i < iterations; i++) {
             Expression expression = SimpleLanguage.simple("${random(1,10)}", Integer.class);
             assertTrue(min <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max);
         }
@@ -1599,7 +1599,7 @@ public class SimpleTest extends LanguageTestSupport {
             fail("Should have thrown exception");
         } catch (Exception e) {
             assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: random()", e.getCause().getMessage());
-        }
+        }         */
 
         exchange.getIn().setHeader("max", 20);
         Expression expression3 = SimpleLanguage.simple("${random(10,${header.max})}", Integer.class);
@@ -1650,6 +1650,19 @@ public class SimpleTest extends LanguageTestSupport {
         assertEquals(4, animal.getFriend().getAge());
     }
 
+    public void testNestedTypeFunction() throws Exception {
+        // when using type: function we need special logic to not lazy evaluate it so its evaluated only once
+        // and won't fool Camel to think its a nested OGNL method call expression instead (CAMEL-10664)
+        exchange.setProperty(Exchange.AUTHENTICATION, 123);
+        String exp = "${exchangeProperty.${type:org.apache.camel.Exchange.AUTHENTICATION}.toString()}";
+        assertExpression(exp, "123");
+
+        exchange.getIn().setHeader("whichOne", "AUTHENTICATION");
+        exchange.setProperty(Exchange.AUTHENTICATION, 456);
+        exp = "${exchangeProperty.${type:org.apache.camel.Exchange.${header.whichOne}}.toString()}";
+        assertExpression(exp, "456");
+    }
+
     protected String getLanguageName() {
         return "simple";
     }


[2/4] camel git commit: CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.

Posted by da...@apache.org.
CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.


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

Branch: refs/heads/camel-2.18.x
Commit: 544909c854c62f84172e60ca76cadb7b54ee73f1
Parents: 94b4e6f
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 5 11:49:51 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 13:02:34 2017 +0100

----------------------------------------------------------------------
 .../language/simple/ast/SimpleFunctionStart.java   | 13 ++++++++++++-
 .../apache/camel/language/simple/SimpleTest.java   | 17 +++++++++++++++--
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/544909c8/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
index 24ab4d8..e505548 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionStart.java
@@ -35,6 +35,12 @@ public class SimpleFunctionStart extends BaseSimpleNode implements BlockStart {
         this.block = new CompositeNodes(token);
     }
 
+    public boolean lazyEval(SimpleNode child) {
+        String text = child.toString();
+        // don't lazy evaluate nested type references as they are static
+        return !text.startsWith("${type:");
+    }
+
     @Override
     public String toString() {
         // output a nice toString so it makes debugging easier as we can see the entire block
@@ -68,12 +74,17 @@ public class SimpleFunctionStart extends BaseSimpleNode implements BlockStart {
 
                 // we need to concat the block so we have the expression
                 for (SimpleNode child : block.getChildren()) {
+                    // whether a nested function should be lazy evaluated or not
+                    boolean lazy = true;
+                    if (child instanceof SimpleFunctionStart) {
+                        lazy = ((SimpleFunctionStart) child).lazyEval(child);
+                    }
                     if (child instanceof LiteralNode) {
                         String text = ((LiteralNode) child).getText();
                         sb.append(text);
                         quoteEmbeddedFunctions |= ((LiteralNode) child).quoteEmbeddedNodes();
                     // if its quoted literal then embed that as text
-                    } else if (child instanceof SingleQuoteStart || child instanceof DoubleQuoteStart) {
+                    } else if (!lazy || child instanceof SingleQuoteStart || child instanceof DoubleQuoteStart) {
                         try {
                             // pass in null when we evaluate the nested expressions
                             Expression nested = child.createExpression(null);

http://git-wip-us.apache.org/repos/asf/camel/blob/544909c8/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 357a903..4293284 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
@@ -1574,7 +1574,7 @@ public class SimpleTest extends LanguageTestSupport {
         int max = 10;
         int iterations = 30;
         int i = 0;
-        for (i = 0; i < iterations; i++) {
+/*        for (i = 0; i < iterations; i++) {
             Expression expression = SimpleLanguage.simple("${random(1,10)}", Integer.class);
             assertTrue(min <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max);
         }
@@ -1599,7 +1599,7 @@ public class SimpleTest extends LanguageTestSupport {
             fail("Should have thrown exception");
         } catch (Exception e) {
             assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: random()", e.getCause().getMessage());
-        }
+        }         */
 
         exchange.getIn().setHeader("max", 20);
         Expression expression3 = SimpleLanguage.simple("${random(10,${header.max})}", Integer.class);
@@ -1650,6 +1650,19 @@ public class SimpleTest extends LanguageTestSupport {
         assertEquals(4, animal.getFriend().getAge());
     }
 
+    public void testNestedTypeFunction() throws Exception {
+        // when using type: function we need special logic to not lazy evaluate it so its evaluated only once
+        // and won't fool Camel to think its a nested OGNL method call expression instead (CAMEL-10664)
+        exchange.setProperty(Exchange.AUTHENTICATION, 123);
+        String exp = "${exchangeProperty.${type:org.apache.camel.Exchange.AUTHENTICATION}.toString()}";
+        assertExpression(exp, "123");
+
+        exchange.getIn().setHeader("whichOne", "AUTHENTICATION");
+        exchange.setProperty(Exchange.AUTHENTICATION, 456);
+        exp = "${exchangeProperty.${type:org.apache.camel.Exchange.${header.whichOne}}.toString()}";
+        assertExpression(exp, "456");
+    }
+
     protected String getLanguageName() {
         return "simple";
     }


[4/4] camel git commit: CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.

Posted by da...@apache.org.
CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.


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

Branch: refs/heads/camel-2.18.x
Commit: 432ff7657548158b2137fc9633869d92ff86afb6
Parents: 544909c
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 5 13:03:57 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 13:04:16 2017 +0100

----------------------------------------------------------------------
 .../test/java/org/apache/camel/language/simple/SimpleTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/432ff765/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 4293284..2bf3e3a 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
@@ -1574,7 +1574,7 @@ public class SimpleTest extends LanguageTestSupport {
         int max = 10;
         int iterations = 30;
         int i = 0;
-/*        for (i = 0; i < iterations; i++) {
+        for (i = 0; i < iterations; i++) {
             Expression expression = SimpleLanguage.simple("${random(1,10)}", Integer.class);
             assertTrue(min <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max);
         }
@@ -1599,7 +1599,7 @@ public class SimpleTest extends LanguageTestSupport {
             fail("Should have thrown exception");
         } catch (Exception e) {
             assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: random()", e.getCause().getMessage());
-        }         */
+        }
 
         exchange.getIn().setHeader("max", 20);
         Expression expression3 = SimpleLanguage.simple("${random(10,${header.max})}", Integer.class);


[3/4] camel git commit: CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.

Posted by da...@apache.org.
CAMEL-10664: Simple language parser should not lazt evaluate type function which otherwise would be regarded as a nested OGNL method call chain.


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

Branch: refs/heads/master
Commit: efc735119feaae09adbbc299837286237a6a9098
Parents: b2c6fcc
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 5 13:03:57 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 13:03:57 2017 +0100

----------------------------------------------------------------------
 .../test/java/org/apache/camel/language/simple/SimpleTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/efc73511/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 4293284..2bf3e3a 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
@@ -1574,7 +1574,7 @@ public class SimpleTest extends LanguageTestSupport {
         int max = 10;
         int iterations = 30;
         int i = 0;
-/*        for (i = 0; i < iterations; i++) {
+        for (i = 0; i < iterations; i++) {
             Expression expression = SimpleLanguage.simple("${random(1,10)}", Integer.class);
             assertTrue(min <= expression.evaluate(exchange, Integer.class) && expression.evaluate(exchange, Integer.class) < max);
         }
@@ -1599,7 +1599,7 @@ public class SimpleTest extends LanguageTestSupport {
             fail("Should have thrown exception");
         } catch (Exception e) {
             assertEquals("Valid syntax: ${random(min,max)} or ${random(max)} was: random()", e.getCause().getMessage());
-        }         */
+        }
 
         exchange.getIn().setHeader("max", 20);
         Expression expression3 = SimpleLanguage.simple("${random(10,${header.max})}", Integer.class);