camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10700: camel-catalog validate simple should deal with property placeholders cannot be resolved and therefore opt them out.
Date Fri, 13 Jan 2017 17:02:33 GMT
Repository: camel
Updated Branches:
  refs/heads/master 4afb42f82 -> 4683a8726


CAMEL-10700: camel-catalog validate simple should deal with property placeholders cannot be
resolved and therefore opt them out.


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

Branch: refs/heads/master
Commit: 4683a87260d6c133a02bd11167d5465bfc315c94
Parents: 4afb42f
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jan 13 17:57:04 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jan 13 18:02:25 2017 +0100

----------------------------------------------------------------------
 .../apache/camel/catalog/DefaultCamelCatalog.java  | 17 ++++++++++++++---
 .../org/apache/camel/catalog/CamelCatalogTest.java | 16 ++++++++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4683a872/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index e30616f..7c5ad30 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -1820,6 +1820,12 @@ public class DefaultCamelCatalog implements CamelCatalog {
             classLoader = DefaultCamelCatalog.class.getClassLoader();
         }
 
+        // if there are {{ }}} property placeholders then we need to resolve them to something
else
+        // as the simple parse cannot resolve them before parsing as we dont run the actual
Camel application
+        // with property placeholders setup so we need to dummy this by replace the {{ }}
to something else
+        // therefore we use an more unlikely character: {{XXX}} to ~^XXX^~
+        String resolved = simple.replaceAll("\\{\\{(.+)\\}\\}", "~^$1^~");
+
         SimpleValidationResult answer = new SimpleValidationResult(simple);
 
         Object instance = null;
@@ -1835,9 +1841,9 @@ public class DefaultCamelCatalog implements CamelCatalog {
             Throwable cause = null;
             try {
                 if (predicate) {
-                    instance.getClass().getMethod("createPredicate", String.class).invoke(instance,
simple);
+                    instance.getClass().getMethod("createPredicate", String.class).invoke(instance,
resolved);
                 } else {
-                    instance.getClass().getMethod("createExpression", String.class).invoke(instance,
simple);
+                    instance.getClass().getMethod("createExpression", String.class).invoke(instance,
resolved);
                 }
             } catch (InvocationTargetException e) {
                 cause = e.getTargetException();
@@ -1846,7 +1852,12 @@ public class DefaultCamelCatalog implements CamelCatalog {
             }
 
             if (cause != null) {
-                answer.setError(cause.getMessage());
+
+                // reverse ~^XXX^~ back to {{XXX}}
+                String errMsg = cause.getMessage();
+                errMsg = errMsg.replaceAll("\\~\\^(.+)\\^\\~", "{{$1}}");
+
+                answer.setError(errMsg);
 
                 // is it simple parser exception then we can grab the index where the problem
is
                 if (cause.getClass().getName().equals("org.apache.camel.language.simple.types.SimpleIllegalSyntaxException")

http://git-wip-us.apache.org/repos/asf/camel/blob/4683a872/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 0682026..a541d24 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -822,6 +822,22 @@ public class CamelCatalogTest {
     }
 
     @Test
+    public void testSimplePredicatePlaceholder() throws Exception {
+        SimpleValidationResult result = catalog.validateSimplePredicate(null, "${body} contains
'{{danger}}'");
+        assertTrue(result.isSuccess());
+        assertEquals("${body} contains '{{danger}}'", result.getSimple());
+
+        result = catalog.validateSimplePredicate(null, "${bdy} contains '{{danger}}'");
+        assertFalse(result.isSuccess());
+        assertEquals("${bdy} contains '{{danger}}'", result.getSimple());
+        LOG.info(result.getError());
+        assertTrue(result.getError().startsWith("Unknown function: bdy at location 0"));
+        assertTrue(result.getError().contains("'{{danger}}'"));
+        assertEquals("Unknown function: bdy", result.getShortError());
+        assertEquals(0, result.getIndex());
+    }
+
+    @Test
     public void testValidateLanguage() throws Exception {
         LanguageValidationResult result = catalog.validateLanguageExpression(null, "simple",
"${body}");
         assertTrue(result.isSuccess());


Mime
View raw message