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 14:37:12 UTC

[2/2] git commit: CAMEL-7131 Set the default feature of DocumentFactoryBuilder

CAMEL-7131 Set the default feature of DocumentFactoryBuilder

Conflicts:
	camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java


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

Branch: refs/heads/camel-2.11.x
Commit: 2f490aa27ca747afcf2c94cd763b2f039e87869d
Parents: 97121cb
Author: Willem Jiang <wi...@gmail.com>
Authored: Mon Jan 13 21:29:22 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Mon Jan 13 21:34:05 2014 +0800

----------------------------------------------------------------------
 .../camel/converter/jaxp/XmlConverter.java      |  7 +++++
 .../camel/builder/xml/XPathFeatureTest.java     | 30 ++++++++++++++------
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2f490aa2/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
index 70326f4..c822cfa 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
@@ -963,6 +963,13 @@ public class XmlConverter {
         factory.setNamespaceAware(true);
         factory.setIgnoringElementContentWhitespace(true);
         factory.setIgnoringComments(true);
+        try {
+            // Disable the external-general-entitites by default
+            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
+        } catch (ParserConfigurationException e) {
+            LOG.warn("DocumentBuilderFactory doesn't support the feature {} with value {}, due to {}."
+                     , new Object[]{"http://xml.org/sax/features/external-general-entities", true, e});
+        }
         // setup the feature from the system property
         setupFeatures(factory);
         return factory;

http://git-wip-us.apache.org/repos/asf/camel/blob/2f490aa2/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java b/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
index 2a3f947..0d90530 100644
--- a/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
+++ b/camel-core/src/test/java/org/apache/camel/builder/xml/XPathFeatureTest.java
@@ -17,7 +17,9 @@
 package org.apache.camel.builder.xml;
 
 
-import javax.xml.parsers.SAXParserFactory;
+import java.io.FileNotFoundException;
+
+import javax.xml.xpath.XPathExpressionException;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
@@ -36,16 +38,28 @@ public class XPathFeatureTest extends ContextTestSupport {
     public boolean isUseRouteBuilder() {
         return false;
     }
-
+  
     public void testXPathResult() throws Exception {
-        // Set this feature will disable the external general entities
-        System.setProperty(DOM_BUILER_FACTORY_FEATRUE + ":" 
-            + "http://xml.org/sax/features/external-general-entities", "false");
-       
         String result = (String)xpath("/").stringResult().evaluate(createExchange(XML_DATA));
         assertEquals("Get a wrong result", "  ", result);
-        System.clearProperty(DOM_BUILER_FACTORY_FEATRUE + ":" 
-            + "http://xml.org/sax/features/external-general-entities");
+    }
+    
+    public void testXPath() throws Exception {
+        
+        // Set this feature will enable the external general entities
+        System.setProperty(DOM_BUILER_FACTORY_FEATRUE + ":" 
+            + "http://xml.org/sax/features/external-general-entities", "true");
+        try {
+            xpath("/").stringResult().evaluate(createExchange(XML_DATA));
+            fail("Expect an Exception here");
+        } catch (Exception ex) {
+            assertTrue("Get a wrong exception cause.", ex instanceof InvalidXPathExpression);
+            assertTrue("Get a wrong exception cause.", ex.getCause() instanceof XPathExpressionException);
+            assertTrue("Get a wrong exception cause.", ex.getCause().getCause() instanceof FileNotFoundException);
+        } finally {
+            System.clearProperty(DOM_BUILER_FACTORY_FEATRUE + ":" 
+                + "http://xml.org/sax/features/external-general-entities");
+        }
     }
     
     protected Exchange createExchange(Object xml) {