camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-10684: camel-catalog - Simple validator should provide location index of the error
Date Mon, 09 Jan 2017 20:33:53 GMT
CAMEL-10684: camel-catalog - Simple validator should provide location index of the error


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

Branch: refs/heads/camel-2.18.x
Commit: 37c6375b7e8d1a8f8cafc9898ccf2f3787eef6ae
Parents: 28c066c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Jan 9 21:26:51 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Jan 9 21:33:22 2017 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 26 ++++++++++++++++++--
 .../camel/catalog/SimpleValidationResult.java   |  9 +++++++
 .../apache/camel/catalog/CamelCatalogTest.java  |  2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/37c6375b/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 74b4b41..688c546 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
@@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -1683,6 +1684,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
         }
 
         if (clazz != null && instance != null) {
+            Throwable cause = null;
             try {
                 if (predicate) {
                     instance.getClass().getMethod("createPredicate", String.class).invoke(instance,
simple);
@@ -1690,9 +1692,29 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     instance.getClass().getMethod("createExpression", String.class).invoke(instance,
simple);
                 }
             } catch (InvocationTargetException e) {
-                answer.setError(e.getTargetException().getMessage());
+                cause = e.getTargetException();
             } catch (Exception e) {
-                answer.setError(e.getMessage());
+                cause = e;
+            }
+
+            if (cause != null) {
+                answer.setError(cause.getMessage());
+
+                // 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")
+                    || cause.getClass().getName().equals("org.apache.camel.language.simple.types.SimpleParserException"))
{
+                    try {
+                        // we need to grab the index field from those simple parser exceptions
+                        Method method = cause.getClass().getMethod("getIndex");
+                        Object result = method.invoke(cause);
+                        if (result != null) {
+                            int index = (int) result;
+                            answer.setIndex(index);
+                        }
+                    } catch (Throwable i) {
+                        // ignore
+                    }
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/37c6375b/platforms/catalog/src/main/java/org/apache/camel/catalog/SimpleValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/SimpleValidationResult.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/SimpleValidationResult.java
index cd11ef0..87c846e 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/SimpleValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/SimpleValidationResult.java
@@ -22,6 +22,7 @@ public class SimpleValidationResult implements Serializable {
 
     private final String simple;
     private String error;
+    private int index;
 
     public SimpleValidationResult(String simple) {
         this.simple = simple;
@@ -42,4 +43,12 @@ public class SimpleValidationResult implements Serializable {
     public String getError() {
         return error;
     }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/37c6375b/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 6380941..cc6c339 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
@@ -802,6 +802,7 @@ public class CamelCatalogTest {
         assertEquals("${body", result.getSimple());
         LOG.info(result.getError());
         assertTrue(result.getError().startsWith("expected symbol functionEnd but was eol
at location 5"));
+        assertEquals(5, result.getIndex());
     }
 
     @Test
@@ -815,6 +816,7 @@ public class CamelCatalogTest {
         assertEquals("${body} > ${header.size", result.getSimple());
         LOG.info(result.getError());
         assertTrue(result.getError().startsWith("expected symbol functionEnd but was eol
at location 22"));
+        assertEquals(22, result.getIndex());
     }
 
     @Test


Mime
View raw message