camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: CAMEL-7359 Throwing exception when bodyAs(type) has some addition text
Date Fri, 11 Apr 2014 12:42:44 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 7eec1d39b -> 60d60e825
  refs/heads/camel-2.13.x 11dc3c675 -> 86be25f51


CAMEL-7359 Throwing exception when bodyAs(type) has some addition text


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

Branch: refs/heads/camel-2.13.x
Commit: 86be25f5147803469e8d8b62797d0a9c8c7d4e1e
Parents: 11dc3c6
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Apr 11 20:39:53 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Apr 11 20:42:00 2014 +0800

----------------------------------------------------------------------
 .../simple/ast/SimpleFunctionExpression.java       |  7 +++++--
 .../apache/camel/language/simple/SimpleTest.java   | 17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/86be25f5/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index d02f050..32a22b2 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -195,9 +195,11 @@ public class SimpleFunctionExpression extends LiteralExpression {
         String remainder = ifStartsWithReturnRemainder("bodyAs", function);
         if (remainder != null) {
             String type = ObjectHelper.between(remainder, "(", ")");
-            if (type == null) {
+            remainder = ObjectHelper.after(remainder, ")");
+            if (type == null || ObjectHelper.isNotEmpty(remainder)) {
                 throw new SimpleParserException("Valid syntax: ${bodyAs(type)} was: " + function,
token.getIndex());
             }
+            
             type = StringHelper.removeQuotes(type);
             return ExpressionBuilder.bodyExpression(type);
         }
@@ -205,7 +207,8 @@ public class SimpleFunctionExpression extends LiteralExpression {
         remainder = ifStartsWithReturnRemainder("mandatoryBodyAs", function);
         if (remainder != null) {
             String type = ObjectHelper.between(remainder, "(", ")");
-            if (type == null) {
+            remainder = ObjectHelper.after(remainder, ")");
+            if (type == null || ObjectHelper.isNotEmpty(remainder)) {
                 throw new SimpleParserException("Valid syntax: ${mandatoryBodyAs(type)} was:
" + function, token.getIndex());
             }
             type = StringHelper.removeQuotes(type);

http://git-wip-us.apache.org/repos/asf/camel/blob/86be25f5/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 c9e22a3..53dae26 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
@@ -440,7 +440,7 @@ public class SimpleTest extends LanguageTestSupport {
     public void testBodyAs() throws Exception {
         assertExpression("${bodyAs(String)}", "<hello id='m123'>world!</hello>");
         assertExpression("${bodyAs('String')}", "<hello id='m123'>world!</hello>");
-
+       
         exchange.getIn().setBody(null);
         assertExpression("${bodyAs('String')}", null);
 
@@ -455,6 +455,14 @@ public class SimpleTest extends LanguageTestSupport {
         } catch (CamelExecutionException e) {
             assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
         }
+        
+        exchange.getIn().setBody("hello");
+        try {
+            assertExpression("${bodyAs(String).test}", "hello.test");
+            fail("should have thrown an exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertTrue("Get a wrong message", e.getMessage().indexOf("bodyAs(String).test")
> 0);
+        }
     }
 
     public void testMandatoryBodyAs() throws Exception {
@@ -480,6 +488,13 @@ public class SimpleTest extends LanguageTestSupport {
         } catch (CamelExecutionException e) {
             assertIsInstanceOf(ClassNotFoundException.class, e.getCause());
         }
+        
+        try {
+            assertExpression("${mandatoryBodyAs(String).test}", "hello.test");
+            fail("should have thrown an exception");
+        } catch (SimpleIllegalSyntaxException e) {
+            assertTrue("Get a wrong message", e.getMessage().indexOf("mandatoryBodyAs(String).test")
> 0);
+        }
     }
 
     public void testHeaderEmptyBody() throws Exception {


Mime
View raw message