1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.action;
17
18 import org.apache.log4j.Logger;
19 import org.apache.struts.Globals;
20 import org.apache.struts.action.Action;
21 import org.apache.struts.action.ActionForm;
22 import org.apache.struts.action.ActionForward;
23 import org.apache.struts.action.ActionMapping;
24 import org.kuali.rice.core.api.util.RiceConstants;
25 import org.kuali.rice.kns.util.IncidentReportUtils;
26 import org.kuali.rice.kns.web.struts.form.KualiExceptionIncidentForm;
27 import org.kuali.rice.krad.exception.KualiExceptionIncident;
28 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29 import org.kuali.rice.krad.service.KualiExceptionIncidentService;
30 import org.kuali.rice.krad.util.KRADConstants;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.util.Enumeration;
35 import java.util.HashMap;
36 import java.util.Map;
37
38
39
40
41
42
43
44 @Deprecated
45 public class KualiExceptionHandlerAction extends Action {
46 private static final Logger LOG = Logger
47 .getLogger(KualiExceptionHandlerAction.class);
48
49
50
51
52
53
54
55
56
57
58
59 public ActionForward execute(ActionMapping mapping, ActionForm form,
60 HttpServletRequest request, HttpServletResponse response)
61 throws Exception {
62 return executeException(mapping, form, request, response);
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public ActionForward executeException(ActionMapping mapping,
79 ActionForm form, HttpServletRequest request,
80 HttpServletResponse response) throws Exception {
81
82 if (LOG.isDebugEnabled()) {
83 String lm = String.format("ENTRY %s%n%s", form.getClass()
84 .getSimpleName(), request.getRequestURI());
85 LOG.debug(lm);
86 }
87
88
89 Exception e = (Exception) request.getAttribute(Globals.EXCEPTION_KEY);
90
91
92 ActionForward returnForward = null;
93
94
95
96
97 if (e == null) {
98 if (form instanceof KualiExceptionIncidentForm) {
99 KualiExceptionIncidentForm formObject = (KualiExceptionIncidentForm) form;
100
101 if (!formObject.isCancel()) {
102
103
104
105
106
107
108 KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb
109 .getKualiExceptionIncidentService();
110
111
112
113 Map reducedMap = new HashMap();
114 Enumeration<String> names = request.getParameterNames();
115 while (names.hasMoreElements()) {
116 String name = names.nextElement();
117 reducedMap.put(name, request.getParameter(name));
118 }
119 KualiExceptionIncident exceptionIncident = reporterService
120 .getExceptionIncident(reducedMap);
121
122 reporterService.report(exceptionIncident);
123 } else {
124
125 ActionForward cancelForward = mapping
126 .findForward(KRADConstants.MAPPING_CANCEL);
127 if (cancelForward == null) {
128 cancelForward = returnForward;
129 } else {
130 returnForward = cancelForward;
131 }
132 }
133 }
134 } else {
135
136 returnForward = processException(mapping, form, request, e);
137 }
138
139
140 if (returnForward == null) {
141 returnForward = mapping.findForward(KRADConstants.MAPPING_CLOSE);
142 }
143
144 if (LOG.isDebugEnabled()) {
145 String lm = String.format("EXIT %s",
146 (returnForward == null) ? "null" : returnForward.getPath());
147 LOG.debug(lm);
148 }
149
150 return returnForward;
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168 @SuppressWarnings("unchecked")
169 protected ActionForward processException(ActionMapping mapping,
170 ActionForm form, HttpServletRequest request, Exception exception)
171 throws Exception {
172
173
174 KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb
175 .getKualiExceptionIncidentService();
176
177 Map<String, String> properties = (Map<String, String>) request
178 .getAttribute(IncidentReportUtils.EXCEPTION_PROPERTIES);
179
180 KualiExceptionIncident ei = reporterService.getExceptionIncident(
181 exception, properties);
182
183 request.setAttribute(KualiExceptionHandlerAction.class
184 .getSimpleName(), ei.toProperties());
185 return mapping.findForward(RiceConstants.MAPPING_BASIC);
186 }
187 }