Replace the RequestDumperValve with a RequestDumperFilter. Merge the RequestDumperFil...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Aug 2009 11:49:26 +0000 (11:49 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 18 Aug 2009 11:49:26 +0000 (11:49 +0000)
Adds:
- thread name to start of output line to make analysing output easier
- request timings
GSOC 2009
Based on a patch by Xie Xiaodong

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@805375 13f79535-47bb-0310-9956-ffa450edef68

conf/server.xml
java/org/apache/catalina/filters/RequestDumperFilter.java [new file with mode: 0644]
java/org/apache/catalina/mbeans/MBeanFactory.java
java/org/apache/catalina/valves/RequestDumperValve.java [deleted file]
webapps/docs/config/filter.xml
webapps/docs/config/valve.xml
webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java [deleted file]
webapps/examples/WEB-INF/web.xml

index c2428aa..1f96f3f 100644 (file)
       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
       -->        
 
-      <!-- The request dumper valve dumps useful debugging information about
-           the request and response data received and sent by Tomcat.
-           Documentation at: /docs/config/valve.html -->
-      <!--
-      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-      -->
-
       <!-- This Realm uses the UserDatabase configured in the global JNDI
            resources under the key "UserDatabase".  Any edits
            that are performed against this UserDatabase are immediately
diff --git a/java/org/apache/catalina/filters/RequestDumperFilter.java b/java/org/apache/catalina/filters/RequestDumperFilter.java
new file mode 100644 (file)
index 0000000..49e9ff2
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina.filters;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+
+/**
+ * <p>Implementation of a Filter that logs interesting contents from the
+ * specified Request (before processing) and the corresponding Response
+ * (after processing).  It is especially useful in debugging problems
+ * related to headers and cookies.</p>
+ * 
+ * <p>When using this Filter, it is strongly recommended that the
+ * <code>org.apache.catalina.filter.RequestDumperFilter</code> logger is
+ * directed to a dedicated file and that the
+ * <code>org.apache.juli.VerbatimFormmater</code> is used.</p>
+ *
+ * @author Craig R. McClanahan
+ */
+
+public class RequestDumperFilter implements Filter {
+
+    private static final String NON_HTTP_REQ_MSG =
+        "Not available. Non-http request.";
+    private static final String NON_HTTP_RES_MSG =
+        "Not available. Non-http response.";
+
+    private static final ThreadLocal<Timestamp> timestamp =
+            new ThreadLocal<Timestamp>() {
+        protected Timestamp initialValue() {
+            return new Timestamp();
+        }
+    };
+
+    /**
+     * The logger for this class.
+     */
+    private static Log log = LogFactory.getLog(RequestDumperFilter.class);
+
+
+    /**
+     * Log the interesting request parameters, invoke the next Filter in the
+     * sequence, and log the interesting response parameters.
+     *
+     * @param request  The servlet request to be processed
+     * @param response The servlet response to be created
+     * @param chain    The filter chain being processed
+     *
+     * @exception IOException if an input/output error occurs
+     * @exception ServletException if a servlet error occurs
+     */
+    public void doFilter(ServletRequest request, ServletResponse response,
+            FilterChain chain)
+        throws IOException, ServletException {
+
+        HttpServletRequest hRequest = null;
+        HttpServletResponse hResponse = null;
+        
+        if (request instanceof HttpServletRequest) {
+            hRequest = (HttpServletRequest) request;
+        }
+        if (response instanceof HttpServletResponse) {
+            hResponse = (HttpServletResponse) response;
+        }
+
+        // Log pre-service information
+        doLog("START TIME        ", getTimestamp());
+        
+        if (hRequest == null) {
+            doLog("        requestURI", NON_HTTP_REQ_MSG);
+            doLog("          authType", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("        requestURI", hRequest.getRequestURI());
+            doLog("          authType", hRequest.getAuthType());
+        }
+        
+        doLog(" characterEncoding", request.getCharacterEncoding());
+        doLog("     contentLength",
+                Integer.valueOf(request.getContentLength()).toString());
+        doLog("       contentType", request.getContentType());
+        
+        if (hRequest == null) {
+            doLog("       contextPath", NON_HTTP_REQ_MSG);
+            doLog("            cookie", NON_HTTP_REQ_MSG);
+            doLog("            header", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("       contextPath", hRequest.getContextPath());
+            Cookie cookies[] = hRequest.getCookies();
+            if (cookies != null) {
+                for (int i = 0; i < cookies.length; i++)
+                    doLog("            cookie", cookies[i].getName() +
+                            "=" + cookies[i].getValue());
+            }
+            Enumeration<String> hnames = hRequest.getHeaderNames();
+            while (hnames.hasMoreElements()) {
+                String hname = hnames.nextElement();
+                Enumeration<String> hvalues = hRequest.getHeaders(hname);
+                while (hvalues.hasMoreElements()) {
+                    String hvalue = hvalues.nextElement();
+                    doLog("            header", hname + "=" + hvalue);
+                }
+            }
+        }
+        
+        doLog("            locale", request.getLocale().toString());
+        
+        if (hRequest == null) {
+            doLog("            method", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("            method", hRequest.getMethod());
+        }
+        
+        Enumeration<String> pnames = request.getParameterNames();
+        while (pnames.hasMoreElements()) {
+            String pname = pnames.nextElement();
+            String pvalues[] = request.getParameterValues(pname);
+            StringBuffer result = new StringBuffer(pname);
+            result.append('=');
+            for (int i = 0; i < pvalues.length; i++) {
+                if (i > 0)
+                    result.append(", ");
+                result.append(pvalues[i]);
+            }
+            doLog("         parameter", result.toString());
+        }
+        
+        if (hRequest == null) {
+            doLog("          pathInfo", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("          pathInfo", hRequest.getPathInfo());
+        }
+        
+        doLog("          protocol", request.getProtocol());
+        
+        if (hRequest == null) {
+            doLog("       queryString", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("       queryString", hRequest.getQueryString());
+        }
+        
+        doLog("        remoteAddr", request.getRemoteAddr());
+        doLog("        remoteHost", request.getRemoteHost());
+        
+        if (hRequest == null) {
+            doLog("        remoteUser", NON_HTTP_REQ_MSG);
+            doLog("requestedSessionId", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("        remoteUser", hRequest.getRemoteUser());
+            doLog("requestedSessionId", hRequest.getRequestedSessionId());
+        }
+        
+        doLog("            scheme", request.getScheme());
+        doLog("        serverName", request.getServerName());
+        doLog("        serverPort",
+                Integer.valueOf(request.getServerPort()).toString());
+        
+        if (hRequest == null) {
+            doLog("       servletPath", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("       servletPath", hRequest.getServletPath());
+        }
+        
+        doLog("          isSecure",
+                Boolean.valueOf(request.isSecure()).toString());
+        doLog("------------------",
+                "--------------------------------------------");
+
+        // Perform the request
+        chain.doFilter(request, response);
+
+        // Log post-service information
+        doLog("------------------",
+                "--------------------------------------------");
+        if (hRequest == null) {
+            doLog("          authType", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("          authType", hRequest.getAuthType());
+        }
+        
+        doLog("       contentType", response.getContentType());
+        
+        if (hResponse == null) {
+            doLog("            header", NON_HTTP_RES_MSG);
+        } else {
+            Iterable<String> rhnames = hResponse.getHeaderNames();
+            for (String rhname : rhnames) {
+                Iterable<String> rhvalues = hResponse.getHeaders(rhname);
+                for (String rhvalue : rhvalues)
+                    doLog("            header", rhname + "=" + rhvalue);
+            }
+        }
+
+        if (hRequest == null) {
+            doLog("        remoteUser", NON_HTTP_REQ_MSG);
+        } else {
+            doLog("        remoteUser", hRequest.getRemoteUser());
+        }
+        
+        if (hResponse == null) {
+            doLog("        remoteUser", NON_HTTP_RES_MSG);
+        } else {
+            doLog("            status",
+                    Integer.valueOf(hResponse.getStatus()).toString());
+        }
+
+        doLog("END TIME          ", getTimestamp());
+        doLog("==================",
+                "============================================");
+       }
+
+    private void doLog(String attribute, String value) {
+        StringBuilder sb = new StringBuilder(80);
+        sb.append(Thread.currentThread().getName());
+        sb.append(' ');
+        sb.append(attribute);
+        sb.append('=');
+        sb.append(value);
+        log.info(sb.toString());
+    }
+
+    private String getTimestamp() {
+        Timestamp ts = timestamp.get();
+        long currentTime = System.currentTimeMillis();
+        
+        if ((ts.date.getTime() + 999) < currentTime) {
+            ts.date.setTime(currentTime - (currentTime % 1000));
+            ts.update();
+        }
+        return ts.dateString;
+    }
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        // NOOP
+    }
+
+    @Override
+    public void destroy() {
+        // NOOP
+    }
+
+    private static final class Timestamp {
+        private Date date = new Date(0);
+        private SimpleDateFormat format =
+            new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
+        private String dateString = format.format(date);
+        private void update() {
+            dateString = format.format(date);
+        }
+    }
+}
index 03c85d2..0ac143d 100644 (file)
@@ -49,7 +49,6 @@ import org.apache.catalina.startup.HostConfig;
 import org.apache.catalina.valves.AccessLogValve;
 import org.apache.catalina.valves.RemoteAddrValve;
 import org.apache.catalina.valves.RemoteHostValve;
-import org.apache.catalina.valves.RequestDumperValve;
 import org.apache.catalina.valves.ValveBase;
 import org.apache.tomcat.util.modeler.BaseModelMBean;
 
@@ -513,29 +512,6 @@ public class MBeanFactory extends BaseModelMBean {
 
 
     /**
-     * Create a new Request Dumper Valve.
-     *
-     * @param parent MBean Name of the associated parent component
-     *
-     * @exception Exception if an MBean cannot be created or registered
-     */
-    public String createRequestDumperValve(String parent)
-        throws Exception {
-
-        // Create a new RequestDumperValve instance
-        RequestDumperValve valve = new RequestDumperValve();
-
-        // Add the new instance to its parent component
-        ObjectName pname = new ObjectName(parent);
-        ContainerBase containerBase = getParentContainerFromParent(pname);
-        containerBase.addValve(valve);
-        ObjectName oname = valve.getObjectName();
-        return (oname.toString());
-
-    }
-
-
-    /**
      * Create a new Single Sign On Valve.
      *
      * @param parent MBean Name of the associated parent component
diff --git a/java/org/apache/catalina/valves/RequestDumperValve.java b/java/org/apache/catalina/valves/RequestDumperValve.java
deleted file mode 100644 (file)
index f550c3c..0000000
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.catalina.valves;
-
-
-import java.io.IOException;
-import java.util.Enumeration;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.Cookie;
-
-import org.apache.catalina.connector.Request;
-import org.apache.catalina.connector.Response;
-import org.apache.tomcat.util.res.StringManager;
-import org.apache.juli.logging.Log;
-
-
-/**
- * <p>Implementation of a Valve that logs interesting contents from the
- * specified Request (before processing) and the corresponding Response
- * (after processing).  It is especially useful in debugging problems
- * related to headers and cookies.</p>
- *
- * <p>This Valve may be attached to any Container, depending on the granularity
- * of the logging you wish to perform.</p>
- *
- * @author Craig R. McClanahan
- * @version $Revision$ $Date$
- */
-
-public class RequestDumperValve
-    extends ValveBase {
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * The descriptive information related to this implementation.
-     */
-    private static final String info =
-        "org.apache.catalina.valves.RequestDumperValve/1.0";
-
-
-    /**
-     * The StringManager for this package.
-     */
-    protected static StringManager sm =
-        StringManager.getManager(Constants.Package);
-
-
-    // ------------------------------------------------------------- Properties
-
-
-    /**
-     * Return descriptive information about this Valve implementation.
-     */
-    public String getInfo() {
-
-        return (info);
-
-    }
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    /**
-     * Log the interesting request parameters, invoke the next Valve in the
-     * sequence, and log the interesting response parameters.
-     *
-     * @param request The servlet request to be processed
-     * @param response The servlet response to be created
-     *
-     * @exception IOException if an input/output error occurs
-     * @exception ServletException if a servlet error occurs
-     */
-    public void invoke(Request request, Response response)
-        throws IOException, ServletException {
-
-        Log log = container.getLogger();
-        
-        // Log pre-service information
-        log.info("REQUEST URI       =" + request.getRequestURI());
-        log.info("          authType=" + request.getAuthType());
-        log.info(" characterEncoding=" + request.getCharacterEncoding());
-        log.info("     contentLength=" + request.getContentLength());
-        log.info("       contentType=" + request.getContentType());
-        log.info("       contextPath=" + request.getContextPath());
-        Cookie cookies[] = request.getCookies();
-        if (cookies != null) {
-            for (int i = 0; i < cookies.length; i++)
-                log.info("            cookie=" + cookies[i].getName() + "=" +
-                    cookies[i].getValue());
-        }
-        Enumeration<String> hnames = request.getHeaderNames();
-        while (hnames.hasMoreElements()) {
-            String hname = hnames.nextElement();
-            Enumeration<String> hvalues = request.getHeaders(hname);
-            while (hvalues.hasMoreElements()) {
-                String hvalue = hvalues.nextElement();
-                log.info("            header=" + hname + "=" + hvalue);
-            }
-        }
-        log.info("            locale=" + request.getLocale());
-        log.info("            method=" + request.getMethod());
-        Enumeration<String> pnames = request.getParameterNames();
-        while (pnames.hasMoreElements()) {
-            String pname = pnames.nextElement();
-            String pvalues[] = request.getParameterValues(pname);
-            StringBuffer result = new StringBuffer(pname);
-            result.append('=');
-            for (int i = 0; i < pvalues.length; i++) {
-                if (i > 0)
-                    result.append(", ");
-                result.append(pvalues[i]);
-            }
-            log.info("         parameter=" + result.toString());
-        }
-        log.info("          pathInfo=" + request.getPathInfo());
-        log.info("          protocol=" + request.getProtocol());
-        log.info("       queryString=" + request.getQueryString());
-        log.info("        remoteAddr=" + request.getRemoteAddr());
-        log.info("        remoteHost=" + request.getRemoteHost());
-        log.info("        remoteUser=" + request.getRemoteUser());
-        log.info("requestedSessionId=" + request.getRequestedSessionId());
-        log.info("            scheme=" + request.getScheme());
-        log.info("        serverName=" + request.getServerName());
-        log.info("        serverPort=" + request.getServerPort());
-        log.info("       servletPath=" + request.getServletPath());
-        log.info("          isSecure=" + request.isSecure());
-        log.info("---------------------------------------------------------------");
-
-        // Perform the request
-        getNext().invoke(request, response);
-
-        // Log post-service information
-        log.info("---------------------------------------------------------------");
-        log.info("          authType=" + request.getAuthType());
-        log.info("     contentLength=" + response.getContentLength());
-        log.info("       contentType=" + response.getContentType());
-        Cookie rcookies[] = response.getCookies();
-        for (int i = 0; i < rcookies.length; i++) {
-            log.info("            cookie=" + rcookies[i].getName() + "=" +
-                rcookies[i].getValue() + "; domain=" +
-                rcookies[i].getDomain() + "; path=" + rcookies[i].getPath());
-        }
-        Iterable<String> rhnames = response.getHeaderNames();
-        for (String rhname : rhnames) {
-            Iterable<String> rhvalues = response.getHeaders(rhname);
-            for (String rhvalue : rhvalues)
-                log.info("            header=" + rhname + "=" + rhvalue);
-        }
-        log.info("           message=" + response.getMessage());
-        log.info("        remoteUser=" + request.getRemoteUser());
-        log.info("            status=" + response.getStatus());
-        log.info("===============================================================");
-
-    }
-
-
-    /**
-     * Return a String rendering of this object.
-     */
-    public String toString() {
-
-        StringBuffer sb = new StringBuffer("RequestDumperValve[");
-        if (container != null)
-            sb.append(container.getName());
-        sb.append("]");
-        return (sb.toString());
-
-    }
-
-
-}
index 1e9c943..d4e6248 100644 (file)
 </section>
 
 
+<section name="Request Dumper Filter">
+
+  <subsection name="Introduction">
+
+    <p>The Request Dumper Filter logs information from the request and response
+    objects and is intended to be used for debugging purposes. When using this
+    Filter, it is recommended that the
+    <code>org.apache.catalina.filter.RequestDumperFilter</code> logger is
+    directed to a dedicated file and that the
+    <code>org.apache.juli.VerbatimFormmater</code> is used.</p>
+
+    <p><strong>WARNING: Using this filter has side-effects.</strong>  The
+    output from this filter includes any parameters included with the request.
+    The parameters will be decoded using the default platform encoding. Any
+    subsequent calls to <code>request.setCharacterEncoding()</code> within
+    the web application will have no effect.</p>
+    
+  </subsection>
+
+  <subsection name="Filter Class Name">
+
+    <p>The filter class name for the Request Dumper Filter is
+    <strong><code>org.apache.catalina.filters.RequestDumperFilter</code>
+    </strong>.</p>
+
+  </subsection>
+
+  <subsection name="Initialisation parameters">
+
+    <p>The Request Dumper Filter does not support any initialization
+    parameters.</p>
+
+  </subsection>
+
+  <subsection name="Sample Configuration">
+  
+    <p>The following entries in a web application's web.xml would enable the
+    Request Dumper filter for all requests for that web application. If the
+    entries were added to <code>CATALINA_BASE/conf/web.xml</code>, the Request
+    Dumper Filter would be enabled for all web applications.</p>
+    <source>
+&lt;filter&gt;
+    &lt;filter-name&gt;requestdumper&lt;/filter-name&gt;
+    &lt;filter-class&gt;
+        org.apache.catalina.filters.RequestDumperFilter
+    &lt;/filter-class&gt;
+&lt;/filter&gt;
+&lt;filter-mapping&gt;
+    &lt;filter-name&gt;requestdumper&lt;/filter-name&gt;
+    &lt;url-pattern&gt;*&lt;/url-pattern&gt;
+&lt;/filter-mapping&gt;
+    </source>
+    
+    <p>The following entries in CATALINA_BASE/conf/logging.properties would
+    create a separate log file for the Request Dumper Filter output.</p>
+    <source>
+# To this configuration below, 1request-dumper.org.apache.juli.FileHandler
+# also needs to be added to the handlers property near the top of the file
+1request-dumper.org.apache.juli.FileHandler.level = INFO
+1request-dumper.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
+1request-dumper.org.apache.juli.FileHandler.prefix = request-dumper.
+1request-dumper.org.apache.juli.FileHandler.formatter = org.apache.juli.VerbatimFormatter
+org.apache.catalina.filters.RequestDumperFilter.level = INFO
+org.apache.catalina.filters.RequestDumperFilter.handlers = 1request-dumper.org.apache.juli.FileHandler
+    </source>
+  </subsection>
+</section>
+
+
 <section name="WebDAV Fix Filter">
 
   <subsection name="Introduction">
index 6c35452..b8ecf69 100644 (file)
 </section>
 
 
-<section name="Request Dumper Valve">
-
-
-  <subsection name="Introduction">
-
-    <p>The <em>Request Dumper Valve</em> is a useful tool in debugging
-    interactions with a client application (or browser) that is sending
-    HTTP requests to your Tomcat-based server.  When configured, it causes
-    details about each request processed by its associated <code>Engine</code>, 
-    <code>Host</code>, or <code>Context</code> to be logged according to 
-    the logging configuration for that container.</p>
-
-    <p><strong>WARNING: Using this valve has side-effects.</strong>  The
-    output from this valve includes any parameters included with the request.
-    The parameters will be decoded using the default platform encoding. Any
-    subsequent calls to <code>request.setCharacterEncoding()</code> within
-    the web application will have no effect.</p>
-
-  </subsection>
-
-
-  <subsection name="Attributes">
-
-    <p>The <strong>Request Dumper Valve</strong> supports the following
-    configuration attributes:</p>
-
-    <attributes>
-
-      <attribute name="className" required="true">
-        <p>Java class name of the implementation to use.  This MUST be set to
-        <strong>org.apache.catalina.valves.RequestDumperValve</strong>.</p>
-      </attribute>
-
-    </attributes>
-
-  </subsection>
-
-
-</section>
-
-
 <section name="Single Sign On Valve">
 
   <subsection name="Introduction">
diff --git a/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java b/webapps/examples/WEB-INF/classes/filters/RequestDumperFilter.java
deleted file mode 100644 (file)
index df5faa8..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-package filters;
-
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.sql.Timestamp;
-import java.util.Enumeration;
-import java.util.Locale;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-
-
-/**
- * Example filter that dumps interesting state information about a request
- * to the associated servlet context log file, before allowing the servlet
- * to process the request in the usual way.  This can be installed as needed
- * to assist in debugging problems.
- *
- * @author Craig McClanahan
- * @version $Revision$ $Date$
- */
-
-public final class RequestDumperFilter implements Filter {
-
-
-    // ----------------------------------------------------- Instance Variables
-
-
-    /**
-     * The filter configuration object we are associated with.  If this value
-     * is null, this filter instance is not currently configured.
-     */
-    private FilterConfig filterConfig = null;
-
-
-    // --------------------------------------------------------- Public Methods
-
-
-    /**
-     * Take this filter out of service.
-     */
-    public void destroy() {
-
-        this.filterConfig = null;
-
-    }
-
-
-    /**
-     * Time the processing that is performed by all subsequent filters in the
-     * current filter stack, including the ultimately invoked servlet.
-     *
-     * @param request The servlet request we are processing
-     * @param result The servlet response we are creating
-     * @param chain The filter chain we are processing
-     *
-     * @exception IOException if an input/output error occurs
-     * @exception ServletException if a servlet error occurs
-     */
-    public void doFilter(ServletRequest request, ServletResponse response,
-                         FilterChain chain)
-       throws IOException, ServletException {
-
-        if (filterConfig == null)
-           return;
-
-       // Render the generic servlet request properties
-       StringWriter sw = new StringWriter();
-       PrintWriter writer = new PrintWriter(sw);
-       writer.println("Request Received at " +
-                      (new Timestamp(System.currentTimeMillis())));
-       writer.println(" characterEncoding=" + request.getCharacterEncoding());
-       writer.println("     contentLength=" + request.getContentLength());
-       writer.println("       contentType=" + request.getContentType());
-       writer.println("            locale=" + request.getLocale());
-       writer.print("           locales=");
-       Enumeration<Locale> locales = request.getLocales();
-       boolean first = true;
-       while (locales.hasMoreElements()) {
-           Locale locale = locales.nextElement();
-           if (first)
-               first = false;
-           else
-               writer.print(", ");
-           writer.print(locale.toString());
-       }
-       writer.println();
-       Enumeration<String> names = request.getParameterNames();
-       while (names.hasMoreElements()) {
-           String name = names.nextElement();
-           writer.print("         parameter=" + name + "=");
-           String values[] = request.getParameterValues(name);
-           for (int i = 0; i < values.length; i++) {
-               if (i > 0)
-                   writer.print(", ");
-               writer.print(values[i]);
-           }
-           writer.println();
-       }
-       writer.println("          protocol=" + request.getProtocol());
-       writer.println("        remoteAddr=" + request.getRemoteAddr());
-       writer.println("        remoteHost=" + request.getRemoteHost());
-       writer.println("            scheme=" + request.getScheme());
-       writer.println("        serverName=" + request.getServerName());
-       writer.println("        serverPort=" + request.getServerPort());
-       writer.println("          isSecure=" + request.isSecure());
-
-       // Render the HTTP servlet request properties
-       if (request instanceof HttpServletRequest) {
-           writer.println("---------------------------------------------");
-           HttpServletRequest hrequest = (HttpServletRequest) request;
-           writer.println("       contextPath=" + hrequest.getContextPath());
-           Cookie cookies[] = hrequest.getCookies();
-            if (cookies == null)
-                cookies = new Cookie[0];
-           for (int i = 0; i < cookies.length; i++) {
-               writer.println("            cookie=" + cookies[i].getName() +
-                              "=" + cookies[i].getValue());
-           }
-           names = hrequest.getHeaderNames();
-           while (names.hasMoreElements()) {
-               String name = names.nextElement();
-               String value = hrequest.getHeader(name);
-               writer.println("            header=" + name + "=" + value);
-           }
-           writer.println("            method=" + hrequest.getMethod());
-           writer.println("          pathInfo=" + hrequest.getPathInfo());
-           writer.println("       queryString=" + hrequest.getQueryString());
-           writer.println("        remoteUser=" + hrequest.getRemoteUser());
-           writer.println("requestedSessionId=" +
-                          hrequest.getRequestedSessionId());
-           writer.println("        requestURI=" + hrequest.getRequestURI());
-           writer.println("       servletPath=" + hrequest.getServletPath());
-       }
-       writer.println("=============================================");
-
-       // Log the resulting string
-       writer.flush();
-       filterConfig.getServletContext().log(sw.getBuffer().toString());
-
-       // Pass control on to the next filter
-        chain.doFilter(request, response);
-
-    }
-
-
-    /**
-     * Place this filter into service.
-     *
-     * @param filterConfig The filter configuration object
-     */
-    public void init(FilterConfig filterConfig) throws ServletException {
-
-       this.filterConfig = filterConfig;
-
-    }
-
-
-    /**
-     * Return a String representation of this object.
-     */
-    public String toString() {
-
-       if (filterConfig == null)
-           return ("RequestDumperFilter()");
-       StringBuffer sb = new StringBuffer("RequestDumperFilter(");
-       sb.append(filterConfig);
-       sb.append(")");
-       return (sb.toString());
-
-    }
-
-
-}
-
index ea64cb2..d3a6849 100644 (file)
@@ -39,7 +39,7 @@
 
     <filter>
         <filter-name>Request Dumper Filter</filter-name>
-        <filter-class>filters.RequestDumperFilter</filter-class>
+        <filter-class>org.apache.catalina.filters.RequestDumperFilter</filter-class>
     </filter>
 
     <!-- Example filter to set character encoding on each request -->