You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2018/10/03 15:05:07 UTC
[camel] 19/32: Fix catalog
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 693796f3041740b5daf5e84f944f3a54804596b0
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Sep 27 09:04:09 2018 +0200
Fix catalog
---
.../camel/runtimecatalog/AbstractCamelCatalog.java | 45 +++++++++++++++++++---
.../apache/camel/catalog/AbstractCamelCatalog.java | 42 ++++++++++++++++++++
2 files changed, 82 insertions(+), 5 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
index 51aad7c..8150c00 100644
--- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
+++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
@@ -34,8 +34,6 @@ import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.camel.language.simple.types.SimpleIllegalSyntaxException;
-
import static org.apache.camel.runtimecatalog.CatalogHelper.after;
import static org.apache.camel.runtimecatalog.JSonSchemaHelper.getNames;
import static org.apache.camel.runtimecatalog.JSonSchemaHelper.getPropertyDefaultValue;
@@ -1234,9 +1232,46 @@ public abstract class AbstractCamelCatalog {
if (cause != null) {
answer.setError(cause.getMessage());
- if (cause instanceof SimpleIllegalSyntaxException) {
- answer.setShortError(((SimpleIllegalSyntaxException) cause).getShortMessage());
- answer.setIndex(((SimpleIllegalSyntaxException) cause).getIndex());
+
+ // 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
+ }
+ }
+
+ // we need to grab the short message field from this simple syntax exception
+ if (cause.getClass().getName().equals("org.apache.camel.language.simple.types.SimpleIllegalSyntaxException")) {
+ try {
+ Method method = cause.getClass().getMethod("getShortMessage");
+ Object result = method.invoke(cause);
+ if (result != null) {
+ String msg = (String) result;
+ answer.setShortError(msg);
+ }
+ } catch (Throwable i) {
+ // ignore
+ }
+
+ if (answer.getShortError() == null) {
+ // fallback and try to make existing message short instead
+ String msg = answer.getError();
+ // grab everything before " at location " which would be regarded as the short message
+ int idx = msg.indexOf(" at location ");
+ if (idx > 0) {
+ msg = msg.substring(0, idx);
+ answer.setShortError(msg);
+ }
+ }
}
}
}
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
index b3f16d4..fae3af3 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
@@ -60,6 +60,7 @@ import static org.apache.camel.catalog.URISupport.isEmpty;
import static org.apache.camel.catalog.URISupport.normalizeUri;
import static org.apache.camel.catalog.URISupport.stripQuery;
+
/**
* Base class for both the runtime RuntimeCamelCatalog from camel-core and the complete CamelCatalog from camel-catalog.
*/
@@ -1231,6 +1232,47 @@ public abstract class AbstractCamelCatalog {
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
+ }
+ }
+
+ // we need to grab the short message field from this simple syntax exception
+ if (cause.getClass().getName().equals("org.apache.camel.language.simple.types.SimpleIllegalSyntaxException")) {
+ try {
+ Method method = cause.getClass().getMethod("getShortMessage");
+ Object result = method.invoke(cause);
+ if (result != null) {
+ String msg = (String) result;
+ answer.setShortError(msg);
+ }
+ } catch (Throwable i) {
+ // ignore
+ }
+
+ if (answer.getShortError() == null) {
+ // fallback and try to make existing message short instead
+ String msg = answer.getError();
+ // grab everything before " at location " which would be regarded as the short message
+ int idx = msg.indexOf(" at location ");
+ if (idx > 0) {
+ msg = msg.substring(0, idx);
+ answer.setShortError(msg);
+ }
+ }
+ }
}
}