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:47:00 sinisa Exp $
22: */
23:
24: package transactionsDiscRack.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:
50: if (null != comms.exception) {
51: StringWriter stringWriter = new StringWriter();
52: comms.exception.printStackTrace(new PrintWriter(
53: stringWriter));
54: LogChannel logChannel = Enhydra.getLogChannel();
55: int level = logChannel.getLevel("DEBUG");
56:
57: logChannel
58: .write(level,
59: "transactionsDiscRack.presentation.ErrorHandler stack trace = ");
60: logChannel.write(level, stringWriter.toString());
61: logChannel.write(level,
62: "transactionsDiscRack.presentation.ErrorHandler caught an exception - "
63: + comms.exception.toString(),
64: comms.exception);
65: errorPage.setTextStackTrace(stringWriter.toString());
66: String m = comms.exception.getMessage();
67: if (null == m)
68: m = "NULL message";
69: errorPage.setTextErrorMessage(m);
70: }
71:
72: comms.response.writeHTML(errorPage.toDocument());
73: }
74: }
|