01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.web.servlets;
23:
24: import java.io.IOException;
25: import java.io.PrintWriter;
26: import java.net.URL;
27: import java.net.URLClassLoader;
28: import java.security.Principal;
29: import javax.naming.Context;
30: import javax.naming.InitialContext;
31: import javax.servlet.ServletConfig;
32: import javax.servlet.ServletException;
33: import javax.servlet.http.HttpServlet;
34: import javax.servlet.http.HttpServletRequest;
35: import javax.servlet.http.HttpServletResponse;
36:
37: import org.jboss.test.web.util.Util;
38:
39: /** A servlet that dumps out debugging information about its environment.
40: * @author Scott.Stark@jboss.org
41: * @version $Revision: 57211 $
42: */
43: public class DebugServlet extends HttpServlet {
44: protected void processRequest(HttpServletRequest request,
45: HttpServletResponse response) throws ServletException,
46: IOException {
47: response.setContentType("text/html");
48: PrintWriter out = response.getWriter();
49: out.println("<html>");
50: out.println("<head><title>ENCServlet</title></head>");
51: out.println("<h1>Debug Accessed</h1>");
52: out.println("<body>");
53: out.println("<h2>Call Stack</h2>");
54: out.println("<pre>");
55: Throwable t = new Throwable("Trace");
56: t.printStackTrace(out);
57: out.println("</pre>");
58: out.println("<h2>ClassLoaders</h2>");
59: ClassLoader cl = Thread.currentThread().getContextClassLoader();
60: out.println("<pre>");
61: Util.dumpClassLoader(cl, out);
62: out.println("</pre>");
63: out.println("<h2>JNDI</h2>");
64: out.println("<pre>");
65: try {
66: InitialContext iniCtx = new InitialContext();
67: super .log("InitialContext.env: " + iniCtx.getEnvironment());
68: out.println("InitialContext.env: "
69: + iniCtx.getEnvironment());
70: out.println("</pre><h3>java:comp</h3><pre>");
71: Util.showTree(" ", (Context) iniCtx.lookup("java:comp"),
72: out);
73: } catch (Exception e) {
74: super .log("Failed to create InitialContext", e);
75: e.printStackTrace(out);
76: }
77: out.println("</pre></body></html>");
78: out.close();
79: }
80:
81: protected void doGet(HttpServletRequest request,
82: HttpServletResponse response) throws ServletException,
83: IOException {
84: processRequest(request, response);
85: }
86:
87: protected void doPost(HttpServletRequest request,
88: HttpServletResponse response) throws ServletException,
89: IOException {
90: processRequest(request, response);
91: }
92: }
|