camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7130 XsltBuilder uses the StaxSource by default
Date Wed, 22 Jan 2014 08:10:24 GMT
CAMEL-7130 XsltBuilder uses the StaxSource by default


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

Branch: refs/heads/camel-2.11.x
Commit: 363c89e0af21dca5a39115f42e55c01c8ad2979c
Parents: 9194990
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Jan 22 15:57:23 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Jan 22 16:07:43 2014 +0800

----------------------------------------------------------------------
 .../apache/camel/builder/xml/XsltBuilder.java   |  3 ---
 .../camel/component/xslt/XsltDTDTest.java       | 20 ++++++++++++++++--
 .../camel/component/xslt/SaxonXsltDTDTest.java  | 22 ++++++++++++++++++--
 3 files changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/363c89e0/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 3a7b9a4..d4291b2 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
@@ -452,9 +452,6 @@ public class XsltBuilder implements Processor {
             return (Source) body;
         }
         Source source = null;
-        if (body instanceof InputStream) {
-            return new StreamSource((InputStream)body);
-        }
         if (body != null) {
             if (isAllowStAX()) {
                 source = exchange.getContext().getTypeConverter().tryConvertTo(StAXSource.class,
exchange, body);

http://git-wip-us.apache.org/repos/asf/camel/blob/363c89e0/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
index b66d62d..db5d63c 100644
--- 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.xslt;
 
+import java.io.InputStream;
 import java.util.List;
 
 import javax.xml.transform.TransformerException;
@@ -25,15 +26,28 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.impl.DefaultExchange;
 
 
 public class XsltDTDTest extends ContextTestSupport {
+    private static final String MESSAGE = 
+        "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
     
-    public void testSendEntityMessage() throws Exception {
+    public void testSendingStringMessage() throws Exception {
+        sendEntityMessage(MESSAGE);
+    }
+    
+    public void testSendingInputStreamMessage() throws Exception {
+        InputStream is = IOConverter.toInputStream(MESSAGE, new DefaultExchange(context));
+        sendEntityMessage(is);   
+    }
+    
+    private void sendEntityMessage(Object message) throws Exception {
         
         MockEndpoint endpoint = getMockEndpoint("mock:result");
+        endpoint.reset();
         endpoint.expectedMessageCount(1);
-        String message = "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
         
         template.sendBody("direct:start1", message);
 
@@ -44,6 +58,8 @@ public class XsltDTDTest extends ContextTestSupport {
         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");

http://git-wip-us.apache.org/repos/asf/camel/blob/363c89e0/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
index 30802ff..b826608 100644
--- 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.xslt;
 
+import java.io.InputStream;
 import java.util.List;
 
 import javax.xml.transform.TransformerException;
@@ -24,18 +25,33 @@ 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.converter.IOConverter;
+import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
 
 public class SaxonXsltDTDTest extends CamelTestSupport {
     
+    private static final String MESSAGE = 
+        "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
+    
+    @Test
+    public void testSendingStringMessage() throws Exception {
+        sendEntityMessage(MESSAGE);
+    }
+    
     @Test
-    public void testSendEntityMessage() throws Exception {
+    public void testSendingInputStreamMessage() throws Exception {
+        InputStream is = IOConverter.toInputStream(MESSAGE, new DefaultExchange(context));
+        sendEntityMessage(is);   
+    }
+    
+    private void sendEntityMessage(Object message) throws Exception {
         
         MockEndpoint endpoint = getMockEndpoint("mock:result");
+        endpoint.reset();
         endpoint.expectedMessageCount(1);
-        String message = "<!DOCTYPE foo [<!ENTITY xxe SYSTEM \"file:///etc//user//test\">]><task><name>&xxe;</name></task>";
         
         template.sendBody("direct:start1", message);
 
@@ -46,6 +62,8 @@ public class SaxonXsltDTDTest extends CamelTestSupport {
         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");


Mime
View raw message