camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r647393 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/xml/ components/camel-spring/src/test/java/org/apache/camel/component/xslt/ components/camel-spring/src/test/resources/org/apache/camel/component/xslt/
Date Sat, 12 Apr 2008 08:22:25 GMT
Author: davsclaus
Date: Sat Apr 12 01:22:23 2008
New Revision: 647393

URL: http://svn.apache.org/viewvc?rev=647393&view=rev
Log:
CAMEL-457 applied patch with thanks to Torsten Mielke and added a unit test

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/InvalidXsltFileTest.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/invalid.xsl
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?rev=647393&r1=647392&r2=647393&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
Sat Apr 12 01:22:23 2008
@@ -193,9 +193,22 @@
 
     /**
      * Sets the XSLT transformer from a Source
+     *
+     * @param source  the source
+     * @throws TransformerConfigurationException is thrown if creating a XSLT transformer
failed.
      */
     public void setTransformerSource(Source source) throws TransformerConfigurationException
{
-        setTransformer(converter.getTransformerFactory().newTransformer(source));
+    	 // Check that the call to newTransformer() returns a valid transformer instance.
+    	 // In case of an xslt parse error, it will return null and we should stop the
+    	 // deployment and raise an exception as the route will not be setup properly.
+    	Transformer transformer = converter.getTransformerFactory().newTransformer(source);
+    	if (transformer != null) {
+    		setTransformer(transformer);
+    	} else {
+    		throw new TransformerConfigurationException("Error creating XSLT transformer. " +
+    				"This is most likely be caused by an XML parse error. " + 
+    				"Please verify your XSLT file configured.");
+    	} 
     }
 
     /**

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/InvalidXsltFileTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/InvalidXsltFileTest.java?rev=647393&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/InvalidXsltFileTest.java
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/component/xslt/InvalidXsltFileTest.java
Sat Apr 12 01:22:23 2008
@@ -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 org.apache.camel.CamelContext;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.TestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * Unit test for CAMEL-457
+ */
+public class InvalidXsltFileTest extends TestSupport {
+
+    public void testInvalidStylesheet() throws Exception {
+        try {
+            RouteBuilder builder = createRouteBuilder();
+            CamelContext context = new DefaultCamelContext();
+            context.addRoutes(builder);
+            context.start();
+
+            fail("Should have thrown a ResolveEndpointFailedException due XSL compilation
error");
+        } catch (ResolveEndpointFailedException e) {
+            // expected
+        }
+
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("seda:a").to("xslt:org/apache/camel/component/xslt/invalid.xsl");
+            }
+        };
+    }
+    
+}

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/invalid.xsl
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/invalid.xsl?rev=647393&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/invalid.xsl
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/xslt/invalid.xsl
Sat Apr 12 01:22:23 2008
@@ -0,0 +1,50 @@
+<?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'
+  xmlns:xs='http://www.w3.org/2001/XMLSchema'
+  version='1.0'>
+
+  <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+
+  <xsl:template match="/">
+    <transformed>
+
+      <!-- adjust-dateTime-to-timezone not known to the XSLT parser, 
+           will cause it raise an exception but no error logged by 
+           camel and deployment will proceed instead of failing.
+      -->
+      <xsl:value-of select="adjust-dateTime-to-timezone(xs:dateTime($datetimemod), xs:dayTimeDuration('-PT6H'))"
/>
+ 
+      <xsl:copy>
+        <xsl:copy-of select="attribute::*"/>
+        <xsl:apply-templates/>
+      </xsl:copy>
+    </transformed>
+  </xsl:template>
+  
+  <xsl:template match="node() | @*">
+    <xsl:copy>
+      <xsl:apply-templates select="node() | @*"/>
+    </xsl:copy>
+  </xsl:template>  
+
+</xsl:stylesheet>



Mime
View raw message