Skip to content

Commit

Permalink
Fixed: Use ‘WebAppUtil#parseWebXmlFile’ when handling “web.xml” files
Browse files Browse the repository at this point in the history
(OFBIZ-6993)
  • Loading branch information
Samuel Trégouët authored and mthl committed Dec 7, 2019
1 parent 3c9af84 commit e7bec48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
Expand All @@ -34,7 +33,6 @@

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.catalina.Context;
import org.apache.catalina.Engine;
Expand Down Expand Up @@ -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.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;

/**
Expand Down Expand Up @@ -514,7 +510,7 @@ private static StandardContext prepareContext(Host host, ContainerConfig.Configu
Tomcat.initWebappDefaults(context);

String location = getWebappRootLocation(appInfo);
boolean contextIsDistributable = isContextDistributable(configuration, location);
boolean contextIsDistributable = isContextDistributable(configuration, appInfo);

context.setParent(host);
context.setDocBase(location);
Expand Down Expand Up @@ -582,20 +578,13 @@ private static String getWebappMountPoint(ComponentConfig.WebappInfo appInfo) {
return mount;
}

private static 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public static String getControlServletPath(WebappInfo webAppInfo) throws IOExcep
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.
Expand Down

0 comments on commit e7bec48

Please sign in to comment.