1 package com.blandware.atleap.webapp.action.core; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.apache.struts.Globals; 6 import org.apache.struts.action.ActionForm; 7 import org.apache.struts.action.ActionForward; 8 import org.apache.struts.action.ActionMapping; 9 import org.apache.struts.action.ActionMessage; 10 import org.apache.struts.action.ActionMessages; 11 import org.apache.struts.action.ExceptionHandler; 12 import org.apache.struts.config.ExceptionConfig; 13 14 import javax.servlet.ServletException ; 15 import javax.servlet.http.HttpServletRequest ; 16 import javax.servlet.http.HttpServletResponse ; 17 import java.io.PrintWriter ; 18 import java.io.StringWriter ; 19 20 21 33 public final class ActionExceptionHandler extends ExceptionHandler { 34 36 private Log log = LogFactory.getLog(ActionExceptionHandler.class); 37 38 40 56 public ActionForward execute(Exception ex, ExceptionConfig ae, 57 ActionMapping mapping, 58 ActionForm formInstance, 59 HttpServletRequest request, 60 HttpServletResponse response) 61 throws ServletException { 62 63 65 request.setAttribute(Globals.EXCEPTION_KEY, ex); 66 67 try { 68 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 69 } catch ( Exception e ) { 70 throw new ServletException (e); 71 } 72 73 return null; 74 } 75 76 86 protected void storeException(HttpServletRequest request, String property, 87 ActionMessage error, ActionForward forward) { 88 ActionMessages errors = 89 (ActionMessages) request.getAttribute(Globals.ERROR_KEY); 90 91 if ( errors == null ) { 92 errors = new ActionMessages(); 93 } 94 95 errors.add(property, error); 96 97 request.setAttribute(Globals.ERROR_KEY, errors); 98 } 99 100 105 protected void logException(Exception ex) { 106 StringWriter sw = new StringWriter (); 107 ex.printStackTrace(new PrintWriter (sw)); 108 log.error(sw.toString()); 109 } 110 } 111 | Popular Tags |