You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2017/07/04 19:14:09 UTC
svn commit: r1800807 - in /tomcat/trunk: conf/
java/org/apache/catalina/startup/ webapps/docs/ webapps/docs/config/
Author: markt
Date: Tue Jul 4 19:14:08 2017
New Revision: 1800807
URL: http://svn.apache.org/viewvc?rev=1800807&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=52924
Add support for a Tomcat specific deployment descriptor. This allows apps to ship with Tomcat specific configuration (e.g for JSP or Default Servlet) without breaking when the app is deployed on other containers.
Modified:
tomcat/trunk/conf/context.xml
tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/context.xml
tomcat/trunk/webapps/docs/default-servlet.xml
tomcat/trunk/webapps/docs/jasper-howto.xml
tomcat/trunk/webapps/docs/security-howto.xml
Modified: tomcat/trunk/conf/context.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/conf/context.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/conf/context.xml (original)
+++ tomcat/trunk/conf/context.xml Tue Jul 4 19:14:08 2017
@@ -21,6 +21,7 @@
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
+ <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Tue Jul 4 19:14:08 2017
@@ -1107,6 +1107,9 @@ public class ContextConfig implements Li
Set<WebXml> defaults = new HashSet<>();
defaults.add(getDefaultWebXmlFragment(webXmlParser));
+ Set<WebXml> tomcatWebXml = new HashSet<>();
+ tomcatWebXml.add(getTomcatWebXmlFragment(webXmlParser));
+
WebXml webXml = createWebXml();
// Parse context level web.xml
@@ -1175,7 +1178,11 @@ public class ContextConfig implements Li
ok = webXml.merge(orderedFragments);
}
- // Step 7. Apply global defaults
+ // Step 7a
+ // merge tomcat-web.xml
+ webXml.merge(tomcatWebXml);
+
+ // Step 7b. Apply global defaults
// Have to merge defaults before JSP conversion since defaults
// provide JSP servlet definition.
webXml.merge(defaults);
@@ -1190,6 +1197,7 @@ public class ContextConfig implements Li
configureContext(webXml);
}
} else {
+ webXml.merge(tomcatWebXml);
webXml.merge(defaults);
convertJsps(webXml);
configureContext(webXml);
@@ -1452,6 +1460,35 @@ public class ContextConfig implements Li
}
+ private WebXml getTomcatWebXmlFragment(WebXmlParser webXmlParser) {
+
+ WebXml webXmlTomcatFragment = createWebXml();
+ webXmlTomcatFragment.setOverridable(true);
+
+ // Set to distributable else every app will be prevented from being
+ // distributable when the Tomcat fragment is merged with the main
+ // web.xml
+ webXmlTomcatFragment.setDistributable(true);
+ // When merging, the default welcome files are only used if the app has
+ // not defined any welcomes files.
+ webXmlTomcatFragment.setAlwaysAddWelcomeFiles(false);
+
+ WebResource resource = context.getResources().getResource("/WEB-INF/tomcat-web.xml");
+ if (resource.isFile()) {
+ try {
+ InputSource source = new InputSource(resource.getURL().toURI().toString());
+ source.setByteStream(resource.getInputStream());
+ if (!webXmlParser.parseWebXml(source, webXmlTomcatFragment, false)) {
+ ok = false;
+ }
+ } catch (URISyntaxException e) {
+ log.error(sm.getString("contextConfig.tomcatWebXmlError"), e);
+ }
+ }
+ return webXmlTomcatFragment;
+ }
+
+
private WebXml getDefaultWebXmlFragment(WebXmlParser webXmlParser) {
// Host should never be null
Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Tue Jul 4 19:14:08 2017
@@ -67,6 +67,7 @@ contextConfig.sci.info=Unable to process
contextConfig.servletContainerInitializerFail=Failed to detect ServletContainerInitializers for context with name [{0}]
contextConfig.start=ContextConfig: Processing START
contextConfig.stop=ContextConfig: Processing STOP
+contextConfig.tomcatWebXmlError=Error processing /WEB-INF/tomcat-web.xml
contextConfig.unavailable=Marking this application unavailable due to previous error(s)
contextConfig.unknownUrlProtocol=The URL protocol [{0}] was not recognised during annotation processing. URL [{1}] was ignored.
contextConfig.urlPatternValue=Both the urlPatterns and value attributes were set for the [{0}] annotation on class [{1}]
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Jul 4 19:14:08 2017
@@ -45,6 +45,18 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 9.0.0.M24 (markt)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <add>
+ <bug>52924</bug>: Add support for a Tomcat specific deployment
+ descriptor, <code>/WEB-INF/tomcat-web.xml</code>. This descriptor has an
+ identical format to <code>/WEB-INF/web.xml</code>. The Tomcat descriptor
+ takes precedence over any settings in <code>conf/web.xml</code> but does
+ not take precedence over any settings in <code>/WEB-INF/web.xml</code>.
+ (markt)
+ </add>
+ </changelog>
+ </subsection>
<subsection name="Other">
<changelog>
<add>
Modified: tomcat/trunk/webapps/docs/config/context.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/context.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/context.xml (original)
+++ tomcat/trunk/webapps/docs/config/context.xml Tue Jul 4 19:14:08 2017
@@ -618,23 +618,23 @@
<attribute name="xmlBlockExternal" required="false">
<p>If the value of this flag is <code>true</code>, the parsing of
- <code>web.xml</code>, <code>web-fragment.xml</code>, <code>*.tld</code>,
- <code>*.jspx</code>, <code>*.tagx</code> and <code>tagPlugins.xml</code>
- files for this web application will not permit external entities to be
- loaded. If not specified, the default value of <code>true</code> will
- be used.</p>
+ <code>web.xml</code>, <code>web-fragment.xml</code>,
+ <code>tomcat-web.xml</code>, <code>*.tld</code>, <code>*.jspx</code>,
+ <code>*.tagx</code> and <code>tagPlugins.xml</code> files for this web
+ application will not permit external entities to be loaded. If not
+ specified, the default value of <code>true</code> will be used.</p>
</attribute>
<attribute name="xmlNamespaceAware" required="false">
<p>If the value of this flag is <code>true</code>, the parsing of
- <code>web.xml</code> and <code>web-fragment.xml</code> files for this
- web application will be namespace-aware. Note that <code>*.tld</code>,
- <code>*.jspx</code> and <code>*.tagx</code> files are always parsed
- using a namespace-aware parser and that the <code>tagPlugins.xml</code>
- file (if any) is never parsed using a namespace-aware parser. Note also
- that if you turn this flag on, you should probably also turn
- <code>xmlValidation</code> on. If the
- <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
+ <code>web.xml</code>, <code>web-fragment.xml</code> and
+ <code>tomcat-web.xml</code> files for this web application will be
+ namespace-aware. Note that <code>*.tld</code>, <code>*.jspx</code> and
+ <code>*.tagx</code> files are always parsed using a namespace-aware
+ parser and that the <code>tagPlugins.xml</code> file (if any) is never
+ parsed using a namespace-aware parser. Note also that if you turn this
+ flag on, you should probably also turn <code>xmlValidation</code> on. If
+ the <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
<a href="systemprops.html">system property</a> is set to
<code>true</code>, the default value of this attribute will be
<code>true</code>, else the default value will be <code>false</code>.
@@ -644,8 +644,9 @@
<attribute name="xmlValidation" required="false">
<p>If the value of this flag is <code>true</code>, the parsing of
- <code>web.xml</code> and <code>web-fragment.xml</code> files for this
- web application will use a validating parser. If the
+ <code>web.xml</code>, <code>web-fragment.xml</code> and
+ <code>tomcat-web.xml</code> files for this web application will use a
+ validating parser. If the
<code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code>
<a href="systemprops.html">system property</a> is set to
<code>true</code>, the default value of this attribute will be
@@ -924,6 +925,10 @@
extension to the corresponding JSP servlet), and other standard
features that apply to all web applications.</li>
<li>The web application properties listed in the
+ <code>/WEB-INF/tomcat-web.xml</code> resource for this web application
+ will be processed (if this resource exists), taking precedence over the
+ defaults.</li>
+ <li>The web application properties listed in the
<code>/WEB-INF/web.xml</code> resource for this web application
will be processed (if this resource exists).</li>
<li>If your web application has specified security constraints that might
Modified: tomcat/trunk/webapps/docs/default-servlet.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/default-servlet.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/default-servlet.xml (original)
+++ tomcat/trunk/webapps/docs/default-servlet.xml Tue Jul 4 19:14:08 2017
@@ -68,8 +68,19 @@ By default here is it's declaration:
<url-pattern>/</url-pattern>
</servlet-mapping>]]></source>
-So by default, the default servlet is loaded at webapp startup and
-directory listings are disabled and debugging is turned off.
+<p>So by default, the default servlet is loaded at webapp startup and directory
+listings are disabled and debugging is turned off.</p>
+
+<p>If you need to change the DefaultServlet settings for an application you can
+override the default configuration by re-defining the DefaultServlet in
+<code>/WEB-INF/web.xml</code>. However, this will cause problems if you attempt
+to deploy the application on another container as the DefaultServlet class will
+not be recognised. You can work-around this problem by using the Tomact specific
+<code>/WEB-INF/tomcat-web.xml</code> deployment descriptor. The format is
+identical to <code>/WEB-INF/web.xml</code>. It will override any default
+settings but not those in <code>/WEB-INF/web.xml</code>. Since it is Tomcat
+specific, it will only be processed when the application is deployed on
+Tomcat.</p>
</section>
<section anchor="change" name="What can I change?">
Modified: tomcat/trunk/webapps/docs/jasper-howto.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/jasper-howto.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/jasper-howto.xml (original)
+++ tomcat/trunk/webapps/docs/jasper-howto.xml Tue Jul 4 19:14:08 2017
@@ -223,6 +223,17 @@ for even large JSP pages.</p>
of the new compiler by configuring the compiler attribute as explained above.
</p>
+<p>If you need to change the JSP Servlet settings for an application you can
+override the default configuration by re-defining the JSP Servlet in
+<code>/WEB-INF/web.xml</code>. However, this may cause problems if you attempt
+to deploy the application on another container as the JSP Servlet class may
+not be recognised. You can work-around this problem by using the Tomact specific
+<code>/WEB-INF/tomcat-web.xml</code> deployment descriptor. The format is
+identical to <code>/WEB-INF/web.xml</code>. It will override any default
+settings but not those in <code>/WEB-INF/web.xml</code>. Since it is Tomcat
+specific, it will only be processed when the application is deployed on
+Tomcat.</p>
+
</section>
<section name="Known issues">
Modified: tomcat/trunk/webapps/docs/security-howto.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/security-howto.xml?rev=1800807&r1=1800806&r2=1800807&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/security-howto.xml (original)
+++ tomcat/trunk/webapps/docs/security-howto.xml Tue Jul 4 19:14:08 2017
@@ -483,9 +483,9 @@
</section>
<section name="web.xml">
- <p>This applies to the default <code>conf/web.xml</code> file and
- <code>WEB-INF/web.xml</code> files in web applications if they define
- the components mentioned here.</p>
+ <p>This applies to the default <code>conf/web.xml</code> file, the
+ <code>/WEB-INF/tomcat-web.xml</code> and the <code>/WEB-INF/web.xml</code>
+ files in web applications if they define the components mentioned here.</p>
<p>The <a href="default-servlet.html">DefaultServlet</a> is configured
with <strong>readonly</strong> set to
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org