camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] git commit: CAMEL-7131 Set the default feature of DocumentFactoryBuilder
Date Mon, 13 Jan 2014 13:37:11 GMT
Updated Branches:
  refs/heads/camel-2.11.x 97121cbd6 -> 2f490aa27
  refs/heads/camel-2.12.x 31687be4c -> b940d2a37


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/b940d2a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b940d2a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b940d2a3

Branch: refs/heads/camel-2.12.x
Commit: b940d2a37d2b33c0c43eae28ace47df4118aab84
Parents: 31687be
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Jan 13 21:29:22 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Jan 13 21:33:41 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/b940d2a3/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 43d39a4..ca3df7d 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
@@ -944,6 +944,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/b940d2a3/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) {


Mime
View raw message