001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: ErrorHandler.java,v 1.1 2006-09-11 12:29:11 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation;
021:
022: import com.lutris.airsent.presentation.messenger.*;
023: import com.lutris.logging.*;
024: import com.lutris.appserver.server.httpPresentation.*;
025: import com.lutris.appserver.server.*;
026: import java.io.*;
027: import org.enhydra.xml.xmlc.XMLObject;
028: import java.lang.reflect.Method;
029:
030: /**
031: * Class to handle exceptions not caught anywhere else in the framework of
032: * our application
033: *
034: * @author
035: * @version
036: */
037: public class ErrorHandler implements HttpPresentation {
038:
039: /**
040: * This implements the run method in HttpPresentation.
041: *
042: * @param HttpPresentationComms
043: * @exception HttpPresentationException
044: */
045: public void run(HttpPresentationComms comms)
046: throws HttpPresentationException {
047:
048: java.util.Enumeration enumeration = comms.request
049: .getHeaderNames();
050: while (enumeration.hasMoreElements()) {
051: String name = (String) enumeration.nextElement();
052: System.out.println("HEADER " + name + " = "
053: + comms.request.getHeader(name));
054: }
055:
056: Class tempClass = null;
057: Object zvek = null;
058: Method errorTemp = null;
059: Method stackTemp = null;
060:
061: try {
062: Class stringClass = Class.forName("java.lang.String");
063: tempClass = Class.forName(DeviceUtils.getPageName(comms,
064: "com.lutris.airsent.presentation.messenger.Error"));
065: zvek = comms.xmlcFactory.create(tempClass);
066: Class[] argTypeArr = { stringClass };
067: errorTemp = tempClass.getMethod("setTextErrorMessage",
068: argTypeArr);
069: stackTemp = tempClass.getMethod("setTextStackTrace",
070: argTypeArr);
071: } catch (Exception e) {
072: }
073:
074: //ErrorPage errorPage = (ErrorPage)comms.xmlcFactory.create(DeviceUtils.getPageName(comms,
075: // "com.lutris.airsent.presentation.messenger.Error"));
076:
077: try {
078: if (null != comms.exception) {
079: Enhydra.getLogChannel().write(Logger.DEBUG,
080: "Exception in Airsent", comms.exception);
081: Object[] temp = { comms.exception.getMessage() };
082: errorTemp.invoke(zvek, temp);
083: //errorPage.setTextErrorMessage((comms.exception.getMessage()));
084: }
085:
086: if (null != comms.exception) {
087: StringWriter stringWriter = new StringWriter();
088:
089: comms.exception.printStackTrace(new PrintWriter(
090: stringWriter));
091:
092: LogChannel logChannel = Enhydra.getLogChannel();
093: int level = logChannel.getLevel("DEBUG");
094:
095: // Write to log
096: logChannel
097: .write(level,
098: "airSent.presentation.ErrorHandler stack trace = ");
099: logChannel.write(level, stringWriter.toString());
100: logChannel.write(level,
101: "airSent.presentation.ErrorHandler caught an exception - "
102: + comms.exception.toString(),
103: comms.exception);
104:
105: // Write to stdout
106: System.out
107: .print("airSent.presentation.ErrorHandler stack trace = ");
108: System.out.print(stringWriter.toString());
109: System.out.print(comms.exception.toString());
110:
111: // Write to page
112: Object[] temp1 = { comms.exception.getMessage() };
113: Object[] temp2 = { stringWriter.toString() };
114: errorTemp.invoke(zvek, temp1);
115: stackTemp.invoke(zvek, temp2);
116: //errorPage.setTextStackTrace(stringWriter.toString());
117: //errorPage.setTextErrorMessage(comms.exception.getMessage());
118: }
119: } catch (Exception e) {
120: }
121: comms.response.writeDOM((XMLObject) zvek);
122: }
123:
124: }
|