KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > barracudaDiscRack > presentation > ErrorHandler


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ErrorHandler.java,v 1.4 2004/12/03 14:12:34 slobodan Exp $
22  */

23
24 package barracudaDiscRack.presentation;
25
26 import com.lutris.logging.*;
27 import com.lutris.appserver.server.httpPresentation.*;
28 import com.lutris.appserver.server.*;
29 import java.io.*;
30     
31 /**
32  * Class to handle exceptions not caught anywhere else in the framework of
33  * our application
34  *
35  * @author
36  * @version
37  */

38 public class ErrorHandler implements HttpPresentation {
39     
40     /**
41      * This implements the run method in HttpPresentation.
42      *
43      * @param HttpPresentationComms
44      * @exception HttpPresentationException
45      */

46     public void run(HttpPresentationComms comms)
47         throws HttpPresentationException {
48                 ErrorHTML errorPage = (ErrorHTML)comms.xmlcFactory.create(ErrorHTML.class);
49         
50         if(null != comms.exception) {
51             StringWriter stringWriter = new StringWriter();
52             comms.exception.printStackTrace(new PrintWriter(stringWriter));
53             LogChannel logChannel = Enhydra.getLogChannel();
54             int level = logChannel.getLevel("DEBUG");
55             
56             logChannel.write(level, "discRack.presentation.ErrorHandler stack trace = ");
57             logChannel.write(level, stringWriter.toString());
58             logChannel.write(level, "discRack.presentation.ErrorHandler caught an exception - "
59                              + comms.exception.toString(), comms.exception);
60             errorPage.setTextStackTrace(stringWriter.toString());
61             errorPage.setTextErrorMessage(comms.exception.getMessage());
62         }
63         
64         comms.response.writeHTML(errorPage.toDocument());
65     }
66 }
67
Popular Tags