001: /**
002: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
003: * All Rights Reserved.
004: *
005: * This file is part of jWebApp.
006: *
007: * jWebApp is free software; you can redistribute it and/or modify it under
008: * the terms of the GNU General Public License (Version 2) as published by
009: * the Free Software Foundation.
010: *
011: * jWebApp is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with jWebApp; if not, write to the Free Software Foundation,
018: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019: */package jwebapp.request;
020:
021: import java.io.IOException;
022: import java.io.PrintWriter;
023: import java.util.Date;
024: import java.util.Enumeration;
025: import java.util.Iterator;
026: import java.util.Vector;
027: import javax.servlet.http.Cookie;
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import javax.servlet.http.HttpSession;
031: import jwebapp.controller.ServerInterface;
032: import jwebapp.controller.RequestHandler;
033:
034: /**
035: * Provides all the information associated with a web request and is useful in debugging.
036: * Performs no function other then to display request related information.
037: */
038: public class RequestViewer extends RequestHandler {
039: public String processRequest(ServerInterface serverInterface)
040: throws IOException {
041: HttpServletRequest request = serverInterface
042: .getServletRequest();
043: HttpServletResponse response = serverInterface
044: .getServletResponse();
045: PrintWriter out = response.getWriter();
046: HttpSession session = request.getSession();
047:
048: response.setContentType("text/plain");
049:
050: out.println();
051: out.println("******* Request Viewer *******");
052: out.println();
053:
054: out.println("request.getAuthType()=" + request.getAuthType());
055: out.println("request.getCharacterEncoding()="
056: + request.getCharacterEncoding());
057: out.println("request.getContentLength()="
058: + request.getContentLength());
059: out.println("request.getContextPath()="
060: + request.getContextPath());
061: out.println("request.getContentType()="
062: + request.getContentType());
063: out.println("request.getMethod()=" + request.getMethod());
064: out.println("request.getPathInfo()=" + request.getPathInfo());
065: out.println("request.getPathTranslated()="
066: + request.getPathTranslated());
067: out.println("request.getProtocol()=" + request.getProtocol());
068: out.println("request.getRemoteAddr()="
069: + request.getRemoteAddr());
070: out.println("request.getRemoteHost()="
071: + request.getRemoteHost());
072: out.println("request.getRemotePort()="
073: + request.getRemotePort());
074: out.println("serverInterface.getRemoteUser()="
075: + serverInterface.getRemoteUser());
076: out.println("request.getRequestURI()="
077: + request.getRequestURI());
078: out.println("request.getQueryString()="
079: + request.getQueryString());
080: out.println("request.getRequestURL()="
081: + request.getRequestURL());
082: out.println("request.getScheme()=" + request.getScheme());
083: out.println("request.getServerName()="
084: + request.getServerName());
085: out.println("request.getServerPort()="
086: + request.getServerPort());
087: out.println("request.getServletPath()="
088: + request.getServletPath());
089: out.println("request.isSecure()=" + request.isSecure());
090:
091: out.println();
092:
093: out.println("headers:");
094:
095: Enumeration e = request.getHeaderNames();
096:
097: while (e.hasMoreElements()) {
098: String headerName = (String) e.nextElement();
099: Enumeration e2 = request.getHeaders(headerName);
100:
101: out.println(" Header Name=" + headerName);
102:
103: while (e2.hasMoreElements()) {
104: String header = (String) e2.nextElement();
105: out.println(" " + headerName + "=" + header);
106: }
107: }
108:
109: out.println();
110:
111: out.println("attributes:");
112:
113: e = request.getAttributeNames();
114:
115: while (e.hasMoreElements()) {
116: String name = (String) e.nextElement();
117: out.println(" " + name + ": "
118: + request.getAttribute(name));
119: }
120:
121: out.println();
122:
123: out.println("parameters:");
124:
125: e = request.getParameterNames();
126:
127: while (e.hasMoreElements()) {
128: String name = (String) e.nextElement();
129: out.print(" " + name + ": ");
130:
131: String vals[] = request.getParameterValues(name);
132:
133: for (int i = 0; i < vals.length; i++)
134: out.print("[" + vals[i] + "]");
135:
136: out.println();
137: }
138:
139: out.println();
140:
141: out.println("cookies:");
142:
143: Cookie cookies[] = request.getCookies();
144:
145: if (cookies != null)
146: for (int i = 0; i < cookies.length; i++) {
147: out.println(" cookie.getName()="
148: + cookies[i].getName());
149: out.println(" cookie.getValue()="
150: + cookies[i].getValue());
151: out.println(" cookie.getVersion()="
152: + cookies[i].getVersion());
153: out.println(" cookie.getPath()="
154: + cookies[i].getPath());
155: out.println(" cookie.getComment()="
156: + cookies[i].getComment());
157: out.println(" cookie.getDomain()="
158: + cookies[i].getDomain());
159: out.println(" cookie.getMaxAge()="
160: + cookies[i].getMaxAge());
161: out.println(" cookie.getSecure()="
162: + cookies[i].getSecure());
163: }
164:
165: out.println();
166:
167: out.println("session data:");
168:
169: e = session.getAttributeNames();
170:
171: while (e.hasMoreElements()) {
172: String name = (String) e.nextElement();
173: out.println(" " + name + ": "
174: + session.getAttribute(name));
175: }
176:
177: out.println();
178:
179: out.println("file uploads:");
180:
181: String contentType = serverInterface.getServletRequest()
182: .getContentType();
183:
184: if (contentType != null
185: && contentType.toLowerCase().startsWith("multipart")) {
186: Vector formDataVector = serverInterface
187: .getMultipartFormDataVector();
188: Iterator i = formDataVector.iterator();
189:
190: while (i.hasNext()) {
191: ServerInterface.MultipartFormData formData = (ServerInterface.MultipartFormData) i
192: .next();
193:
194: out.println(" formData.getCharSet()="
195: + formData.getCharSet());
196: out.println(" formData.getContentType()="
197: + formData.getContentType());
198: out.println(" formData.getFieldName()="
199: + formData.getFieldName());
200: out.println(" formData.getName()="
201: + formData.getName());
202: out.println(" formData.getSize()="
203: + formData.getSize());
204: out.println(" formData.isFormField()="
205: + formData.isFormField());
206: out.println(" formData.isInMemory()="
207: + formData.isInMemory());
208: out.println();
209: }
210: }
211:
212: out.println();
213:
214: out.println("Session id: " + session.getId());
215: out.println("New session: " + session.isNew());
216:
217: out.println();
218:
219: out.print("Timeout: " + session.getMaxInactiveInterval());
220: out.println("(" + session.getMaxInactiveInterval() / 60
221: + " minutes)");
222:
223: out.println();
224:
225: out.print("Creation time: " + session.getCreationTime());
226: out.println("(" + new Date(session.getCreationTime()) + ")");
227: out.print("Last access time: " + session.getLastAccessedTime());
228: out
229: .println("(" + new Date(session.getLastAccessedTime())
230: + ")");
231:
232: out.println();
233:
234: out.println("session ID from cookie: "
235: + request.isRequestedSessionIdFromCookie());
236: out.println("session ID from URL: "
237: + request.isRequestedSessionIdFromURL());
238: out.println("session ID valid: "
239: + request.isRequestedSessionIdValid());
240:
241: return NO_FORWARDING;
242: }
243: }
|