e.g. Calendar Search Help
You must enter a value before pressing Search
tomcat

Class: org.apache.catalina.valves.RequestDumperValve   ©

 OK to copy?
001 /*
002  * Copyright 1999-2001,2004 The Apache Software Foundation.
003  * 
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  * 
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  * 
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 
017 
018 package org.apache.catalina.valves;
019 
020 
021 import java.io.IOException;
022 import java.util.Enumeration;
023 
024 import javax.servlet.ServletException;
025 import javax.servlet.http.Cookie;
026 
027 import org.apache.catalina.connector.Request;
028 import org.apache.catalina.connector.Response;
029 import org.apache.catalina.util.StringManager;
030 import org.apache.commons.logging.Log;
031 
032 
033 /**
034  * <p>Implementation of a Valve that logs interesting contents from the
035  * specified Request (before processing) and the corresponding Response
036  * (after processing).  It is especially useful in debugging problems
037  * related to headers and cookies.</p>
038  *
039  * <p>This Valve may be attached to any Container, depending on the granularity
040  * of the logging you wish to perform.</p>
041  *
042  * @author Craig R. McClanahan
043  * @version $Revision: 1.6 $ $Date: 2004/06/23 13:51:34 $
044  */
045 
046 public class RequestDumperValve
047     extends ValveBase {
048 
049 
050     // ----------------------------------------------------- Instance Variables
051 
052 
053     /**
054      * The descriptive information related to this implementation.
055      */
056     private static final String info =
057         "org.apache.catalina.valves.RequestDumperValve/1.0";
058 
059 
060     /**
061      * The StringManager for this package.
062      */
063     protected static StringManager sm =
064         StringManager.getManager(Constants.Package);
065 
066 
067     // ------------------------------------------------------------- Properties
068 
069 
070     /**
071      * Return descriptive information about this Valve implementation.
072      */
073     public String getInfo() {
074 
075         return (info);
076 
077     }
078 
079 
080     // --------------------------------------------------------- Public Methods
081 
082 
083     /**
084      * Log the interesting request parameters, invoke the next Valve in the
085      * sequence, and log the interesting response parameters.
086      *
087      * @param request The servlet request to be processed
088      * @param response The servlet response to be created
089      * @param context The valve context used to invoke the next valve
090      *  in the current processing pipeline
091      *
092      * @exception IOException if an input/output error occurs
093      * @exception ServletException if a servlet error occurs
094      */
095     public void invoke(Request request, Response response)
096         throws IOException, ServletException {
097 
098         Log log = container.getLogger();
099         
100         // Log pre-service information
101         log.info("REQUEST URI       =" + request.getRequestURI());
102         log.info("          authType=" + request.getAuthType());
103         log.info(" characterEncoding=" + request.getCharacterEncoding());
104         log.info("     contentLength=" + request.getContentLength());
105         log.info("       contentType=" + request.getContentType());
106         log.info("       contextPath=" + request.getContextPath());
107         Cookie cookies[] = request.getCookies();
108         if (cookies != null) {
109             for (int i = 0; i < cookies.length; i++)
110                 log.info("            cookie=" + cookies[i].getName() + "=" +
111                     cookies[i].getValue());
112         }
113         Enumeration hnames = request.getHeaderNames();
114         while (hnames.hasMoreElements()) {
115             String hname = (String) hnames.nextElement();
116             Enumeration hvalues = request.getHeaders(hname);
117             while (hvalues.hasMoreElements()) {
118                 String hvalue = (String) hvalues.nextElement();
119                 log.info("            header=" + hname + "=" + hvalue);
120             }
121         }
122         log.info("            locale=" + request.getLocale());
123         log.info("            method=" + request.getMethod());
124         Enumeration pnames = request.getParameterNames();
125         while (pnames.hasMoreElements()) {
126             String pname = (String) pnames.nextElement();
127             String pvalues[] = request.getParameterValues(pname);
128             StringBuffer result = new StringBuffer(pname);
129             result.append('=');
130             for (int i = 0; i < pvalues.length; i++) {
131                 if (i > 0)
132                     result.append(", ");
133                 result.append(pvalues[i]);
134             }
135             log.info("         parameter=" + result.toString());
136         }
137         log.info("          pathInfo=" + request.getPathInfo());
138         log.info("          protocol=" + request.getProtocol());
139         log.info("       queryString=" + request.getQueryString());
Rate140         log.info("        remoteAddr=" + request.getRemoteAddr());
141         log.info("        remoteHost=" + request.getRemoteHost());
142         log.info("        remoteUser=" + request.getRemoteUser());
143         log.info("requestedSessionId=" + request.getRequestedSessionId());
144         log.info("            scheme=" + request.getScheme());
145         log.info("        serverName=" + request.getServerName());
146         log.info("        serverPort=" + request.getServerPort());
147         log.info("       servletPath=" + request.getServletPath());
148         log.info("          isSecure=" + request.isSecure());
149         log.info("---------------------------------------------------------------");
150 
151         // Perform the request
152         getNext().invoke(request, response);
153 
154         // Log post-service information
155         log.info("---------------------------------------------------------------");
156         log.info("          authType=" + request.getAuthType());
157         log.info("     contentLength=" + response.getContentLength());
158         log.info("       contentType=" + response.getContentType());
159         Cookie rcookies[] = response.getCookies();
160         for (int i = 0; i < rcookies.length; i++) {
161             log.info("            cookie=" + rcookies[i].getName() + "=" +
162                 rcookies[i].getValue() + "; domain=" +
163                 rcookies[i].getDomain() + "; path=" + rcookies[i].getPath());
164         }
165         String rhnames[] = response.getHeaderNames();
166         for (int i = 0; i < rhnames.length; i++) {
167             String rhvalues[] = response.getHeaderValues(rhnames[i]);
168             for (int j = 0; j < rhvalues.length; j++)
169                 log.info("            header=" + rhnames[i] + "=" + rhvalues[j]);
Rate170         }
171         log.info("           message=" + response.getMessage());
172         log.info("        remoteUser=" + request.getRemoteUser());
173         log.info("            status=" + response.getStatus());
174         log.info("===============================================================");
175 
176     }
177 
178 
179     /**
180      * Return a String rendering of this object.
181      */
182     public String toString() {
183 
184         StringBuffer sb = new StringBuffer("RequestDumperValve[");
185         if (container != null)
186             sb.append(container.getName());
187         sb.append("]");
188         return (sb.toString());
189 
190     }
191 
192 
193 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
140 0% of 0
170 0% of 0