knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From su...@apache.org
Subject knox git commit: KNOX-854 Consolidate DocumentBuilderFactory calls + enable SECURE_PROCESSING (Colm O hEigeartaigh via Sumit Gupta)
Date Tue, 24 Jan 2017 18:41:56 GMT
Repository: knox
Updated Branches:
  refs/heads/master 039915f6e -> ebc2ac819


KNOX-854 Consolidate DocumentBuilderFactory calls + enable SECURE_PROCESSING (Colm O hEigeartaigh
via Sumit Gupta)


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

Branch: refs/heads/master
Commit: ebc2ac8192627034b72892744b5277eaf5fc9439
Parents: 039915f
Author: Sumit Gupta <sumit@apache.org>
Authored: Tue Jan 24 13:40:11 2017 -0500
Committer: Sumit Gupta <sumit@apache.org>
Committed: Tue Jan 24 13:40:11 2017 -0500

----------------------------------------------------------------------
 .../ha/provider/impl/HaDescriptorManager.java   | 12 +++------
 .../rewrite/impl/html/HtmlFilterReaderBase.java |  4 +--
 .../rewrite/impl/xml/XmlFilterReader.java       |  4 +--
 .../impl/xml/XmlUrlRewriteRulesExporter.java    | 12 +--------
 .../gateway/deploy/DeploymentFactoryTest.java   |  3 ++-
 .../xml/XmlGatewayDescriptorExporterTest.java   | 16 ++++--------
 .../gateway/shell/hbase/table/CreateTable.java  |  8 ++----
 .../gateway/shell/hbase/table/UpdateTable.java  |  8 ++----
 .../gateway/shell/hbase/table/row/StoreRow.java |  8 ++----
 .../hbase/table/scanner/CreateScanner.java      |  8 ++----
 .../java/org/apache/hadoop/test/TestUtils.java  | 12 ---------
 .../gateway/GatewayAdminTopologyFuncTest.java   | 16 +++---------
 .../gateway/OozieServiceDefinitionTest.java     |  7 +++---
 .../deploy/DeploymentFactoryFuncTest.java       | 23 ++++++++---------
 .../apache/hadoop/gateway/util/XmlUtils.java    | 26 +++++++++++++++++---
 15 files changed, 65 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
index cbd0c78..6f7af32 100644
--- a/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
+++ b/gateway-provider-ha/src/main/java/org/apache/hadoop/gateway/ha/provider/impl/HaDescriptorManager.java
@@ -21,13 +21,12 @@ import org.apache.hadoop.gateway.ha.provider.HaDescriptor;
 import org.apache.hadoop.gateway.ha.provider.HaServiceConfig;
 import org.apache.hadoop.gateway.ha.provider.impl.i18n.HaMessages;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
@@ -46,10 +45,7 @@ public class HaDescriptorManager implements HaDescriptorConstants {
 
    public static void store(HaDescriptor descriptor, Writer writer) throws IOException {
       try {
-         DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-         DocumentBuilder builder = builderFactory.newDocumentBuilder();
-         Document document = builder.newDocument();
-         document.setXmlStandalone(true);
+         Document document = XmlUtils.createDocument();
 
          Element root = document.createElement(ROOT_ELEMENT);
          document.appendChild(root);
@@ -94,10 +90,8 @@ public class HaDescriptorManager implements HaDescriptorConstants {
 
    public static HaDescriptor load(InputStream inputStream) throws IOException {
       HaDescriptor descriptor = HaDescriptorFactory.createDescriptor();
-      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
       try {
-         DocumentBuilder builder = builderFactory.newDocumentBuilder();
-         Document document = builder.parse(inputStream);
+         Document document = XmlUtils.readXml( inputStream );
          NodeList nodeList = document.getElementsByTagName(SERVICE_ELEMENT);
          if (nodeList != null && nodeList.getLength() > 0) {
             for (int i = 0; i < nodeList.getLength(); i++) {

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
index 6839e44..1eb2c1d 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/html/HtmlFilterReaderBase.java
@@ -31,11 +31,11 @@ import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
 import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteFilterReader;
 import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteUtil;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.IOException;
 import java.io.Reader;
@@ -67,7 +67,7 @@ public abstract class HtmlFilterReaderBase extends Reader implements UrlRewriteF
 
   protected HtmlFilterReaderBase( Reader reader ) throws IOException, ParserConfigurationException
{
     this.reader = reader;
-    document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+    document = XmlUtils.createDocument( false );
     stack = new Stack<Level>();
     parser = new StreamedSource( reader );
     iterator = parser.iterator();

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
index 4b06540..e6e1797 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlFilterReader.java
@@ -29,6 +29,7 @@ import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteMessages;
 import org.apache.hadoop.gateway.filter.rewrite.i18n.UrlRewriteResources;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.i18n.resources.ResourcesFactory;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -36,7 +37,6 @@ import org.w3c.dom.Node;
 import org.w3c.dom.Text;
 
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLInputFactory;
@@ -190,7 +190,7 @@ public abstract class XmlFilterReader extends Reader {
     //System.out.println( "SD=" + event );
     String s;
 
-    document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+    document = XmlUtils.createDocument( false );
     pushLevel( null, event, document, document, config );
 
     writer.write( "<?xml" );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteRulesExporter.java
----------------------------------------------------------------------
diff --git a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteRulesExporter.java
b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteRulesExporter.java
index 6fa92d5..1cc10a3 100644
--- a/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteRulesExporter.java
+++ b/gateway-provider-rewrite/src/main/java/org/apache/hadoop/gateway/filter/rewrite/impl/xml/XmlUrlRewriteRulesExporter.java
@@ -27,15 +27,8 @@ import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.beans.BeanInfo;
 import java.beans.IntrospectionException;
 import java.beans.Introspector;
@@ -56,10 +49,7 @@ public class XmlUrlRewriteRulesExporter implements UrlRewriteRulesExporter,
XmlR
   @Override
   public void store( UrlRewriteRulesDescriptor descriptor, Writer writer ) throws IOException
{
     try {
-      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-      DocumentBuilder builder = builderFactory.newDocumentBuilder();
-      Document document = builder.newDocument();
-      document.setXmlStandalone( true );
+      Document document = XmlUtils.createDocument();
 
       Element root = document.createElement( ROOT );
       document.appendChild( root );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
index 129f0fb..76f7858 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryTest.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.gateway.config.impl.GatewayConfigImpl;
 import org.apache.hadoop.gateway.topology.Application;
 import org.apache.hadoop.gateway.topology.Service;
 import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.test.TestUtils;
 import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
 import org.junit.Test;
@@ -48,7 +49,7 @@ public class DeploymentFactoryTest {
 
     EnterpriseArchive archive = DeploymentFactory.createDeployment( config, topology );
 
-    Document xml = TestUtils.parseXml( archive.get( "/META-INF/topology.xml" ).getAsset().openStream()
);
+    Document xml = XmlUtils.readXml( archive.get( "/META-INF/topology.xml" ).getAsset().openStream()
);
     //TestUtils.dumpXml( xml );
     assertThat( xml, hasXPath( "/topology/gateway" ) );
     assertThat( xml, hasXPath( "/topology/name", equalTo( "test-topology" ) ) );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-server/src/test/java/org/apache/hadoop/gateway/descriptor/xml/XmlGatewayDescriptorExporterTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/hadoop/gateway/descriptor/xml/XmlGatewayDescriptorExporterTest.java
b/gateway-server/src/test/java/org/apache/hadoop/gateway/descriptor/xml/XmlGatewayDescriptorExporterTest.java
index 67ee91d..43b7894 100644
--- a/gateway-server/src/test/java/org/apache/hadoop/gateway/descriptor/xml/XmlGatewayDescriptorExporterTest.java
+++ b/gateway-server/src/test/java/org/apache/hadoop/gateway/descriptor/xml/XmlGatewayDescriptorExporterTest.java
@@ -19,14 +19,13 @@ package org.apache.hadoop.gateway.descriptor.xml;
 
 import org.apache.hadoop.gateway.descriptor.GatewayDescriptor;
 import org.apache.hadoop.gateway.descriptor.GatewayDescriptorFactory;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.test.Console;
 import org.junit.Test;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.CharArrayWriter;
 import java.io.IOException;
@@ -72,7 +71,8 @@ public class XmlGatewayDescriptorExporterTest {
 
     String xml = writer.toString();
 
-    Document doc = parse( xml );
+    InputSource source = new InputSource( new StringReader( xml ) );
+    Document doc = XmlUtils.readXml( source );
 
     assertThat( doc, hasXPath( "/gateway/resource[1]/pattern", is( "resource1-source" ) )
);
     //assertThat( doc, hasXPath( "/gateway/resource[1]/target", is( "resource1-target" )
) );
@@ -99,7 +99,8 @@ public class XmlGatewayDescriptorExporterTest {
     String xml = writer.toString();
     //System.out.println( xml );
 
-    Document doc = parse( xml );
+    InputSource source = new InputSource( new StringReader( xml ) );
+    Document doc = XmlUtils.readXml( source );
 
     assertThat( doc, hasXPath( "/gateway/resource/filter/param" ) );
   }
@@ -122,13 +123,6 @@ public class XmlGatewayDescriptorExporterTest {
 
   }
 
-  private Document parse( String xml ) throws IOException, SAXException, ParserConfigurationException
{
-    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-    DocumentBuilder builder = factory.newDocumentBuilder();
-    InputSource source = new InputSource( new StringReader( xml ) );
-    return builder.parse( source );
-  }
-
   private static class BrokenWriter extends Writer {
 
     @Override

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
index cb63757..d1fcc88 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/CreateTable.java
@@ -20,6 +20,7 @@ import org.apache.hadoop.gateway.shell.AbstractRequest;
 import org.apache.hadoop.gateway.shell.EmptyResponse;
 import org.apache.hadoop.gateway.shell.Hadoop;
 import org.apache.hadoop.gateway.shell.hbase.HBase;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPut;
@@ -29,8 +30,6 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -79,10 +78,7 @@ public class CreateTable {
       return new Callable<Response>() {
         @Override
         public Response call() throws Exception {
-          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-          DocumentBuilder builder = builderFactory.newDocumentBuilder();
-          Document document = builder.newDocument();
-          document.setXmlStandalone( true );
+          Document document = XmlUtils.createDocument();
 
           Element root = document.createElement( ELEMENT_TABLE_SCHEMA );
           root.setAttribute( ATTRIBUTE_NAME, tableName );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
index ea4f02e..80c7b47 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/UpdateTable.java
@@ -20,6 +20,7 @@ import org.apache.hadoop.gateway.shell.AbstractRequest;
 import org.apache.hadoop.gateway.shell.EmptyResponse;
 import org.apache.hadoop.gateway.shell.Hadoop;
 import org.apache.hadoop.gateway.shell.hbase.HBase;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -29,8 +30,6 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -73,10 +72,7 @@ public class UpdateTable {
       return new Callable<Response>() {
         @Override
         public Response call() throws Exception {
-          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-          DocumentBuilder builder = builderFactory.newDocumentBuilder();
-          Document document = builder.newDocument();
-          document.setXmlStandalone( true );
+          Document document = XmlUtils.createDocument();
 
           Element root = document.createElement( ELEMENT_TABLE_SCHEMA );
           document.appendChild( root );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
index 42a2703..c78b3c5 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/row/StoreRow.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.gateway.shell.AbstractRequest;
 import org.apache.hadoop.gateway.shell.EmptyResponse;
 import org.apache.hadoop.gateway.shell.Hadoop;
 import org.apache.hadoop.gateway.shell.hbase.HBase;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -30,8 +31,6 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -77,10 +76,7 @@ public class StoreRow {
       return new Callable<Response>() {
         @Override
         public Response call() throws Exception {
-          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-          DocumentBuilder builder = builderFactory.newDocumentBuilder();
-          Document document = builder.newDocument();
-          document.setXmlStandalone( true );
+          Document document = XmlUtils.createDocument();
 
           Element root = document.createElement( ELEMENT_CELL_SET );
           document.appendChild( root );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
index d0ff0f8..df95514 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/hbase/table/scanner/CreateScanner.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.gateway.shell.EmptyResponse;
 import org.apache.hadoop.gateway.shell.Hadoop;
 import org.apache.hadoop.gateway.shell.hbase.HBase;
 import org.apache.hadoop.gateway.shell.hbase.table.row.Column;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -32,8 +33,6 @@ import org.apache.http.entity.StringEntity;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -134,10 +133,7 @@ public class CreateScanner {
       return new Callable<Response>() {
         @Override
         public Response call() throws Exception {
-          DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-          DocumentBuilder builder = builderFactory.newDocumentBuilder();
-          Document document = builder.newDocument();
-          document.setXmlStandalone( true );
+          Document document = XmlUtils.createDocument();
 
           Element root = document.createElement( ELEMENT_SCANNER );
           if( startRow != null ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
index 87f801c..143973e 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/TestUtils.java
@@ -33,9 +33,6 @@ import java.nio.ByteBuffer;
 import java.util.Properties;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
@@ -54,8 +51,6 @@ import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.eclipse.jetty.http.HttpTester;
 import org.eclipse.jetty.servlet.ServletTester;
 import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
 public class TestUtils {
 
@@ -118,13 +113,6 @@ public class TestUtils {
     return tempDir;
   }
 
-  public static Document parseXml( InputStream stream ) throws ParserConfigurationException,
IOException, SAXException {
-    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-    DocumentBuilder builder = factory.newDocumentBuilder();
-    Document document = builder.parse( new InputSource( stream ) );
-    return document;
-  }
-
   public static void dumpXml( Document document ) throws TransformerException {
     Transformer transformer = TransformerFactory.newInstance().newTransformer();
     transformer.setOutputProperty( OutputKeys.INDENT, "yes" );

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
index ed85562..94b458e 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayAdminTopologyFuncTest.java
@@ -22,7 +22,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;
-import java.net.ServerSocket;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -31,9 +30,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 import javax.ws.rs.core.MediaType;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 
 import com.jayway.restassured.http.ContentType;
 import com.mycila.xmltool.XMLDoc;
@@ -49,6 +45,7 @@ import org.apache.hadoop.gateway.topology.Param;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.test.TestUtils;
 import org.apache.http.HttpStatus;
 import org.apache.log4j.Appender;
@@ -61,7 +58,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
 import static com.jayway.restassured.RestAssured.given;
 import static org.apache.hadoop.test.TestUtils.LOG_ENTER;
@@ -622,7 +618,8 @@ public class GatewayAdminTopologyFuncTest {
         //.log().all()
         .put(url).getBody().asString();
 
-    Document doc = parse( XML );
+    InputSource source = new InputSource( new StringReader( XML ) );
+    Document doc = XmlUtils.readXml( source );
 
     assertThat( doc, hasXPath( "/topology/gateway/provider[1]/name", containsString( "WebAppSec"
) ) );
     assertThat( doc, hasXPath( "/topology/gateway/provider[1]/param/name", containsString(
"csrf.enabled" ) ) );
@@ -828,13 +825,6 @@ public class GatewayAdminTopologyFuncTest {
     LOG_EXIT();
   }
 
-  private Document parse(String xml ) throws IOException, SAXException, ParserConfigurationException
{
-    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-    DocumentBuilder builder = factory.newDocumentBuilder();
-    InputSource source = new InputSource( new StringReader( xml ) );
-    return builder.parse( source );
-  }
-
   private static final String CLASS = GatewayAdminTopologyFuncTest.class.getCanonicalName();
 
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
index 5acd34e..6a19e82 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/OozieServiceDefinitionTest.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.gateway.filter.rewrite.api.UrlRewriteServletFilter;
 import org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteRequest;
 import org.apache.hadoop.gateway.services.GatewayServices;
 import org.apache.hadoop.gateway.services.registry.ServiceRegistry;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.mock.MockServletInputStream;
 import org.easymock.EasyMock;
@@ -91,7 +92,7 @@ public class OozieServiceDefinitionTest {
 
     InputStream stream = rewriteRequest.getInputStream();
 
-    Document document = TestUtils.parseXml( stream );
+    Document document = XmlUtils.readXml( stream );
 
     assertThat( document,
         hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",
@@ -144,7 +145,7 @@ public class OozieServiceDefinitionTest {
 
     InputStream stream = rewriteRequest.getInputStream();
 
-    Document document = TestUtils.parseXml( stream );
+    Document document = XmlUtils.readXml( stream );
 
     assertThat( document,
         hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",
@@ -198,7 +199,7 @@ public class OozieServiceDefinitionTest {
 
     InputStream stream = rewriteRequest.getInputStream();
 
-    Document document = TestUtils.parseXml( stream );
+    Document document = XmlUtils.readXml( stream );
 
     assertThat( document,
         hasXPath( "/configuration/property[name='oozie.wf.application.path']/value",

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
index 76d923f..0763ea5 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/deploy/DeploymentFactoryFuncTest.java
@@ -51,6 +51,7 @@ import org.apache.hadoop.gateway.topology.Param;
 import org.apache.hadoop.gateway.topology.Provider;
 import org.apache.hadoop.gateway.topology.Service;
 import org.apache.hadoop.gateway.topology.Topology;
+import org.apache.hadoop.gateway.util.XmlUtils;
 import org.apache.hadoop.test.TestUtils;
 import org.apache.hadoop.test.log.NoOpAppender;
 import org.apache.log4j.Appender;
@@ -130,7 +131,7 @@ public class DeploymentFactoryFuncTest {
 
     EnterpriseArchive war = DeploymentFactory.createDeployment( config, topology );
 
-    Document gateway = TestUtils.parseXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
+    Document gateway = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
     //dump( gateway );
 
     //by default the first filter will be the X-Forwarded header filter
@@ -260,7 +261,7 @@ public class DeploymentFactoryFuncTest {
 //    File dir = new File( System.getProperty( "user.dir" ) );
 //    File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war"
);
 
-    Document web = TestUtils.parseXml( war.get( "%2F/WEB-INF/web.xml" ).getAsset().openStream()
);
+    Document web = XmlUtils.readXml( war.get( "%2F/WEB-INF/web.xml" ).getAsset().openStream()
);
     //TestUtils.dumpXml( web );
     assertThat( web, hasXPath( "/web-app" ) );
     assertThat( web, hasXPath( "/web-app/servlet" ) );
@@ -272,7 +273,7 @@ public class DeploymentFactoryFuncTest {
     assertThat( web, hasXPath( "/web-app/servlet-mapping/servlet-name", equalTo( "test-cluster-knox-gateway-servlet"
) ) );
     assertThat( web, hasXPath( "/web-app/servlet-mapping/url-pattern", equalTo( "/*" ) )
);
 
-    Document gateway = TestUtils.parseXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
+    Document gateway = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
 
     assertThat( gateway, hasXPath( "/gateway/resource[1]/pattern", equalTo( "/webhdfs/v1/?**"
) ) );
     //assertThat( gateway, hasXPath( "/gateway/resource[1]/target", equalTo( "http://localhost:50070/webhdfs/v1/?{**}"
) ) );
@@ -395,7 +396,7 @@ public class DeploymentFactoryFuncTest {
 //      File dir = new File( System.getProperty( "user.dir" ) );
 //      File file = war.as( ExplodedExporter.class ).exportExploded( dir, "test-cluster.war"
);
 
-      Document web = TestUtils.parseXml(war.get("%2F/WEB-INF/web.xml").getAsset().openStream());
+      Document web = XmlUtils.readXml(war.get("%2F/WEB-INF/web.xml").getAsset().openStream());
       assertThat(web, hasXPath("/web-app/servlet/servlet-class", equalTo("org.apache.hadoop.gateway.GatewayServlet")));
       assertThat(web, hasXPath("/web-app/servlet/init-param/param-name", equalTo("gatewayDescriptorLocation")));
       assertThat(web, hasXPath("/web-app/servlet/init-param/param-value", equalTo("/WEB-INF/gateway.xml")));
@@ -463,7 +464,7 @@ public class DeploymentFactoryFuncTest {
     topology.addService( service );
 
     EnterpriseArchive war = DeploymentFactory.createDeployment( config, topology );
-    Document doc = TestUtils.parseXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
+    Document doc = XmlUtils.readXml( war.get( "%2F/WEB-INF/gateway.xml" ).getAsset().openStream()
);
 //    dump( doc );
 
     Node resourceNode, filterNode, paramNode;
@@ -540,10 +541,10 @@ public class DeploymentFactoryFuncTest {
 
     Document doc;
 
-    doc = TestUtils.parseXml( archive.get( "META-INF/topology.xml" ).getAsset().openStream()
);
+    doc = XmlUtils.readXml( archive.get( "META-INF/topology.xml" ).getAsset().openStream()
);
     assertThat( doc, notNullValue() );
 
-    doc = TestUtils.parseXml( archive.get( "%2Fminimal-test-app-path/WEB-INF/gateway.xml"
).getAsset().openStream() );
+    doc = XmlUtils.readXml( archive.get( "%2Fminimal-test-app-path/WEB-INF/gateway.xml" ).getAsset().openStream()
);
     assertThat( doc, notNullValue() );
     //dump( doc );
     assertThat( doc, hasXPath("/gateway/resource/pattern", equalTo("/**?**")));
@@ -612,28 +613,28 @@ public class DeploymentFactoryFuncTest {
 
     node = archive.get( "META-INF/topology.xml" );
     assertThat( "Find META-INF/topology.xml", node, notNullValue() );
-    doc = TestUtils.parseXml( node.getAsset().openStream() );
+    doc = XmlUtils.readXml( node.getAsset().openStream() );
     assertThat( "Parse META-INF/topology.xml", doc, notNullValue() );
 
     node = archive.get( "%2F" );
     assertThat( "Find %2F", node, notNullValue() );
     node = archive.get( "%2F/WEB-INF/gateway.xml" );
     assertThat( "Find %2F/WEB-INF/gateway.xml", node, notNullValue() );
-    doc = TestUtils.parseXml( node.getAsset().openStream() );
+    doc = XmlUtils.readXml( node.getAsset().openStream() );
     assertThat( "Parse %2F/WEB-INF/gateway.xml", doc, notNullValue() );
 
     WebArchive war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-one"
);
     assertThat( "Find %2Fminimal-test-app-path-one", war, notNullValue() );
     node = war.get( "/WEB-INF/gateway.xml" );
     assertThat( "Find %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", node, notNullValue()
);
-    doc = TestUtils.parseXml( node.getAsset().openStream() );
+    doc = XmlUtils.readXml( node.getAsset().openStream() );
     assertThat( "Parse %2Fminimal-test-app-path-one/WEB-INF/gateway.xml", doc, notNullValue()
);
 
     war = archive.getAsType( WebArchive.class, "%2Fminimal-test-app-path-two" );
     assertThat( "Find %2Fminimal-test-app-path-two", war, notNullValue() );
     node = war.get( "/WEB-INF/gateway.xml" );
     assertThat( "Find %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", node, notNullValue()
);
-    doc = TestUtils.parseXml( node.getAsset().openStream() );
+    doc = XmlUtils.readXml( node.getAsset().openStream() );
     assertThat( "Parse %2Fminimal-test-app-path-two/WEB-INF/gateway.xml", doc, notNullValue()
);
 
     LOG_EXIT();

http://git-wip-us.apache.org/repos/asf/knox/blob/ebc2ac81/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
index 1536793..44bd3b1 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/XmlUtils.java
@@ -17,10 +17,13 @@
 package org.apache.hadoop.gateway.util;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.Writer;
 
+import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -32,15 +35,27 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class XmlUtils {
 
   public static Document readXml( File file ) throws ParserConfigurationException, IOException,
SAXException {
+    return readXml( new FileInputStream( file ));
+  }
+
+  public static Document readXml( InputStream input ) throws ParserConfigurationException,
IOException, SAXException {
     DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
+    f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
     DocumentBuilder b = f.newDocumentBuilder();
-    Document d = b.parse( file );
-    return d;
+    return b.parse( input );
+  }
+  
+  public static Document readXml( InputSource source ) throws ParserConfigurationException,
IOException, SAXException {
+    DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
+    f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
+    DocumentBuilder b = f.newDocumentBuilder();
+    return b.parse( source );
   }
 
   public static void writeXml( Document document, Writer writer ) throws TransformerException
{
@@ -62,10 +77,15 @@ public class XmlUtils {
 
 
   public static Document createDocument() throws ParserConfigurationException {
+    return createDocument(true);
+  }
+  
+  public static Document createDocument(boolean standalone) throws ParserConfigurationException
{
     DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
+    f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
     DocumentBuilder b = f.newDocumentBuilder();
     Document d = b.newDocument();
-    d.setXmlStandalone( true );
+    d.setXmlStandalone( standalone );
     return d;
   }
 


Mime
View raw message