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   * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
38   */
39  @Deprecated
40  public class StrutsExceptionIncidentHandler extends ExceptionHandler {
41      private static final Logger LOG=
42          Logger.getLogger(StrutsExceptionIncidentHandler.class);
43      
44      /**
45       * This is defined in struts-config.xml for forwarding this exception to a specified
46       * exception handler.
47       * <p>Value is exceptionIncidentHandler
48       */
49      public static final String EXCEPTION_INCIDENT_HANDLER="exceptionIncidentHandler";
50      
51      /**
52       * This overridden method extract exception information such as component name,
53       * user name and email, etc.
54       * 
55       * @see org.apache.struts.action.ExceptionHandler#execute(
56       * java.lang.Exception,
57       *  org.apache.struts.config.ExceptionConfig,
58       *   org.apache.struts.action.ActionMapping,
59       *    org.apache.struts.action.ActionForm,
60       *     javax.servlet.http.HttpServletRequest,
61       *      javax.servlet.http.HttpServletResponse)
62       */
63      public ActionForward execute(Exception exception,
64              ExceptionConfig exceptionConfig,
65              ActionMapping mapping,
66              ActionForm form,
67              HttpServletRequest request,
68              HttpServletResponse response) {
69          
70          if (LOG.isTraceEnabled()) {
71              String message=String.format("ENTRY %s", exception.getMessage());
72              LOG.trace(message);
73          }
74          
75          LOG.error("Exception being handled by Exception Handler", exception);
76  
77          String documentId="";
78          if (form instanceof KualiDocumentFormBase) {
79              KualiDocumentFormBase docForm=(KualiDocumentFormBase)form;
80              if (docForm.getDocument() != null) {
81              	documentId=docForm.getDocument().getDocumentNumber();
82              }
83          }
84          
85          Map<String, String> properties = IncidentReportUtils.populateRequestForIncidentReport(exception, documentId, form.getClass().getSimpleName(), request);
86          
87          ActionForward forward=mapping.findForward(EXCEPTION_INCIDENT_HANDLER);
88          
89          if (LOG.isTraceEnabled()) {
90              String message=String.format("ENTRY %s%n%s%n%s",
91                      exception.getMessage(),
92                      properties.toString(),
93                      (forward==null)?"null":forward.getPath());
94              LOG.trace(message);
95          }
96  
97          return forward;
98      }
99  
100 }
101