KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > 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.1 2004/08/16 10:48:52 slobodan 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.create(ErrorHTML.class);
48     // ErrorHTML errorPage = new ErrorHTML();
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, "transactionsDiscRack.presentation.ErrorHandler stack trace = ");
57             logChannel.write(level, stringWriter.toString());
58             logChannel.write(level, "transactionsDiscRack.presentation.ErrorHandler caught an exception - "
59                              + comms.exception.toString(), comms.exception);
60            errorPage.setTextStackTrace(stringWriter.toString());
61         String JavaDoc m = comms.exception.getMessage();
62         if (null == m)
63         m = "NULL message";
64             errorPage.setTextErrorMessage(m);
65         }
66         
67        comms.response.writeHTML(errorPage.toDocument());
68     }
69 }
70
Popular Tags