Simplify xml validation configuration. It is now configurable per context and can...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 May 2010 09:04:39 +0000 (09:04 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 May 2010 09:04:39 +0000 (09:04 +0000)
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

14 files changed:
conf/server.xml
java/org/apache/catalina/Host.java
java/org/apache/catalina/core/LocalStrings.properties
java/org/apache/catalina/core/LocalStrings_es.properties
java/org/apache/catalina/core/LocalStrings_ja.properties
java/org/apache/catalina/core/StandardContext.java
java/org/apache/catalina/core/StandardHost.java
java/org/apache/catalina/manager/host/HostManagerServlet.java
java/org/apache/catalina/mbeans/MBeanFactory.java
java/org/apache/catalina/startup/ContextConfig.java
java/org/apache/catalina/startup/HostConfig.java
java/org/apache/catalina/startup/TldConfig.java
webapps/docs/config/context.xml
webapps/docs/config/systemprops.xml

index f9f3d94..642c8ee 100644 (file)
            Note: XML Schema validation will not work with Xerces 2.2.
        -->
       <Host name="localhost"  appBase="webapps"
-            unpackWARs="true" autoDeploy="true"
-            xmlValidation="false" xmlNamespaceAware="false">
+            unpackWARs="true" autoDeploy="true">
 
         <!-- SingleSignOn valve, share authentication between web applications
              Documentation at: /docs/config/valve.html -->
index 7ea9140..8e3bd00 100644 (file)
@@ -166,38 +166,6 @@ public interface Host extends Container {
     public void setName(String name);
 
 
-    /**
-     * Get the server.xml &lt;host&gt; attribute's xmlNamespaceAware.
-     * @return true if namespace awareness is enabled.
-     *
-     */
-    public boolean getXmlNamespaceAware();
-
-
-    /**
-     * Get the server.xml &lt;host&gt; 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
 
 
index f744775..6b3dd56 100644 (file)
@@ -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}]
index 1427b5c..a8124e1 100644 (file)
@@ -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}
index 24dc484..fd65c85 100644 (file)
@@ -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
index 2cca32f..7079b5f 100644 (file)
@@ -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;
 
 
     /**
index c3b1b38..6e34295 100644 (file)
@@ -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 &lt;host&gt; attribute's xmlValidation.
-     * @return true if validation is enabled.
-     *
-     */
-    public boolean getXmlValidation(){
-        return xmlValidation;
-    }
-
-    /**
-     * Get the server.xml &lt;host&gt; 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();
     }
 
index 5d0a46c..64c4576 100644 (file)
@@ -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 {
index bcb257b..46ae950 100644 (file)
@@ -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();
index b24fb17..138b32e 100644 (file)
@@ -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();
 
index 65d3ef4..3b81634 100644 (file)
@@ -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);
index 92b0b13..54f71e7 100644 (file)
@@ -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);
         }
     }
index 2254253..e20f044 100644 (file)
       </attribute>
 
       <attribute name="override" required="false">
-        <p>Set to <code>true</code> to have explicit settings in this
-        Context element override any corresponding settings in either the global
+        <p>Set to <code>true</code> to ignore any settings in both the global
         or <a href="host.html">Host</a> default contexts.  By default, settings
-        from a default context will be used.</p>
+        from a default context will be used but may be overridden by a setting
+        the same attribute explicitly for the Context.</p>
         <p>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
         file.</p>
       </attribute>
       
+      <attribute name="tldNamespaceAware" required="false">
+        <p>If the value of this flag is <code>true</code>, the TLD files
+        XML validation will be namespace-aware.  If you turn this flag on,
+        you should probably also turn <code>tldValidation</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>.
+        Setting this attribute to <code>true</code> will incur a performance
+        penalty.</p>
+      </attribute>
+
+      <attribute name="tldValidation" required="false">
+        <p>If the value of this flag is <code>true</code>, the TLD files
+        will be XML validated on context startup. 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>.
+        Setting this attribute to <code>true</code> will incur a performance
+        penalty.</p>
+      </attribute>
+
       <attribute name="wrapperClass" required="false">
         <p>Java class name of the <code>org.apache.catalina.Wrapper</code>
         implementation class that will be used for servlets managed by this
           <code>true</code>.</p>
       </attribute>
       
+      <attribute name="xmlNamespaceAware" required="false">
+        <p>If the value of this flag is <code>true</code>, the validation of
+        XML files will be namespace-aware.  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>.
+        Setting this attribute to <code>true</code> will incur a performance
+        penalty.</p>
+      </attribute>
+
+      <attribute name="xmlValidation" required="false">
+        <p>If the value of this flag is <code>true</code>, the XML files
+        will be validated on context startup. 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>.
+        Setting this attribute to <code>true</code> will incur a performance
+        penalty.</p>
+      </attribute>
+
 
+      
     </attributes>
 
   </subsection>
         of the flag is <code>false</code>.</p>
       </attribute>
 
-      <attribute name="tldNamespaceAware" required="false">
-        <p>If the value of this flag is <code>true</code>, the TLD files
-        XML validation will be namespace-aware.  If you turn this flag on,
-        you should probably also turn <code>tldValidation</code> on.  The
-        default value for this flag is <code>false</code>, and setting it
-        to true will incur a performance penalty.
-        </p>
-      </attribute>
-
-      <attribute name="tldValidation" required="false">
-        <p>If the value of this flag is <code>true</code>, the TLD files
-        will be XML validated on context startup.  The default value for
-        this flag is <code>false</code>, and setting it to true will incur
-        a performance penalty.</p>
-      </attribute>
-
       <attribute name="unloadDelay" required="false">
         <p>Amount of ms that the container will wait for servlets to unload.
         If not specified, the default value of the flag is <code>2000</code> 
index 190cd25..858aa8a 100644 (file)
         if set to false, code like <code>getResource("myfolder/myresource.txt")</code> will work
       </li>
       <li>
-        The default value will be changed for
-        <code>org.apache.tomcat.util.http.ServerCookie.ALWAYS_ADD_EXPIRES</code>.
-        <code>org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR</code>.
-        <code>org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING</code>.
+        The default value will be changed for:
+        <ul>
+        <li><code>org.apache.tomcat.util.http.ServerCookie.ALWAYS_ADD_EXPIRES</code>.</li>
+        <li><code>org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR</code>.</li>
+        <li><code>org.apache.tomcat.util.http.ServerCookie.STRICT_NAMING</code>.</li>
+        <li>The <code>tldNamespaceAware</code> attribute of any
+            <a href="context.html">Context</a> element</li>.
+        <li>The <code>tldValidation</code> attribute of any
+            <a href="context.html">Context</a> element</li>.
+        <li>The <code>xmlNamespaceAware</code> attribute of any
+            <a href="context.html">Context</a> element</li>.
+        <li>The <code>xmlValidation</code> attribute of any
+            <a href="context.html">Context</a> element</li>.
+        </ul>
       </li>
       </ul>
       </p>
       specifications. Defaults, regardless of whether or not they have been
       changed by setting
       <code>org.apache.catalina.STRICT_SERVLET_COMPLIANCE</code> can always be
-      overridden by explicitly setting the appropriate system property.</p>
+      overridden by explicitly setting the appropriate system property or element
+      attribute.</p>
     </property>
 
     <property name="org.apache.catalina.connector. Response.ENFORCE_ENCODING_IN_GET_WRITER">