1 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 43 public class DebugServlet extends HttpServlet 44 { 45 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 46 throws ServletException , IOException 47 { 48 response.setContentType("text/html"); 49 PrintWriter 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 t = new Throwable ("Trace"); 57 t.printStackTrace(out); 58 out.println("</pre>"); 59 out.println("<h2>ClassLoaders</h2>"); 60 ClassLoader 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 iniCtx = new InitialContext (); 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 ) iniCtx.lookup("java:comp"), out); 73 } 74 catch(Exception 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 request, HttpServletResponse response) 84 throws ServletException , IOException 85 { 86 processRequest(request, response); 87 } 88 89 protected void doPost(HttpServletRequest request, HttpServletResponse response) 90 throws ServletException , IOException 91 { 92 processRequest(request, response); 93 } 94 } 95 | Popular Tags |