[ofbiz-framework] branch release17.12 updated: Fixed: Use ‘WebAppUtil#parseWebXmlFile’ when handling “web.xml” files (OFBIZ-6993)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch release17.12 updated: Fixed: Use ‘WebAppUtil#parseWebXmlFile’ when handling “web.xml” files (OFBIZ-6993)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release17.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/release17.12 by this push:
     new 6facc0e  Fixed: Use ‘WebAppUtil#parseWebXmlFile’ when handling “web.xml” files (OFBIZ-6993)
6facc0e is described below

commit 6facc0e73da9871b9ebbf1ef381db9662f0b2b40
Author: Samuel Trégouët <[hidden email]>
AuthorDate: Thu Nov 28 13:48:55 2019 +0100

    Fixed: Use ‘WebAppUtil#parseWebXmlFile’ when handling “web.xml” files
    (OFBIZ-6993)
   
    # Conflict handled by hand in:
    # framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
---
 .../catalina/container/CatalinaContainer.java      | 24 +++++++---------------
 .../java/org/apache/ofbiz/webapp/WebAppUtil.java   |  5 +++++
 2 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java b/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
index f601df1..d300b70 100644
--- a/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
+++ b/framework/catalina/src/main/java/org/apache/ofbiz/catalina/container/CatalinaContainer.java
@@ -20,7 +20,6 @@ package org.apache.ofbiz.catalina.container;
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -34,7 +33,6 @@ import java.util.stream.Collectors;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
@@ -70,19 +68,17 @@ import org.apache.ofbiz.base.container.ContainerConfig;
 import org.apache.ofbiz.base.container.ContainerConfig.Configuration;
 import org.apache.ofbiz.base.container.ContainerConfig.Configuration.Property;
 import org.apache.ofbiz.base.container.ContainerException;
-import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.start.Start;
 import org.apache.ofbiz.base.start.StartupCommand;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilValidate;
-import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.entity.util.EntityUtilProperties;
+import org.apache.ofbiz.webapp.WebAppUtil;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.descriptor.web.FilterDef;
 import org.apache.tomcat.util.descriptor.web.FilterMap;
 import org.apache.tomcat.util.scan.StandardJarScanner;
-import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
 /**
@@ -502,7 +498,7 @@ public class CatalinaContainer implements Container {
         Tomcat.initWebappDefaults(context);
 
         String location = getWebappRootLocation(appInfo);
-        boolean contextIsDistributable = isContextDistributable(configuration, location);
+        boolean contextIsDistributable = isContextDistributable(configuration, appInfo);
 
         context.setParent(host);
         context.setDocBase(location);
@@ -572,19 +568,13 @@ public class CatalinaContainer implements Container {
         return mount;
     }
 
-    private boolean isContextDistributable(ContainerConfig.Configuration configuration, String location) throws ContainerException {
-        String webXmlFilePath = new StringBuilder().append("file:///").append(location).append("/WEB-INF/web.xml").toString();
+    private static boolean isContextDistributable(ContainerConfig.Configuration configuration,
+            ComponentConfig.WebappInfo appInfo) throws ContainerException {
         boolean appIsDistributable = ContainerConfig.getPropertyValue(configuration, "apps-distributable", true);
         try {
-            URL webXmlUrl = FlexibleLocation.resolveLocation(webXmlFilePath);
-            File webXmlFile = new File(webXmlUrl.getFile());
-            if (webXmlFile.exists()) {
-                Document webXmlDoc = UtilXml.readXmlDocument(webXmlUrl);
-                return appIsDistributable && webXmlDoc.getElementsByTagName("distributable").getLength() > 0;
-            }
-            Debug.logInfo(webXmlFilePath + " not found.", module);
-            return appIsDistributable;
-        } catch (SAXException | ParserConfigurationException | IOException e) {
+            boolean isDistributable = WebAppUtil.isDistributable(appInfo);
+            return appIsDistributable && isDistributable;
+        } catch (SAXException | IOException e) {
             throw new ContainerException(e);
         }
     }
diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
index ccd146b..c8edb15 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java
@@ -101,6 +101,11 @@ public final class WebAppUtil {
         return servletPath;
     }
 
+    public static boolean isDistributable(WebappInfo appinfo) throws IOException, SAXException {
+        WebXml webxml = getWebXml(appinfo);
+        return webxml.isDistributable();
+    }
+
     /**
      * Returns the <code>WebappInfo</code> instance associated to the specified web site ID.
      * Throws <code>IllegalArgumentException</code> if the web site ID was not found.