From e14df286861ece054c182caa0ace866127395bd1 Mon Sep 17 00:00:00 2001
From: markt
Date: Thu, 13 May 2010 09:04:39 +0000
Subject: [PATCH] Simplify xml validation configuration. It is now configurable
per context and can be set per host using a host-level context.xml file so
remove the attributes on the host. If running with STRICT_SERVLET_COMPLIANCE,
enable validation by default.
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@943851 13f79535-47bb-0310-9956-ffa450edef68
---
conf/server.xml | 3 +-
java/org/apache/catalina/Host.java | 32 ----------
.../apache/catalina/core/LocalStrings.properties | 2 -
.../catalina/core/LocalStrings_es.properties | 2 -
.../catalina/core/LocalStrings_ja.properties | 2 -
java/org/apache/catalina/core/StandardContext.java | 8 +--
java/org/apache/catalina/core/StandardHost.java | 56 ------------------
.../catalina/manager/host/HostManagerServlet.java | 12 +---
java/org/apache/catalina/mbeans/MBeanFactory.java | 6 +-
.../org/apache/catalina/startup/ContextConfig.java | 31 ++--------
java/org/apache/catalina/startup/HostConfig.java | 2 -
java/org/apache/catalina/startup/TldConfig.java | 17 ------
webapps/docs/config/context.xml | 69 ++++++++++++++++------
webapps/docs/config/systemprops.xml | 21 +++++--
14 files changed, 78 insertions(+), 185 deletions(-)
diff --git a/conf/server.xml b/conf/server.xml
index f9f3d94aa..642c8ee7b 100644
--- a/conf/server.xml
+++ b/conf/server.xml
@@ -117,8 +117,7 @@
Note: XML Schema validation will not work with Xerces 2.2.
-->
+ unpackWARs="true" autoDeploy="true">
diff --git a/java/org/apache/catalina/Host.java b/java/org/apache/catalina/Host.java
index 7ea914055..8e3bd00ca 100644
--- a/java/org/apache/catalina/Host.java
+++ b/java/org/apache/catalina/Host.java
@@ -166,38 +166,6 @@ public interface Host extends Container {
public void setName(String name);
- /**
- * Get the server.xml <host> attribute's xmlNamespaceAware.
- * @return true if namespace awareness is enabled.
- *
- */
- public boolean getXmlNamespaceAware();
-
-
- /**
- * Get the server.xml <host> attribute's xmlValidation.
- * @return true if validation is enabled.
- *
- */
- public boolean getXmlValidation();
-
-
- /**
- * Set the validation feature of the XML parser used when
- * parsing xml instances.
- * @param xmlValidation true to enable xml instance validation
- */
- public void setXmlValidation(boolean xmlValidation);
-
-
- /**
- * Set the namespace aware feature of the XML parser used when
- * parsing xml instances.
- * @param xmlNamespaceAware true to enable namespace awareness
- */
- public void setXmlNamespaceAware(boolean xmlNamespaceAware);
-
-
// --------------------------------------------------------- Public Methods
diff --git a/java/org/apache/catalina/core/LocalStrings.properties b/java/org/apache/catalina/core/LocalStrings.properties
index f74477577..6b3dd5682 100644
--- a/java/org/apache/catalina/core/LocalStrings.properties
+++ b/java/org/apache/catalina/core/LocalStrings.properties
@@ -186,8 +186,6 @@ standardHost.stop=Stopping web application at context path {0}
standardHost.unfoundContext=Cannot find context for request URI {0}
standardHost.warRequired=URL to web application archive is required
standardHost.warURL=Invalid URL for web application archive: {0}
-standardHost.validationEnabled=XML validation enabled
-standardHost.validationDisabled=XML validation disabled
standardServer.onameFail=MBean name specified for Server [{0}] is not valid
standardServer.shutdownViaPort=A valid shutdown command was received via the shutdown port. Stopping the Server instance.
standardService.connector.initFailed=Failed to initialise connector [{0}]
diff --git a/java/org/apache/catalina/core/LocalStrings_es.properties b/java/org/apache/catalina/core/LocalStrings_es.properties
index 1427b5c95..a8124e119 100644
--- a/java/org/apache/catalina/core/LocalStrings_es.properties
+++ b/java/org/apache/catalina/core/LocalStrings_es.properties
@@ -160,8 +160,6 @@ standardHost.stop = Parando aplicaci\u00F3n web en trayectoria de contexto {0}
standardHost.unfoundContext = No puedo hallar contexto para URI de requerimiento {0}
standardHost.warRequired = Es necesario poner la URL a archivo de aplicaci\u00F3n web
standardHost.warURL = URL inv\u00E1lida para archivo de aplicaci\u00F3n web\: {0}
-standardHost.validationEnabled = Activada la validaci\u00F3n XML
-standardHost.validationDisabled = Desactivada la validaci\u00F3n XML
standardService.initialize.failed = Servicio inicializando en {0} fall\u00F3
standardService.register.failed = Error registrando servicio en dominio {0}
standardService.start.name = Arrancando servicio {0}
diff --git a/java/org/apache/catalina/core/LocalStrings_ja.properties b/java/org/apache/catalina/core/LocalStrings_ja.properties
index 24dc48419..fd65c854d 100644
--- a/java/org/apache/catalina/core/LocalStrings_ja.properties
+++ b/java/org/apache/catalina/core/LocalStrings_ja.properties
@@ -140,8 +140,6 @@ standardHost.stop=\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30d1\u30b9 {0} \u306eWeb
standardHost.unfoundContext=\u30ea\u30af\u30a8\u30b9\u30c8URI {0} \u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093
standardHost.warRequired=Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30a2\u30fc\u30ab\u30a4\u30d6\u306eURL\u304c\u5fc5\u8981\u3067\u3059
standardHost.warURL=Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u5bfe\u3059\u308b\u7121\u52b9\u306aURL\u3067\u3059: {0}
-standardHost.validationEnabled=XML\u691c\u8a3c\u306f\u6709\u52b9\u3067\u3059
-standardHost.validationDisabled=XML\u691c\u8a3c\u306f\u7121\u52b9\u3067\u3059
standardService.start.name=\u30b5\u30fc\u30d3\u30b9 {0} \u3092\u8d77\u52d5\u3057\u307e\u3059
standardService.stop.name=\u30b5\u30fc\u30d3\u30b9 {0} \u3092\u505c\u6b62\u3057\u307e\u3059
standardWrapper.allocate=\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5272\u308a\u5f53\u3066\u4e2d\u306e\u30a8\u30e9\u30fc\u3067\u3059
diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java
index 2cca32f3e..7079b5f9f 100644
--- a/java/org/apache/catalina/core/StandardContext.java
+++ b/java/org/apache/catalina/core/StandardContext.java
@@ -677,13 +677,13 @@ public class StandardContext extends ContainerBase
/**
* Attribute value used to turn on/off XML validation
*/
- private boolean webXmlValidation = false;
+ private boolean webXmlValidation = Globals.STRICT_SERVLET_COMPLIANCE;
/**
* Attribute value used to turn on/off XML namespace validation
*/
- private boolean webXmlNamespaceAware = false;
+ private boolean webXmlNamespaceAware = Globals.STRICT_SERVLET_COMPLIANCE;
/**
* Attribute value used to turn on/off TLD processing
@@ -693,13 +693,13 @@ public class StandardContext extends ContainerBase
/**
* Attribute value used to turn on/off XML validation
*/
- private boolean tldValidation = false;
+ private boolean tldValidation = Globals.STRICT_SERVLET_COMPLIANCE;
/**
* Attribute value used to turn on/off TLD XML namespace validation
*/
- private boolean tldNamespaceAware = false;
+ private boolean tldNamespaceAware = Globals.STRICT_SERVLET_COMPLIANCE;
/**
diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java
index c3b1b38b6..6e342954a 100644
--- a/java/org/apache/catalina/core/StandardHost.java
+++ b/java/org/apache/catalina/core/StandardHost.java
@@ -156,17 +156,6 @@ public class StandardHost extends ContainerBase implements Host {
/**
- * Attribute value used to turn on/off XML validation
- */
- private boolean xmlValidation = false;
-
-
- /**
- * Attribute value used to turn on/off XML namespace awareness.
- */
- private boolean xmlNamespaceAware = false;
-
- /**
* Should we create directories upon startup for appBase and xmlBase
*/
private boolean createDirs = true;
@@ -503,46 +492,8 @@ public class StandardHost extends ContainerBase implements Host {
}
- /**
- * Set the validation feature of the XML parser used when
- * parsing xml instances.
- * @param xmlValidation true to enable xml instance validation
- */
- public void setXmlValidation(boolean xmlValidation){
-
- this.xmlValidation = xmlValidation;
-
- }
-
- /**
- * Get the server.xml <host> attribute's xmlValidation.
- * @return true if validation is enabled.
- *
- */
- public boolean getXmlValidation(){
- return xmlValidation;
- }
-
- /**
- * Get the server.xml <host> attribute's xmlNamespaceAware.
- * @return true if namespace awareness is enabled.
- *
- */
- public boolean getXmlNamespaceAware(){
- return xmlNamespaceAware;
- }
-
/**
- * Set the namespace aware feature of the XML parser used when
- * parsing xml instances.
- * @param xmlNamespaceAware true to enable namespace awareness
- */
- public void setXmlNamespaceAware(boolean xmlNamespaceAware){
- this.xmlNamespaceAware=xmlNamespaceAware;
- }
-
- /**
* Host work directory base.
*/
public String getWorkDir() {
@@ -819,13 +770,6 @@ public class StandardHost extends ContainerBase implements Host {
errorReportValveClass), t);
}
}
- if(log.isDebugEnabled()) {
- if (xmlValidation)
- log.debug(sm.getString("standardHost.validationEnabled"));
- else
- log.debug(sm.getString("standardHost.validationDisabled"));
- }
-
super.startInternal();
}
diff --git a/java/org/apache/catalina/manager/host/HostManagerServlet.java b/java/org/apache/catalina/manager/host/HostManagerServlet.java
index 5d0a46ca1..64c4576b5 100644
--- a/java/org/apache/catalina/manager/host/HostManagerServlet.java
+++ b/java/org/apache/catalina/manager/host/HostManagerServlet.java
@@ -258,15 +258,11 @@ public class HostManagerServlet
boolean deployOnStartup = booleanParameter(request, "deployOnStartup", true, htmlMode);
boolean deployXML = booleanParameter(request, "deployXML", true, htmlMode);
boolean unpackWARs = booleanParameter(request, "unpackWARs", true, htmlMode);
- boolean xmlNamespaceAware = booleanParameter(request, "xmlNamespaceAware", false, htmlMode);
- boolean xmlValidation = booleanParameter(request, "xmlValidation", false, htmlMode);
add(writer, name, aliases, appBase, manager,
autoDeploy,
deployOnStartup,
deployXML,
- unpackWARs,
- xmlNamespaceAware,
- xmlValidation);
+ unpackWARs);
}
@@ -342,9 +338,7 @@ public class HostManagerServlet
boolean autoDeploy,
boolean deployOnStartup,
boolean deployXML,
- boolean unpackWARs,
- boolean xmlNamespaceAware,
- boolean xmlValidation) {
+ boolean unpackWARs) {
if (debug >= 1) {
log(sm.getString("hostManagerServlet.add", name));
}
@@ -438,8 +432,6 @@ public class HostManagerServlet
host.setDeployOnStartup(deployOnStartup);
host.setDeployXML(deployXML);
host.setUnpackWARs(unpackWARs);
- host.setXmlNamespaceAware(xmlNamespaceAware);
- host.setXmlValidation(xmlValidation);
// Add new host
try {
diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java b/java/org/apache/catalina/mbeans/MBeanFactory.java
index bcb257b5a..46ae950ae 100644
--- a/java/org/apache/catalina/mbeans/MBeanFactory.java
+++ b/java/org/apache/catalina/mbeans/MBeanFactory.java
@@ -649,9 +649,7 @@ public class MBeanFactory {
boolean autoDeploy,
boolean deployOnStartup,
boolean deployXML,
- boolean unpackWARs,
- boolean xmlNamespaceAware,
- boolean xmlValidation)
+ boolean unpackWARs)
throws Exception {
// Create a new StandardHost instance
@@ -662,8 +660,6 @@ public class MBeanFactory {
host.setDeployOnStartup(deployOnStartup);
host.setDeployXML(deployXML);
host.setUnpackWARs(unpackWARs);
- host.setXmlNamespaceAware(xmlNamespaceAware);
- host.setXmlValidation(xmlValidation);
// add HostConfig for active reloading
HostConfig hostConfig = new HostConfig();
diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java
index b24fb17ea..138b32e3d 100644
--- a/java/org/apache/catalina/startup/ContextConfig.java
+++ b/java/org/apache/catalina/startup/ContextConfig.java
@@ -27,7 +27,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
-import java.lang.annotation.Annotation;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@@ -858,36 +857,14 @@ public class ContextConfig
if (log.isDebugEnabled())
log.debug(sm.getString("contextConfig.start"));
- // Process the default and application web.xml files
- // Set properties based on default context
- boolean useXmlValidation = context.getXmlValidation();
- boolean useXmlNamespaceAware = context.getXmlNamespaceAware();
-
- Container container = context.getParent();
- // Use the value from the host if:
- // - override is false on the context
- // - value has been set to false / not set on the context
- if( !context.getOverride() ) {
- if( container instanceof Host ) {
- if (!useXmlValidation) {
- useXmlValidation = ((Host)container).getXmlValidation();
- }
-
- if (!useXmlNamespaceAware){
- useXmlNamespaceAware
- = ((Host)container).getXmlNamespaceAware();
- }
-
- }
- }
-
if (log.isDebugEnabled()) {
log.debug(sm.getString("contextConfig.xmlSettings",
- context.getName(), Boolean.valueOf(useXmlValidation),
- Boolean.valueOf(useXmlNamespaceAware)));
+ context.getName(),
+ Boolean.valueOf(context.getXmlValidation()),
+ Boolean.valueOf(context.getXmlNamespaceAware())));
}
- createWebXmlDigester(useXmlNamespaceAware, useXmlValidation);
+ createWebXmlDigester(context.getXmlNamespaceAware(), context.getXmlValidation());
webConfig();
diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java
index 65d3ef41d..3b8163422 100644
--- a/java/org/apache/catalina/startup/HostConfig.java
+++ b/java/org/apache/catalina/startup/HostConfig.java
@@ -344,8 +344,6 @@ public class HostConfig
setCopyXML(((StandardHost) host).isCopyXML());
setDeployXML(((StandardHost) host).isDeployXML());
setUnpackWARs(((StandardHost) host).isUnpackWARs());
- setXmlNamespaceAware(((StandardHost) host).getXmlNamespaceAware());
- setXmlValidation(((StandardHost) host).getXmlValidation());
}
} catch (ClassCastException e) {
log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e);
diff --git a/java/org/apache/catalina/startup/TldConfig.java b/java/org/apache/catalina/startup/TldConfig.java
index 92b0b1333..54f71e723 100644
--- a/java/org/apache/catalina/startup/TldConfig.java
+++ b/java/org/apache/catalina/startup/TldConfig.java
@@ -42,7 +42,6 @@ import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.StandardContext;
-import org.apache.catalina.core.StandardHost;
import org.apache.tomcat.JarScanner;
import org.apache.tomcat.JarScannerCallback;
import org.apache.tomcat.util.ExceptionUtils;
@@ -586,24 +585,8 @@ public final class TldConfig implements LifecycleListener {
private void init() {
if (tldDigester == null){
- // (1) check if the attribute has been defined
- // on the context element.
setTldValidation(context.getTldValidation());
setTldNamespaceAware(context.getTldNamespaceAware());
-
- // (2) if the attribute wasn't defined on the context
- // and override is not set on the context try the host.
- if (!context.getOverride()) {
- if (!tldValidation) {
- setTldValidation(
- ((StandardHost) context.getParent()).getXmlValidation());
- }
-
- if (!tldNamespaceAware) {
- setTldNamespaceAware(
- ((StandardHost) context.getParent()).getXmlNamespaceAware());
- }
- }
tldDigester = createTldDigester(tldNamespaceAware, tldValidation);
}
}
diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml
index 2254253d6..e20f044c7 100644
--- a/webapps/docs/config/context.xml
+++ b/webapps/docs/config/context.xml
@@ -191,10 +191,10 @@
- Set to true to have explicit settings in this
- Context element override any corresponding settings in either the global
+
Set to true to ignore any settings in both the global
or Host default contexts. By default, settings
- from a default context will be used.
+ from a default context will be used but may be overridden by a setting
+ the same attribute explicitly for the Context.
If a symbolic link is used for docBase then changes to the
symbolic link will only be effective after a Tomcat restart or
by undeploying and redeploying the context. A context reload is not
@@ -255,6 +255,29 @@
file.
+
+ If the value of this flag is true, the TLD files
+ XML validation will be namespace-aware. If you turn this flag on,
+ you should probably also turn tldValidation on. If the
+ org.apache.catalina.STRICT_SERVLET_COMPLIANCE
+ system property is set to
+ true, the default value of this attribute will be
+ true, else the default value will be false.
+ Setting this attribute to true will incur a performance
+ penalty.
+
+
+
+ If the value of this flag is true, the TLD files
+ will be XML validated on context startup. If the
+ org.apache.catalina.STRICT_SERVLET_COMPLIANCE
+ system property is set to
+ true, the default value of this attribute will be
+ true, else the default value will be false.
+ Setting this attribute to true will incur a performance
+ penalty.
+
+
Java class name of the org.apache.catalina.Wrapper
implementation class that will be used for servlets managed by this
@@ -267,7 +290,31 @@
true.
+
+ If the value of this flag is true, the validation of
+ XML files will be namespace-aware. If you turn this flag on,
+ you should probably also turn xmlValidation on. If
+ the org.apache.catalina.STRICT_SERVLET_COMPLIANCE
+ system property is set to
+ true, the default value of this attribute will be
+ true, else the default value will be false.
+ Setting this attribute to true will incur a performance
+ penalty.
+
+
+
+ If the value of this flag is true, the XML files
+ will be validated on context startup. If the
+ org.apache.catalina.STRICT_SERVLET_COMPLIANCE
+ system property is set to
+ true, the default value of this attribute will be
+ true, else the default value will be false.
+ Setting this attribute to true will incur a performance
+ penalty.
+
+
+
@@ -409,22 +456,6 @@
of the flag is false.
-
- If the value of this flag is true, the TLD files
- XML validation will be namespace-aware. If you turn this flag on,
- you should probably also turn tldValidation on. The
- default value for this flag is false, and setting it
- to true will incur a performance penalty.
-
-
-
-
- If the value of this flag is true, the TLD files
- will be XML validated on context startup. The default value for
- this flag is false, and setting it to true will incur
- a performance penalty.
-
-
Amount of ms that the container will wait for servlets to unload.
If not specified, the default value of the flag is 2000
diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml
index 190cd257b..858aa8a10 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -237,10 +237,20 @@
if set to false, code like getResource("myfolder/myresource.txt") will work
- The default value will be changed for
- org.apache.tomcat.util.http.ServerCookie.ALWAYS_ADD_EXPIRES.
- org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR.
- org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING.
+ The default value will be changed for:
+
+ org.apache.tomcat.util.http.ServerCookie.ALWAYS_ADD_EXPIRES.
+ org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR.
+ org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING.
+ - The
tldNamespaceAware attribute of any
+ Context element .
+ - The
tldValidation attribute of any
+ Context element .
+ - The
xmlNamespaceAware attribute of any
+ Context element .
+ - The
xmlValidation attribute of any
+ Context element .
+
@@ -250,7 +260,8 @@
specifications. Defaults, regardless of whether or not they have been
changed by setting
org.apache.catalina.STRICT_SERVLET_COMPLIANCE can always be
- overridden by explicitly setting the appropriate system property.
+ overridden by explicitly setting the appropriate system property or element
+ attribute.
--
2.11.0