You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/04/11 14:40:40 UTC
[2/2] git commit: CAMEL-7359 Throwing exception when bodyAs(type) has
some addition text
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/e6fbbf04
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e6fbbf04
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e6fbbf04
Branch: refs/heads/master
Commit: e6fbbf0462984f8c8c0f352e7f07fe2a7dd9a12b
Parents: 210735d
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Apr 11 20:39:53 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Apr 11 20:39:53 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/e6fbbf04/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/e6fbbf04/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 32dec6e..88c00c1 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
@@ -446,7 +446,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);
@@ -461,6 +461,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 {
@@ -486,6 +494,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 {