View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.struts.form.pojo;
17  
18  import org.apache.log4j.Logger;
19  import org.apache.struts.action.ActionForm;
20  import org.apache.struts.action.ActionForward;
21  import org.apache.struts.action.ActionMapping;
22  import org.apache.struts.action.ExceptionHandler;
23  import org.apache.struts.config.ExceptionConfig;
24  import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
25  import org.kuali.rice.kns.util.IncidentReportUtils;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.http.HttpServletResponse;
29  import java.util.Map;
30  
31  /**
32   * This class is the exception handler for the base exception class java.lang.Throwable
33   * and is defined as global exception in the struts-config.xml. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  public class StrutsExceptionIncidentHandler extends ExceptionHandler {
39      private static final Logger LOG=
40          Logger.getLogger(StrutsExceptionIncidentHandler.class);
41      
42      /**
43       * This is defined in struts-config.xml for forwarding this exception to a specified
44       * exception handler.
45       * <p>Value is exceptionIncidentHandler
46       */
47      public static final String EXCEPTION_INCIDENT_HANDLER="exceptionIncidentHandler";
48      
49      /**
50       * This overridden method extract exception information such as component name,
51       * user name and email, etc.
52       * 
53       * @see org.apache.struts.action.ExceptionHandler#execute(
54       * java.lang.Exception,
55       *  org.apache.struts.config.ExceptionConfig,
56       *   org.apache.struts.action.ActionMapping,
57       *    org.apache.struts.action.ActionForm,
58       *     javax.servlet.http.HttpServletRequest,
59       *      javax.servlet.http.HttpServletResponse)
60       */
61      public ActionForward execute(Exception exception,
62              ExceptionConfig exceptionConfig,
63              ActionMapping mapping,
64              ActionForm form,
65              HttpServletRequest request,
66              HttpServletResponse response) {
67          
68          if (LOG.isTraceEnabled()) {
69              String message=String.format("ENTRY %s", exception.getMessage());
70              LOG.trace(message);
71          }
72          
73          LOG.error("Exception being handled by Exception Handler", exception);
74  
75          String documentId="";
76          if (form instanceof KualiDocumentFormBase) {
77              KualiDocumentFormBase docForm=(KualiDocumentFormBase)form;
78              if (docForm.getDocument() != null) {
79              	documentId=docForm.getDocument().getDocumentNumber();
80              }
81          }
82          
83          Map<String, String> properties = IncidentReportUtils.populateRequestForIncidentReport(exception, documentId, form.getClass().getSimpleName(), request);
84          
85          ActionForward forward=mapping.findForward(EXCEPTION_INCIDENT_HANDLER);
86          
87          if (LOG.isTraceEnabled()) {
88              String message=String.format("ENTRY %s%n%s%n%s",
89                      exception.getMessage(),
90                      properties.toString(),
91                      (forward==null)?"null":forward.getPath());
92              LOG.trace(message);
93          }
94  
95          return forward;
96      }
97  
98  }
99