From: markt Date: Wed, 30 Dec 2009 21:50:33 +0000 (+0000) Subject: Fix an problem highlighted by the JSP 2.1 TCK. Only provide merged 3.0+ web.xml for... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1a8b3312894af0ef477688c685eecd6722a8b169;p=tomcat7.0 Fix an problem highlighted by the JSP 2.1 TCK. Only provide merged 3.0+ web.xml for 3.0+ apps. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@894718 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 17edb9c27..4a4ed9a93 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -1190,7 +1190,13 @@ public class ContextConfig InputSource contextWebXml = getContextWebXmlSource(); parseWebXml(contextWebXml, webXml, false); - if (!webXml.isMetadataComplete()) { + // Assuming 0 is safe for what is required in this case + double webXmlVersion = 0; + if (webXml.getVersion() != null) { + webXmlVersion = Double.parseDouble(webXml.getVersion()); + } + + if (webXmlVersion >= 3 && !webXml.isMetadataComplete()) { // Process /WEB-INF/classes for annotations URL webinfClasses; try { @@ -1219,19 +1225,21 @@ public class ContextConfig // Apply merged web.xml to Context webXml.configureContext(context); + + // Make the merged web.xml available to other components, + // specifically Jasper, to save those components from having to + // re-generate it. + String mergedWebXml = webXml.toXml(); + context.getServletContext().setAttribute( + org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML, + mergedWebXml); + if (context.getLogEffectiveWebXml()) { + log.info("web.xml:\n" + mergedWebXml); + } } else { - // Apply merged web.xml to Context + // Apply unmerged web.xml to Context webXml.configureContext(context); - } - // Make the merged web.xml available to other components, specifically - // Jasper, to save those components from having to re-generate it. - String mergedWebXml = webXml.toXml(); - context.getServletContext().setAttribute( - org.apache.tomcat.util.scan.Constants.MERGED_WEB_XML, - mergedWebXml); - if (context.getLogEffectiveWebXml()) { - log.info("web.xml:\n" + mergedWebXml); - } + } } diff --git a/java/org/apache/catalina/startup/WebRuleSet.java b/java/org/apache/catalina/startup/WebRuleSet.java index 55fc3b2de..dea67e452 100644 --- a/java/org/apache/catalina/startup/WebRuleSet.java +++ b/java/org/apache/catalina/startup/WebRuleSet.java @@ -160,6 +160,8 @@ public class WebRuleSet extends RuleSetBase { new SetPublicIdRule("setPublicId")); digester.addRule(fullPrefix, new IgnoreAnnotationsRule()); + digester.addRule(fullPrefix, + new VersionRule()); if (fragment) { // web-fragment.xml @@ -1007,6 +1009,33 @@ final class IgnoreAnnotationsRule extends Rule { } /** + * A Rule that records the spec version of the web.xml being parsed + * + */ + +final class VersionRule extends Rule { + + public VersionRule() { + // NO-OP + } + + @Override + public void begin(String namespace, String name, Attributes attributes) + throws Exception { + WebXml webxml = (WebXml) digester.peek(digester.getCount() - 1); + webxml.setVersion(attributes.getValue("version")); + + if (digester.getLogger().isDebugEnabled()) { + digester.getLogger().debug + (webxml.getClass().getName() + ".setVersion( " + + webxml.getVersion() + ")"); + } + } + +} + + +/** * A rule that logs a warning if absolute ordering is configured. */ final class AbsoluteOrderingRule extends Rule { diff --git a/java/org/apache/catalina/startup/WebXml.java b/java/org/apache/catalina/startup/WebXml.java index fd0cc27dc..2ce6f2a6d 100644 --- a/java/org/apache/catalina/startup/WebXml.java +++ b/java/org/apache/catalina/startup/WebXml.java @@ -505,7 +505,14 @@ public class WebXml { sb.append("\"http://www.w3.org/2001/XMLSchema-instance\"\n"); sb.append(" xsi:schemaLocation="); sb.append("\"http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n"); - sb.append(" version=\"3.0\"\n"); + sb.append(" version=\""); + if (version != null) { + sb.append(version); + } else { + // Should be non-null but in case it isn't assume 3.0 + sb.append("3.0"); + } + sb.append("\"\n"); sb.append(" metadata-complete=\"true\">\n\n"); appendElement(sb, INDENT2, "display-name", displayName);