camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9119: xslt should throw exception if error/fatal parsing xslt source. Thanks to metatech for the patch.
Date Mon, 07 Sep 2015 14:22:40 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x bffedde0f -> ce7477836
  refs/heads/master a3de7e193 -> 2e2e3fe68


CAMEL-9119: xslt should throw exception if error/fatal parsing xslt source. Thanks to metatech
for the patch.


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

Branch: refs/heads/master
Commit: 2e2e3fe68e0949f9e43806212103fec3676f7636
Parents: a3de7e1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Sep 7 16:20:46 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Sep 7 16:20:46 2015 +0200

----------------------------------------------------------------------
 .../camel/builder/xml/XsltErrorListener.java    | 11 +++--
 .../xslt/XsltRouteXsltWithErrorTest.java        | 52 ++++++++++++++++++++
 .../component/xslt/transform-with-error.xsl     | 28 +++++++++++
 3 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2e2e3fe6/camel-core/src/main/java/org/apache/camel/builder/xml/XsltErrorListener.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltErrorListener.java
b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltErrorListener.java
index fadff65..30fb968 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltErrorListener.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltErrorListener.java
@@ -23,7 +23,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * {@link ErrorListener} which logs the errors.
+ * {@link ErrorListener} which logs the errors and rethrow the exceptions for error and fatal
conditions.
  */
 public class XsltErrorListener implements ErrorListener {
 
@@ -31,16 +31,19 @@ public class XsltErrorListener implements ErrorListener {
 
     @Override
     public void warning(TransformerException e) throws TransformerException {
-        LOG.warn(e.getMessageAndLocation());
+        // just log warning
+        LOG.warn("Warning parsing XSLT file: " + e.getMessageAndLocation());
     }
 
     @Override
     public void error(TransformerException e) throws TransformerException {
-        LOG.error(e.getMessageAndLocation(), e);
+        LOG.error("Error parsing XSLT file: " + e.getMessageAndLocation());
+        throw e;
     }
 
     @Override
     public void fatalError(TransformerException e) throws TransformerException {
-        LOG.error(e.getMessageAndLocation(), e);
+        LOG.error("Fatal error parsing XSLT file: " + e.getMessageAndLocation());
+        throw e;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2e2e3fe6/camel-core/src/test/java/org/apache/camel/component/xslt/XsltRouteXsltWithErrorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/xslt/XsltRouteXsltWithErrorTest.java
b/camel-core/src/test/java/org/apache/camel/component/xslt/XsltRouteXsltWithErrorTest.java
new file mode 100644
index 0000000..a3ab5d3
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/xslt/XsltRouteXsltWithErrorTest.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.xslt;
+
+import javax.xml.transform.TransformerConfigurationException;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.ObjectHelper;
+
+public class XsltRouteXsltWithErrorTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testXsltWithError() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .to("xslt:org/apache/camel/component/xslt/transform-with-error.xsl");
+            }
+        });
+        try {
+            context.start();
+            fail("Should have thrown exception");
+        } catch (FailedToCreateRouteException e) {
+            TransformerConfigurationException cause = ObjectHelper.getException(TransformerConfigurationException.class,
e);
+            assertNotNull(cause);
+            // not sure if XSLT errors may be i18n and not english always so just check for
the spelling mistake of select -> slect
+            assertTrue(cause.getMessage().contains("slect"));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/2e2e3fe6/camel-core/src/test/resources/org/apache/camel/component/xslt/transform-with-error.xsl
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/component/xslt/transform-with-error.xsl
b/camel-core/src/test/resources/org/apache/camel/component/xslt/transform-with-error.xsl
new file mode 100644
index 0000000..8cb5ced
--- /dev/null
+++ b/camel-core/src/test/resources/org/apache/camel/component/xslt/transform-with-error.xsl
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<xsl:stylesheet
+  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+  version='1.0'>
+
+  <xsl:template match="/">
+    <goodbye>
+      <xsl:value-of slect="/hello"/>
+    </goodbye>
+  </xsl:template>
+
+</xsl:stylesheet>


Mime
View raw message