KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > presentation > ErrorHandler


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  * Contributor(s):
16  *
17  * $Id: ErrorHandler.java,v 1.1 2004/08/16 09:33:16 slobodan Exp $
18  */

19
20 package com.lutris.airsent.presentation;
21 import com.lutris.airsent.presentation.messenger.*;
22 import com.lutris.logging.*;
23 import com.lutris.appserver.server.httpPresentation.*;
24 import com.lutris.appserver.server.*;
25 import java.io.*;
26 import org.enhydra.xml.xmlc.XMLObject;
27 import java.lang.reflect.Method;
28 /**
29  * Class to handle exceptions not caught anywhere else in the framework of
30  * our application
31  *
32  * @author
33  * @version
34  */

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

43     public void run(HttpPresentationComms comms)
44         throws HttpPresentationException {
45     
46     java.util.Enumeration enum = comms.request.getHeaderNames();
47     while(enum.hasMoreElements()) {
48         String name = (String)enum.nextElement();
49         System.out.println("HEADER " + name + " = "+ comms.request.getHeader(name));
50     }
51     
52     
53     Class tempClass=null;
54     Object zvek= null;
55     Method errorTemp = null;
56   Method stackTemp = null;
57   
58     try{
59     Class stringClass=Class.forName("java.lang.String");
60     tempClass = Class.forName(DeviceUtils.getPageName(comms, "com.lutris.airsent.presentation.messenger.Error"));
61     zvek= comms.xmlcFactory.create(tempClass);
62     Class[] argTypeArr={stringClass};
63     errorTemp = tempClass.getMethod("setTextErrorMessage",argTypeArr);
64     stackTemp = tempClass.getMethod("setTextStackTrace",argTypeArr);
65   }catch(Exception e){}
66     
67     
68     //ErrorPage errorPage = (ErrorPage)comms.xmlcFactory.create(DeviceUtils.getPageName(comms,
69
// "com.lutris.airsent.presentation.messenger.Error"));
70

71     try{
72     if (null != comms.exception) {
73         Enhydra.getLogChannel().write(Logger.DEBUG,
74                       "Exception in Airsent",
75                       comms.exception);
76         Object [] temp={comms.exception.getMessage()};
77         errorTemp.invoke(zvek,temp);
78         //errorPage.setTextErrorMessage((comms.exception.getMessage()));
79
}
80     
81     
82     if (null != comms.exception) {
83         StringWriter stringWriter = new StringWriter();
84         
85         comms.exception.printStackTrace(new PrintWriter(stringWriter));
86   
87         LogChannel logChannel = Enhydra.getLogChannel();
88         int level = logChannel.getLevel("DEBUG");
89         
90         // Write to log
91
logChannel.write(level,
92                  "airSent.presentation.ErrorHandler stack trace = ");
93         logChannel.write(level, stringWriter.toString());
94         logChannel.write(level,
95                  "airSent.presentation.ErrorHandler caught an exception - "
96                  + comms.exception.toString(), comms.exception);
97   
98         // Write to stdout
99
System.out.print("airSent.presentation.ErrorHandler stack trace = ");
100         System.out.print(stringWriter.toString());
101         System.out.print(comms.exception.toString());
102   
103         // Write to page
104
Object [] temp1={comms.exception.getMessage()};
105         Object [] temp2={stringWriter.toString()};
106         errorTemp.invoke(zvek,temp1);
107         stackTemp.invoke(zvek,temp2);
108         //errorPage.setTextStackTrace(stringWriter.toString());
109
//errorPage.setTextErrorMessage(comms.exception.getMessage());
110
}
111   }catch (Exception e){}
112     comms.response.writeDOM((XMLObject)zvek);
113     }
114
115 }
116
117
118
119
Popular Tags