KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > ExceptionHandler


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.navigation;
21
22 import javax.servlet.ServletException JavaDoc;
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.config.ExceptionConfig;
32
33 import com.sslexplorer.core.PopupException;
34 import com.sslexplorer.security.Constants;
35
36
37 /**
38  * Catches all exceptions thrown by the controller and directs to the
39  * appropriate error page.
40  *
41  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
42  */

43 public class ExceptionHandler extends org.apache.struts.action.ExceptionHandler {
44
45     final static Log log = LogFactory.getLog(ExceptionHandler.class);
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.apache.struts.action.ExceptionHandler#execute(java.lang.Exception,
51      * org.apache.struts.config.ExceptionConfig,
52      * org.apache.struts.action.ActionMapping,
53      * org.apache.struts.action.ActionForm,
54      * javax.servlet.http.HttpServletRequest,
55      * javax.servlet.http.HttpServletResponse)
56      */

57     public ActionForward execute(Exception JavaDoc ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance,
58                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws ServletException JavaDoc {
59         log.error("An error occured during action processing. ", ex);
60         if (ex instanceof PopupException) {
61             request.getSession().setAttribute(Constants.EXCEPTION, ex.getCause());
62             return mapping.findForward("popupException");
63         } else {
64             request.getSession().setAttribute(Constants.EXCEPTION, ex);
65             return mapping.findForward("exception");
66         }
67     }
68 }
69
Popular Tags