Skip to content

Commit 0222ce9

Browse files
committed
Added setter method setAddDefaultWebXmlToWebapp per bz 62755
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1841692 13f79535-47bb-0310-9956-ffa450edef68
1 parent fe56731 commit 0222ce9

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

java/org/apache/catalina/startup/Tomcat.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ public class Tomcat {
158158
private final Map<String, List<String>> userRoles = new HashMap<>();
159159
private final Map<String, Principal> userPrincipals = new HashMap<>();
160160

161+
private boolean addDefaultWebXmlToWebapp = true;
162+
161163
public Tomcat() {
162164
ExceptionUtils.preload();
163165
}
@@ -623,12 +625,15 @@ public Context addWebapp(Host host, String contextPath, String docBase,
623625
Context ctx = createContext(host, contextPath);
624626
ctx.setPath(contextPath);
625627
ctx.setDocBase(docBase);
626-
ctx.addLifecycleListener(getDefaultWebXmlListener());
628+
629+
if (addDefaultWebXmlToWebapp)
630+
ctx.addLifecycleListener(getDefaultWebXmlListener());
631+
627632
ctx.setConfigFile(getWebappConfigFile(docBase, contextPath));
628633

629634
ctx.addLifecycleListener(config);
630635

631-
if (config instanceof ContextConfig) {
636+
if (addDefaultWebXmlToWebapp && (config instanceof ContextConfig)) {
632637
// prevent it from looking ( if it finds one - it'll have dup error )
633638
((ContextConfig) config).setDefaultWebXml(noDefaultWebXmlPath());
634639
}
@@ -803,6 +808,24 @@ private void silence(Host host, String contextPath) {
803808
}
804809

805810

811+
/**
812+
* By default, when calling addWebapp() to create a Context, the settings from
813+
* from the default web.xml are added to the context. Calling this method with
814+
* a <code>false</code> value prior to calling addWebapp() allows to opt out of
815+
* the default settings. In that event you will need to add the configurations
816+
* yourself, either programmatically or by using web.xml deployment descriptors.
817+
* @param addDefaultWebXmlToWebapp <code>false</code> will prevent the class from
818+
* automatically adding the default settings when
819+
* calling addWebapp().
820+
* <code>true</code> will add the default settings
821+
* and is the default behavior.
822+
* @see #addWebapp(Host, String, String, LifecycleListener)
823+
*/
824+
public void setAddDefaultWebXmlToWebapp(boolean addDefaultWebXmlToWebapp){
825+
this.addDefaultWebXmlToWebapp = addDefaultWebXmlToWebapp;
826+
}
827+
828+
806829
/*
807830
* Uses essentially the same logic as {@link ContainerBase#logName()}.
808831
*/

0 commit comments

Comments
 (0)