KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > dd > web > servlets > DebugServlet


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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.ejb3.test.dd.web.servlets;
23
24 import java.io.IOException JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.net.URLClassLoader JavaDoc;
28 import java.security.Principal JavaDoc;
29 import javax.naming.Context JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31 import javax.servlet.ServletConfig JavaDoc;
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServlet JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.jboss.ejb3.test.dd.web.util.Util;
38
39 /** A servlet that dumps out debugging information about its environment.
40  * @author Scott.Stark@jboss.org
41  * @version $Revision: 37459 $
42  */

43 public class DebugServlet extends HttpServlet JavaDoc
44 {
45     protected void processRequest(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
46         throws ServletException JavaDoc, IOException JavaDoc
47     {
48         response.setContentType("text/html");
49         PrintWriter JavaDoc out = response.getWriter();
50         out.println("<html>");
51         out.println("<head><title>ENCServlet</title></head>");
52         out.println("<h1>Debug Accessed</h1>");
53         out.println("<body>");
54         out.println("<h2>Call Stack</h2>");
55         out.println("<pre>");
56         Throwable JavaDoc t = new Throwable JavaDoc("Trace");
57         t.printStackTrace(out);
58         out.println("</pre>");
59         out.println("<h2>ClassLoaders</h2>");
60         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
61         out.println("<pre>");
62         Util.dumpClassLoader(cl, out);
63         out.println("</pre>");
64         out.println("<h2>JNDI</h2>");
65         out.println("<pre>");
66         try
67         {
68             InitialContext JavaDoc iniCtx = new InitialContext JavaDoc();
69             super.log("InitialContext.env: "+iniCtx.getEnvironment());
70             out.println("InitialContext.env: "+iniCtx.getEnvironment());
71             out.println("</pre><h3>java:comp</h3><pre>");
72             Util.showTree(" ", (Context JavaDoc) iniCtx.lookup("java:comp"), out);
73         }
74         catch(Exception JavaDoc e)
75         {
76             super.log("Failed to create InitialContext", e);
77             e.printStackTrace(out);
78         }
79         out.println("</pre></body></html>");
80         out.close();
81     }
82
83     protected void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
84         throws ServletException JavaDoc, IOException JavaDoc
85     {
86         processRequest(request, response);
87     }
88
89     protected void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
90         throws ServletException JavaDoc, IOException JavaDoc
91     {
92         processRequest(request, response);
93     }
94 }
95
Popular Tags