KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > exceptions > ExceptionUtil


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: ExceptionUtil.java,v 1.3 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.exceptions;
21
22 import java.io.*;
23 import java.util.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 /**
28  * Exception utilities
29  */

30 public class ExceptionUtil {
31
32     /**
33      * log an exception as HTML
34      *
35      * @param out the target PrintWriter
36      * @param e the nestable exception to dump
37      * @param req the servlet request that spawned all this
38      */

39     public static void logExceptionAsHTML (PrintWriter out, NestableException e, HttpServletRequest req) {
40         out.println("<html>");
41         out.println("<head>");
42         out.println("<title>Unexpected exception!</title>");
43         out.println("</head>");
44         out.println("<body>");
45         
46         out.println("<h1>Error: EventException</h1>");
47         out.println("<p>There was an unexpected error while servicing this request...please contact your application administrator and notify them of the problem.");
48         out.println("<p>Error dispatching request: "+e.getMessage());
49         out.println("<p>Exception:<br>");
50         out.println("<pre>"); //csc_031103.1
51
e.printStackTrace(out);
52         out.println("</pre>"); //csc_031103.1
53
Exception rootException = NestableException.getRootException(e);
54         if (rootException!=e) {
55             out.println("<p>Root Exception:<br>");
56             out.println("<pre>"); //csc_031103.1
57
rootException.printStackTrace(out);
58             out.println("</pre>"); //csc_031103.1
59
}
60         
61         out.println("<p>Parameters:");
62         Enumeration enum = req.getParameterNames();
63         while (enum.hasMoreElements()) {
64             String key = (String) enum.nextElement();
65             String val = (String) req.getParameter(key);
66             out.println("<br>&nbsp;&nbsp;&nbsp;&nbsp;key:"+key+" value:"+val);
67         }
68
69         out.println("<br>RequestURI:"+req.getRequestURI());
70         out.println("<br>ServletPath:"+req.getServletPath());
71         out.println("<br>PathInfo:"+req.getPathInfo());
72         out.println("<br>PathTranslated:"+req.getPathTranslated());
73     
74         out.println("</body>");
75         out.println("</html>");
76     }
77
78 }
79
Popular Tags