Repository: oozie
Updated Branches:
  refs/heads/master b197da79d -> bda196b60


OOZIE-2400 Workflow xml configuration parser cannot deal with namespace prefix 
(lars_francke via rkanter)


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

Branch: refs/heads/master
Commit: bda196b6089baaa764a0311b5f1fe6ee4621d462
Parents: b197da7
Author: Robert Kanter <[email protected]>
Authored: Thu Feb 18 17:16:46 2016 -0800
Committer: Robert Kanter <[email protected]>
Committed: Thu Feb 18 17:16:46 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/oozie/cli/OozieCLI.java     | 11 +++++---
 .../org/apache/oozie/util/XConfiguration.java   | 10 ++++----
 .../apache/oozie/util/TestXConfiguration.java   | 13 ++++++++++
 .../test/resources/test-oozie-with-prefix.xml   | 27 ++++++++++++++++++++
 release-log.txt                                 |  1 +
 .../action/hadoop/PrepareActionsDriver.java     |  5 ++++
 6 files changed, 58 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java 
b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
index 65291ff..d74457e 100644
--- a/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
+++ b/client/src/main/java/org/apache/oozie/cli/OozieCLI.java
@@ -747,6 +747,9 @@ public class OozieCLI {
     private Properties parse(InputStream is, Properties conf) throws 
IOException {
         try {
             DocumentBuilderFactory docBuilderFactory = 
DocumentBuilderFactory.newInstance();
+            docBuilderFactory.setNamespaceAware(true);
+            // support for includes in the xml file
+            docBuilderFactory.setXIncludeAware(true);
             // ignore all comments inside the xml file
             docBuilderFactory.setIgnoringComments(true);
             DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
@@ -765,7 +768,7 @@ public class OozieCLI {
     private Properties parseDocument(Document doc, Properties conf) throws 
IOException {
         try {
             Element root = doc.getDocumentElement();
-            if (!"configuration".equals(root.getTagName())) {
+            if (!"configuration".equals(root.getLocalName())) {
                 throw new RuntimeException("bad conf file: top-level element 
not <configuration>");
             }
             NodeList props = root.getChildNodes();
@@ -775,7 +778,7 @@ public class OozieCLI {
                     continue;
                 }
                 Element prop = (Element) propNode;
-                if (!"property".equals(prop.getTagName())) {
+                if (!"property".equals(prop.getLocalName())) {
                     throw new RuntimeException("bad conf file: element not 
<property>");
                 }
                 NodeList fields = prop.getChildNodes();
@@ -787,10 +790,10 @@ public class OozieCLI {
                         continue;
                     }
                     Element field = (Element) fieldNode;
-                    if ("name".equals(field.getTagName()) && 
field.hasChildNodes()) {
+                    if ("name".equals(field.getLocalName()) && 
field.hasChildNodes()) {
                         attr = ((Text) field.getFirstChild()).getData();
                     }
-                    if ("value".equals(field.getTagName()) && 
field.hasChildNodes()) {
+                    if ("value".equals(field.getLocalName()) && 
field.hasChildNodes()) {
                         value = ((Text) field.getFirstChild()).getData();
                     }
                 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/core/src/main/java/org/apache/oozie/util/XConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/util/XConfiguration.java 
b/core/src/main/java/org/apache/oozie/util/XConfiguration.java
index 6795ac2..f80d07a 100644
--- a/core/src/main/java/org/apache/oozie/util/XConfiguration.java
+++ b/core/src/main/java/org/apache/oozie/util/XConfiguration.java
@@ -296,7 +296,7 @@ public class XConfiguration extends Configuration {
     // Canibalized from Hadoop <code>Configuration.loadResource()</code>.
     private void parseDocument(Document doc) throws IOException {
         Element root = doc.getDocumentElement();
-        if (!"configuration".equals(root.getTagName())) {
+        if (!"configuration".equals(root.getLocalName())) {
             throw new IOException("bad conf file: top-level element not 
<configuration>");
         }
         processNodes(root);
@@ -312,11 +312,11 @@ public class XConfiguration extends Configuration {
                     continue;
                 }
                 Element prop = (Element) propNode;
-                if (prop.getTagName().equals("configuration")) {
+                if (prop.getLocalName().equals("configuration")) {
                     processNodes(prop);
                     continue;
                 }
-                if (!"property".equals(prop.getTagName())) {
+                if (!"property".equals(prop.getLocalName())) {
                     throw new IOException("bad conf file: element not 
<property>");
                 }
                 NodeList fields = prop.getChildNodes();
@@ -328,10 +328,10 @@ public class XConfiguration extends Configuration {
                         continue;
                     }
                     Element field = (Element) fieldNode;
-                    if ("name".equals(field.getTagName()) && 
field.hasChildNodes()) {
+                    if ("name".equals(field.getLocalName()) && 
field.hasChildNodes()) {
                         attr = ((Text) field.getFirstChild()).getData().trim();
                     }
-                    if ("value".equals(field.getTagName()) && 
field.hasChildNodes()) {
+                    if ("value".equals(field.getLocalName()) && 
field.hasChildNodes()) {
                         value = ((Text) field.getFirstChild()).getData();
                     }
                 }

http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java 
b/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
index a24fd43..bd8e077 100644
--- a/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
+++ b/core/src/test/java/org/apache/oozie/util/TestXConfiguration.java
@@ -107,6 +107,19 @@ public class TestXConfiguration extends XTestCase {
         bw.close();
     }
 
+    public void testWithNamespacePrefix() throws Exception {
+        String configPath = "test-oozie-with-prefix.xml";
+        InputStream is = null;
+        try {
+            is = IOUtils.getResourceAsStream(configPath, -1);
+            XConfiguration conf = new XConfiguration(is);
+            assertEquals("DEFAULT", conf.get("oozie.dummy"));
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+        }
+    }
 
     public void testInvalidParsing() throws Exception {
         try {

http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/core/src/test/resources/test-oozie-with-prefix.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/test-oozie-with-prefix.xml 
b/core/src/test/resources/test-oozie-with-prefix.xml
new file mode 100644
index 0000000..e2aef16
--- /dev/null
+++ b/core/src/test/resources/test-oozie-with-prefix.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+  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.
+-->
+
+
+<wf:configuration xmlns:wf="uri:oozie:workflow:0.5">
+    <wf:property>
+        <wf:name>oozie.dummy</wf:name>
+        <wf:value>DEFAULT</wf:value>
+    </wf:property>
+</wf:configuration>

http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index df8c846..e45aa73 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.3.0 release (trunk - unreleased)
 
+OOZIE-2400 Workflow xml configuration parser cannot deal with namespace prefix 
(lars_francke via rkanter)
 OOZIE-2452 Coordinator Functional Specification - EL Constants Typo 
(markgreene via puru)
 OOZIE-2173 DISCLAIMER.txt still refers to Apache Incubator (eeeva via rkanter)
 OOZIE-2312 oozie doesn't purge audit and error log (puru)

http://git-wip-us.apache.org/repos/asf/oozie/blob/bda196b6/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/PrepareActionsDriver.java
----------------------------------------------------------------------
diff --git 
a/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/PrepareActionsDriver.java
 
b/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/PrepareActionsDriver.java
index e74abee..35e8bfe 100644
--- 
a/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/PrepareActionsDriver.java
+++ 
b/sharelib/oozie/src/main/java/org/apache/oozie/action/hadoop/PrepareActionsDriver.java
@@ -98,6 +98,11 @@ public class PrepareActionsDriver {
     static Document getDocumentFromXML(String prepareXML) throws 
ParserConfigurationException, SAXException,
             IOException {
         DocumentBuilderFactory docBuilderFactory = 
DocumentBuilderFactory.newInstance();
+        docBuilderFactory.setNamespaceAware(true);
+        // support for includes in the xml file
+        docBuilderFactory.setXIncludeAware(true);
+        // ignore all comments inside the xml file
+        docBuilderFactory.setIgnoringComments(true);
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         InputStream is = new 
ByteArrayInputStream(prepareXML.getBytes("UTF-8"));
         return docBuilder.parse(is);

Reply via email to