01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * 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.1 2006-09-11 12:32:06 sinisa Exp $
22: */
23:
24: package discRack.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: */
36: public class ErrorHandler implements HttpPresentation {
37:
38: /**
39: * This implements the run method in HttpPresentation.
40: *
41: * @param comms HttpPresentationComms
42: * @exception HttpPresentationException
43: */
44: public void run(HttpPresentationComms comms)
45: throws HttpPresentationException {
46:
47: ErrorHTML errorPage = (ErrorHTML) comms.xmlcFactory
48: .create(ErrorHTML.class);
49: // ErrorHTML errorPage = new ErrorHTML();
50:
51: if (null != comms.exception) {
52: StringWriter stringWriter = new StringWriter();
53: comms.exception.printStackTrace(new PrintWriter(
54: stringWriter));
55: LogChannel logChannel = Enhydra.getLogChannel();
56: int level = logChannel.getLevel("DEBUG");
57:
58: logChannel
59: .write(level,
60: "discRack.presentation.ErrorHandler stack trace = ");
61: logChannel.write(level, stringWriter.toString());
62: logChannel.write(level,
63: "discRack.presentation.ErrorHandler caught an exception - "
64: + comms.exception.toString(),
65: comms.exception);
66: errorPage.setTextStackTrace(stringWriter.toString());
67: errorPage.setTextErrorMessage(comms.exception.getMessage());
68: }
69:
70: comms.response.writeHTML(errorPage.toDocument());
71: }
72: }
|