Author: remm
Date: Mon Aug 13 11:13:47 2007
New Revision: 565464

URL: http://svn.apache.org/viewvc?view=rev&rev=565464
Log:
- Experiment with reporting warnings for unmatched elements and attributes, 
based on Bill's ideas.
- The NIO HTTP protocol handler does not seem very reporting friendly at the 
moment.
- The change should be rather safe, if it causes problems that cannot be fixed 
easily I will revert it.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Catalina.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Embedded.java
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetAllPropertiesRule.java
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetContextPropertiesRule.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Protocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java
    tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java
    
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertiesRule.java
    
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertyRule.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/Connector.java Mon 
Aug 13 11:13:47 2007
@@ -318,6 +318,20 @@
         if (replacements.get(name) != null) {
             repl = (String) replacements.get(name);
         }
+        if (!IntrospectionUtils.setProperty(protocolHandler, repl, value)) {
+            log.warn("Property " + name + " not found on the protocol 
handler.");
+        }
+    }
+
+
+    /**
+     * Set a configured property.
+     */
+    public void setPropertyInternal(String name, String value) {
+        String repl = name;
+        if (replacements.get(name) != null) {
+            repl = (String) replacements.get(name);
+        }
         IntrospectionUtils.setProperty(protocolHandler, repl, value);
     }
 
@@ -388,7 +402,7 @@
     public void setAllowTrace(boolean allowTrace) {
 
         this.allowTrace = allowTrace;
-        setProperty("allowTrace", String.valueOf(allowTrace));
+        setPropertyInternal("allowTrace", String.valueOf(allowTrace));
 
     }
 
@@ -466,7 +480,7 @@
     public void setEmptySessionPath(boolean emptySessionPath) {
 
         this.emptySessionPath = emptySessionPath;
-        setProperty("emptySessionPath", String.valueOf(emptySessionPath));
+        setPropertyInternal("emptySessionPath", 
String.valueOf(emptySessionPath));
 
     }
 
@@ -489,7 +503,7 @@
     public void setEnableLookups(boolean enableLookups) {
 
         this.enableLookups = enableLookups;
-        setProperty("enableLookups", String.valueOf(enableLookups));
+        setPropertyInternal("enableLookups", String.valueOf(enableLookups));
 
     }
 
@@ -559,7 +573,7 @@
     public void setMaxSavePostSize(int maxSavePostSize) {
 
         this.maxSavePostSize = maxSavePostSize;
-        setProperty("maxSavePostSize", String.valueOf(maxSavePostSize));
+        setPropertyInternal("maxSavePostSize", 
String.valueOf(maxSavePostSize));
     }
 
 
@@ -581,7 +595,7 @@
     public void setPort(int port) {
 
         this.port = port;
-        setProperty("port", String.valueOf(port));
+        setPropertyInternal("port", String.valueOf(port));
 
     }
 
@@ -745,7 +759,7 @@
 
         if(proxyName != null && proxyName.length() > 0) {
             this.proxyName = proxyName;
-            setProperty("proxyName", proxyName);
+            setPropertyInternal("proxyName", proxyName);
         } else {
             this.proxyName = null;
             removeProperty("proxyName");
@@ -772,7 +786,7 @@
     public void setProxyPort(int proxyPort) {
 
         this.proxyPort = proxyPort;
-        setProperty("proxyPort", String.valueOf(proxyPort));
+        setPropertyInternal("proxyPort", String.valueOf(proxyPort));
 
     }
 
@@ -797,7 +811,7 @@
     public void setRedirectPort(int redirectPort) {
 
         this.redirectPort = redirectPort;
-        setProperty("redirectPort", String.valueOf(redirectPort));
+        setPropertyInternal("redirectPort", String.valueOf(redirectPort));
 
     }
 
@@ -846,7 +860,7 @@
     public void setSecure(boolean secure) {
 
         this.secure = secure;
-        setProperty("secure", Boolean.toString(secure));
+        setPropertyInternal("secure", Boolean.toString(secure));
     }
 
      /**
@@ -867,7 +881,7 @@
      public void setURIEncoding(String URIEncoding) {
 
          this.URIEncoding = URIEncoding;
-         setProperty("uRIEncoding", URIEncoding);
+         setPropertyInternal("uRIEncoding", URIEncoding);
 
      }
 
@@ -890,7 +904,7 @@
      public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI) {
 
          this.useBodyEncodingForURI = useBodyEncodingForURI;
-         setProperty
+         setPropertyInternal
              ("useBodyEncodingForURI", String.valueOf(useBodyEncodingForURI));
 
      }
@@ -918,7 +932,7 @@
      */
     public void setXpoweredBy(boolean xpoweredBy) {
         this.xpoweredBy = xpoweredBy;
-        setProperty("xpoweredBy", String.valueOf(xpoweredBy));
+        setPropertyInternal("xpoweredBy", String.valueOf(xpoweredBy));
     }
 
     /**
@@ -929,7 +943,7 @@
      */
     public void setUseIPVHosts(boolean useIPVHosts) {
         this.useIPVHosts = useIPVHosts;
-        setProperty("useIPVHosts", String.valueOf(useIPVHosts));
+        setPropertyInternal("useIPVHosts", String.valueOf(useIPVHosts));
     }
 
     /**

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Catalina.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Catalina.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Catalina.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Catalina.java Mon Aug 
13 11:13:47 2007
@@ -21,10 +21,14 @@
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.InputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.Socket;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
 import org.apache.catalina.Container;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
@@ -260,6 +264,12 @@
         // Initialize the digester
         Digester digester = new Digester();
         digester.setValidating(false);
+        digester.setRulesValidation(true);
+        HashMap<Class, List<String>> fakeAttributes = new HashMap<Class, 
List<String>>();
+        ArrayList<String> attrs = new ArrayList<String>();
+        attrs.add("className");
+        fakeAttributes.put(Object.class, attrs);
+        digester.setFakeAttributes(fakeAttributes);
         digester.setClassLoader(StandardServer.class.getClassLoader());
 
         // Configure the actions we will be using

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Embedded.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Embedded.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Embedded.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/Embedded.java Mon Aug 
13 11:13:47 2007
@@ -427,7 +427,7 @@
                 connector = new Connector();
                 connector.setScheme("https");
                 connector.setSecure(true);
-                connector.setProperty("SSLEnabled","true");
+                connector.setPropertyInternal("SSLEnabled","true");
                 // FIXME !!!! SET SSL PROPERTIES
             } else {
                 connector = new Connector(protocol);

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetAllPropertiesRule.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetAllPropertiesRule.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetAllPropertiesRule.java 
(original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetAllPropertiesRule.java 
Mon Aug 13 11:13:47 2007
@@ -62,8 +62,15 @@
                 name = attributes.getQName(i);
             }
             String value = attributes.getValue(i);
-            if ( !excludes.containsKey(name)) 
-                IntrospectionUtils.setProperty(digester.peek(), name, value);
+            if ( !excludes.containsKey(name)) {
+                if (!digester.isFakeAttribute(digester.peek(), name) 
+                        && !IntrospectionUtils.setProperty(digester.peek(), 
name, value) 
+                        && digester.getRulesValidation()) {
+                    digester.getLogger().warn("[SetAllPropertiesRule]{" + 
digester.getMatch() +
+                            "} Setting property '" + name + "' to '" +
+                            value + "' did not find a matching property.");
+                }
+            }
         }
 
     }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetContextPropertiesRule.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetContextPropertiesRule.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetContextPropertiesRule.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/startup/SetContextPropertiesRule.java
 Mon Aug 13 11:13:47 2007
@@ -60,7 +60,13 @@
                 continue;
             }
             String value = attributes.getValue(i);
-            IntrospectionUtils.setProperty(digester.peek(), name, value);
+            if (!digester.isFakeAttribute(digester.peek(), name) 
+                    && !IntrospectionUtils.setProperty(digester.peek(), name, 
value) 
+                    && digester.getRulesValidation()) {
+                digester.getLogger().warn("[SetContextPropertiesRule]{" + 
digester.getMatch() +
+                        "} Setting property '" + name + "' to '" +
+                        value + "' did not find a matching property.");
+            }
         }
 
     }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java Mon Aug 
13 11:13:47 2007
@@ -137,22 +137,6 @@
 
 
     /**
-     * Set a property.
-     */
-    public void setProperty(String name, String value) {
-        setAttribute(name, value);
-    }
-
-
-    /**
-     * Get a property
-     */
-    public String getProperty(String name) {
-        return (String) getAttribute(name);
-    }
-
-
-    /**
      * The adapter, used to call the connector
      */
     public void setAdapter(Adapter adapter) {

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java Mon Aug 13 
11:13:47 2007
@@ -137,22 +137,6 @@
 
 
     /**
-     * Set a property.
-     */
-    public void setProperty(String name, String value) {
-        setAttribute(name, value);
-    }
-
-
-    /**
-     * Get a property
-     */
-    public String getProperty(String name) {
-        return (String) getAttribute(name);
-    }
-
-
-    /**
      * The adapter, used to call the connector
      */
     public void setAdapter(Adapter adapter) {

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 
Mon Aug 13 11:13:47 2007
@@ -90,20 +90,6 @@
     }
 
     /**
-     * Set a property.
-     */
-    public void setProperty(String name, String value) {
-        setAttribute(name, value);
-    }
-
-    /**
-     * Get a property
-     */
-    public String getProperty(String name) {
-        return (String)getAttribute(name);
-    }
-
-    /**
      * The adapter, used to call the connector.
      */
     protected Adapter adapter;
@@ -325,14 +311,9 @@
     public void setRestrictedUserAgents(String valueS) { restrictedUserAgents 
= valueS; }
     
     
-    public String getProtocol() {
-        return getProperty("protocol");
-    }
-
-    public void setProtocol( String k ) {
-        setSecure(true);
-        setAttribute("protocol", k);
-    }
+    protected String protocol = null;
+    public String getProtocol() { return protocol; }
+    public void setProtocol(String protocol) { setSecure(true); this.protocol 
= protocol; }
 
     /**
      * Maximum number of requests which can be performed over a keepalive 

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Protocol.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Protocol.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Protocol.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11Protocol.java Mon 
Aug 13 11:13:47 2007
@@ -103,20 +103,6 @@
 
     
     /**
-     * Set a property.
-     */
-    public void setProperty(String name, String value) {
-        setAttribute(name, value);
-    }
-
-    /**
-     * Get a property
-     */
-    public String getProperty(String name) {
-        return (String)getAttribute(name);
-    }
-
-    /**
      * Pass config info
      */
     public void setAttribute(String name, Object value) {

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/IntrospectionUtils.java 
Mon Aug 13 11:13:47 2007
@@ -258,7 +258,7 @@
      * int or boolean we'll convert value to the right type before) - that 
means
      * you can have setDebug(1).
      */
-    public static void setProperty(Object o, String name, String value) {
+    public static boolean setProperty(Object o, String name, String value) {
         if (dbg > 1)
             d("setProperty(" + o.getClass() + " " + name + "=" + value + ")");
 
@@ -275,7 +275,7 @@
                         && "java.lang.String".equals(paramT[0].getName())) {
 
                     methods[i].invoke(o, new Object[] { value });
-                    return;
+                    return true;
                 }
             }
 
@@ -328,7 +328,7 @@
 
                     if (ok) {
                         methods[i].invoke(o, params);
-                        return;
+                        return true;
                     }
                 }
 
@@ -344,6 +344,7 @@
                 params[0] = name;
                 params[1] = value;
                 setPropertyMethod.invoke(o, params);
+                return true;
             }
 
         } catch (IllegalArgumentException ex2) {
@@ -367,6 +368,7 @@
             if (dbg > 1)
                 ie.printStackTrace();
         }
+        return false;
     }
 
     public static Object getProperty(Object o, String name) {

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/Digester.java Mon 
Aug 13 11:13:47 2007
@@ -312,6 +312,19 @@
     protected boolean validating = false;
 
 
+    
+    /**
+     * Warn on missing attributes and elements.
+     */
+    protected boolean rulesValidation = false;
+
+    
+    /**
+     * Fake attributes map (attributes are often used for object creation).
+     */
+    protected Map<Class, List<String>> fakeAttributes = null;
+
+
     /**
      * The Log to which most logging calls will be made.
      */
@@ -889,6 +902,72 @@
 
 
     /**
+     * Return the rules validation flag.
+     */
+    public boolean getRulesValidation() {
+
+        return (this.rulesValidation);
+
+    }
+
+
+    /**
+     * Set the rules validation flag.  This must be called before
+     * <code>parse()</code> is called the first time.
+     *
+     * @param rulesValidation The new rules validation flag.
+     */
+    public void setRulesValidation(boolean rulesValidation) {
+
+        this.rulesValidation = rulesValidation;
+
+    }
+
+
+    /**
+     * Return the fake attributes list.
+     */
+    public Map<Class, List<String>> getFakeAttributes() {
+
+        return (this.fakeAttributes);
+
+    }
+
+
+    /**
+     * Determine if an attribute is a fake attribute.
+     */
+    public boolean isFakeAttribute(Object object, String name) {
+
+        if (fakeAttributes == null) {
+            return false;
+        }
+        List<String> result = fakeAttributes.get(object.getClass());
+        if (result == null) {
+            result = fakeAttributes.get(Object.class);
+        }
+        if (result == null) {
+            return false;
+        } else {
+            return result.contains(name);
+        }
+
+    }
+
+
+    /**
+     * Set the fake attributes.
+     *
+     * @param fakeAttributes The new fake attributes.
+     */
+    public void setFakeAttributes(Map<Class, List<String>> fakeAttributes) {
+
+        this.fakeAttributes = fakeAttributes;
+
+    }
+
+
+    /**
      * Return the XMLReader to be used for parsing the input document.
      *
      * FIX ME: there is a bug in JAXP/XERCES that prevent the use of a 
@@ -1037,6 +1116,9 @@
         } else {
             if (debug) {
                 log.debug("  No rules found matching '" + match + "'.");
+            }
+            if (rulesValidation) {
+                log.warn("  No rules found matching '" + match + "'.");
             }
         }
 

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertiesRule.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertiesRule.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertiesRule.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertiesRule.java
 Mon Aug 13 11:13:47 2007
@@ -205,7 +205,13 @@
                         "} Setting property '" + name + "' to '" +
                         value + "'");
             }
-            IntrospectionUtils.setProperty(top, name, value);
+            if (!digester.isFakeAttribute(top, name) 
+                    && !IntrospectionUtils.setProperty(top, name, value) 
+                    && digester.getRulesValidation()) {
+                digester.log.warn("[SetPropertiesRule]{" + digester.match +
+                        "} Setting property '" + name + "' to '" +
+                        value + "' did not find a matching property.");
+            }
         }
 
     }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertyRule.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertyRule.java?view=diff&rev=565464&r1=565463&r2=565464
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertyRule.java 
(original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/digester/SetPropertyRule.java 
Mon Aug 13 11:13:47 2007
@@ -125,8 +125,13 @@
         }
 
         // Set the property (with conversion as necessary)
-        // FIXME: Exception if property doesn't exist ?
-        IntrospectionUtils.setProperty(top, actualName, actualValue);
+        if (!digester.isFakeAttribute(top, actualName) 
+                && !IntrospectionUtils.setProperty(top, actualName, 
actualValue) 
+                && digester.getRulesValidation()) {
+            digester.log.warn("[SetPropertyRule]{" + digester.match +
+                    "} Setting property '" + name + "' to '" +
+                    value + "' did not find a matching property.");
+        }
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to