001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kns.web.struts.form.pojo; 017 018import org.apache.log4j.Logger; 019import org.apache.struts.action.ActionForm; 020import org.apache.struts.action.ActionForward; 021import org.apache.struts.action.ActionMapping; 022import org.apache.struts.action.ExceptionHandler; 023import org.apache.struts.config.ExceptionConfig; 024import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase; 025import org.kuali.rice.kns.util.IncidentReportUtils; 026 027import javax.servlet.http.HttpServletRequest; 028import javax.servlet.http.HttpServletResponse; 029import java.util.Map; 030 031/** 032 * This class is the exception handler for the base exception class java.lang.Throwable 033 * and is defined as global exception in the struts-config.xml. 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 * 037 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework. 038 */ 039@Deprecated 040public class StrutsExceptionIncidentHandler extends ExceptionHandler { 041 private static final Logger LOG= 042 Logger.getLogger(StrutsExceptionIncidentHandler.class); 043 044 /** 045 * This is defined in struts-config.xml for forwarding this exception to a specified 046 * exception handler. 047 * <p>Value is exceptionIncidentHandler 048 */ 049 public static final String EXCEPTION_INCIDENT_HANDLER="exceptionIncidentHandler"; 050 051 /** 052 * This overridden method extract exception information such as component name, 053 * user name and email, etc. 054 * 055 * @see org.apache.struts.action.ExceptionHandler#execute( 056 * java.lang.Exception, 057 * org.apache.struts.config.ExceptionConfig, 058 * org.apache.struts.action.ActionMapping, 059 * org.apache.struts.action.ActionForm, 060 * javax.servlet.http.HttpServletRequest, 061 * javax.servlet.http.HttpServletResponse) 062 */ 063 public ActionForward execute(Exception exception, 064 ExceptionConfig exceptionConfig, 065 ActionMapping mapping, 066 ActionForm form, 067 HttpServletRequest request, 068 HttpServletResponse response) { 069 070 if (LOG.isTraceEnabled()) { 071 String message=String.format("ENTRY %s", exception.getMessage()); 072 LOG.trace(message); 073 } 074 075 LOG.error("Exception being handled by Exception Handler", exception); 076 077 String documentId=""; 078 if (form instanceof KualiDocumentFormBase) { 079 KualiDocumentFormBase docForm=(KualiDocumentFormBase)form; 080 if (docForm.getDocument() != null) { 081 documentId=docForm.getDocument().getDocumentNumber(); 082 } 083 } 084 085 Map<String, String> properties = IncidentReportUtils.populateRequestForIncidentReport(exception, documentId, form.getClass().getSimpleName(), request); 086 087 ActionForward forward=mapping.findForward(EXCEPTION_INCIDENT_HANDLER); 088 089 if (LOG.isTraceEnabled()) { 090 String message=String.format("ENTRY %s%n%s%n%s", 091 exception.getMessage(), 092 properties.toString(), 093 (forward==null)?"null":forward.getPath()); 094 LOG.trace(message); 095 } 096 097 return forward; 098 } 099 100} 101