You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/01/13 09:25:28 UTC

[2/2] git commit: CAMEL-7130 Set XsltBuilder allowStax attribute to be true by default

CAMEL-7130  Set XsltBuilder allowStax attribute to be true by default


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

Branch: refs/heads/camel-2.11.x
Commit: 97121cbd6d71d16c66090ae268b741e4789b5568
Parents: 2ec54fa
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Jan 13 16:18:49 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Jan 13 16:25:01 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/builder/xml/XsltBuilder.java   |  2 +-
 .../camel/component/xslt/XsltDTDTest.java       | 78 +++++++++++++++++++
 .../camel/component/xslt/transform_dtd.xsl      | 30 ++++++++
 .../camel/component/xslt/SaxonXsltDTDTest.java  | 80 ++++++++++++++++++++
 .../camel/component/xslt/transform_dtd.xsl      | 30 ++++++++
 5 files changed, 219 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/97121cbd/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
index 8984828..3a7b9a4 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
@@ -79,7 +79,7 @@ public class XsltBuilder implements Processor {
     private URIResolver uriResolver;
     private boolean deleteOutputFile;
     private ErrorListener errorListener = new XsltErrorListener();
-    private boolean allowStAX;
+    private boolean allowStAX = true;
 
     public XsltBuilder() {
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/97121cbd/camel-core/src/test/java/org/apache/camel/component/xslt/XsltDTDTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/xslt/XsltDTDTest.java b/camel-core/src/test/java/org/apache/camel/component/xslt/XsltDTDTest.java
new file mode 100644
index 0000000..b66d62d
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/xslt/XsltDTDTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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 java.util.List;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+
+public class XsltDTDTest extends ContextTestSupport {
+    
+    public void testSendEntityMessage() throws Exception {
+        
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+        endpoint.expectedMessageCount(1);
+        String message = "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
+        
+        template.sendBody("direct:start1", message);
+
+        assertMockEndpointsSatisfied();
+        
+        List<Exchange> list = endpoint.getReceivedExchanges();
+        Exchange exchange = list.get(0);
+        String xml = exchange.getIn().getBody(String.class);
+        assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
+        
+        try {
+            template.sendBody("direct:start2", message);
+            fail("Expect an exception here");
+        } catch (Exception ex) {
+            // expect an exception here
+            assertTrue("Get a wrong exception", ex instanceof CamelExecutionException);
+            // the file could not be found
+            assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException);
+        }
+        
+    }
+    
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
+                from("direct:start1")
+                    .to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl")
+                    .to("mock:result");
+                
+                from("direct:start2")
+                    .to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl?allowStAX=false")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/97121cbd/camel-core/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
----------------------------------------------------------------------
diff --git a/camel-core/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl b/camel-core/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
new file mode 100644
index 0000000..1ad29bd
--- /dev/null
+++ b/camel-core/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
@@ -0,0 +1,30 @@
+<?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:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+  <xsl:template match="/">
+    <transformed subject="{/task/name}">
+      <cheese/>
+    </transformed>
+  </xsl:template>
+
+</xsl:stylesheet>

http://git-wip-us.apache.org/repos/asf/camel/blob/97121cbd/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltDTDTest.java
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltDTDTest.java b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltDTDTest.java
new file mode 100644
index 0000000..30802ff
--- /dev/null
+++ b/components/camel-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltDTDTest.java
@@ -0,0 +1,80 @@
+/**
+ * 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 java.util.List;
+
+import javax.xml.transform.TransformerException;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+
+public class SaxonXsltDTDTest extends CamelTestSupport {
+    
+    @Test
+    public void testSendEntityMessage() throws Exception {
+        
+        MockEndpoint endpoint = getMockEndpoint("mock:result");
+        endpoint.expectedMessageCount(1);
+        String message = "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
+        
+        template.sendBody("direct:start1", message);
+
+        assertMockEndpointsSatisfied();
+        
+        List<Exchange> list = endpoint.getReceivedExchanges();
+        Exchange exchange = list.get(0);
+        String xml = exchange.getIn().getBody(String.class);
+        assertTrue("Get a wrong transformed message", xml.indexOf("<transformed subject=\"\">") > 0);
+        
+        try {
+            template.sendBody("direct:start2", message);
+            fail("Expect an exception here");
+        } catch (Exception ex) {
+            // expect an exception here
+            assertTrue("Get a wrong exception", ex instanceof CamelExecutionException);
+            // the file could not be found
+            assertTrue("Get a wrong exception cause", ex.getCause() instanceof TransformerException);
+        }
+        
+    }
+    
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
+                from("direct:start1")
+                    .to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl")
+                    .to("mock:result");
+                
+                from("direct:start2")
+                    .to("xslt:org/apache/camel/component/xslt/transform_dtd.xsl?allowStAX=false")
+                    .to("mock:result");
+            }
+        };
+    }
+
+    
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/97121cbd/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
----------------------------------------------------------------------
diff --git a/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
new file mode 100644
index 0000000..1ad29bd
--- /dev/null
+++ b/components/camel-saxon/src/test/resources/org/apache/camel/component/xslt/transform_dtd.xsl
@@ -0,0 +1,30 @@
+<?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:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+  <xsl:template match="/">
+    <transformed subject="{/task/name}">
+      <cheese/>
+    </transformed>
+  </xsl:template>
+
+</xsl:stylesheet>