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.config.property.ConfigContext;
25 import org.kuali.rice.core.api.util.RiceConstants;
26 import org.kuali.rice.kns.util.IncidentReportUtils;
27 import org.kuali.rice.kns.web.struts.form.KualiExceptionIncidentForm;
28 import org.kuali.rice.krad.exception.ExceptionIncident;
29 import org.kuali.rice.krad.exception.KualiExceptionIncident;
30 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
31 import org.kuali.rice.krad.service.KualiExceptionIncidentService;
32 import org.kuali.rice.krad.util.GlobalVariables;
33 import org.kuali.rice.krad.util.KRADConstants;
34
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import java.util.Enumeration;
38 import java.util.HashMap;
39 import java.util.Map;
40
41
42
43
44
45
46
47 @Deprecated
48 public class KualiExceptionHandlerAction extends Action {
49 private static final Logger LOG = Logger
50 .getLogger(KualiExceptionHandlerAction.class);
51
52 private static final String EXCEPTION_TIME_STAMP = "exception-timeStamp";
53 private static final String EXCEPTION_DOCUMENT_ID = "exception-" + ExceptionIncident.DOCUMENT_ID;
54 private static final String EXCEPTION_USER_EMAIL = "exception-" + ExceptionIncident.USER_EMAIL;
55 private static final String EXCEPTION_USER_NAME = "exception-" + ExceptionIncident.USER_NAME;
56 private static final String EXCEPTION_UUID = "exception-" + ExceptionIncident.UUID;
57 private static final String EXCEPTION_COMPONENT_NAME = "exception-" + ExceptionIncident.COMPONENT_NAME;
58 private static final String EXCEPTION_EXCEPTION_REPORT_SUBJECT = "exception-" + ExceptionIncident.EXCEPTION_REPORT_SUBJECT;
59 private static final String EXCEPTION_EXCEPTION_MESSAGE = "exception-" + ExceptionIncident.EXCEPTION_MESSAGE;
60 private static final String EXCEPTION_STACK_TRACE = "exception-" + ExceptionIncident.STACK_TRACE;
61
62
63
64
65
66
67
68
69
70
71
72 public ActionForward execute(ActionMapping mapping, ActionForm form,
73 HttpServletRequest request, HttpServletResponse response)
74 throws Exception {
75 return executeException(mapping, form, request, response);
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 public ActionForward executeException(ActionMapping mapping,
92 ActionForm form, HttpServletRequest request,
93 HttpServletResponse response) throws Exception {
94
95 if (LOG.isDebugEnabled()) {
96 String lm = String.format("ENTRY %s%n%s", form.getClass()
97 .getSimpleName(), request.getRequestURI());
98 LOG.debug(lm);
99 }
100
101
102 Exception e = (Exception) request.getAttribute(Globals.EXCEPTION_KEY);
103
104
105 ActionForward returnForward = null;
106
107
108
109
110 if (e == null) {
111 if (form instanceof KualiExceptionIncidentForm) {
112 KualiExceptionIncidentForm formObject = (KualiExceptionIncidentForm) form;
113
114 if (!formObject.isCancel()) {
115
116
117
118
119
120
121 KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb
122 .getKualiExceptionIncidentService();
123
124
125
126 Map reducedMap = new HashMap();
127 Enumeration<String> names = request.getParameterNames();
128 while (names.hasMoreElements()) {
129 String name = names.nextElement();
130 reducedMap.put(name, request.getParameter(name));
131 }
132
133
134 Map<String, Object> userSessionMap = GlobalVariables.getUserSession().getObjectMap();
135
136
137 if(userSessionMap.get("EXCEPTION_TIME_STAMP").toString().equals(reducedMap.get(ExceptionIncident.STACK_TRACE))) {
138 reducedMap.put(ExceptionIncident.DOCUMENT_ID, userSessionMap.get("EXCEPTION_DOCUMENT_ID").toString());
139 reducedMap.put(ExceptionIncident.USER_EMAIL, userSessionMap.get("EXCEPTION_USER_EMAIL").toString());
140 reducedMap.put(ExceptionIncident.USER_NAME, userSessionMap.get("EXCEPTION_USER_NAME").toString());
141 reducedMap.put(ExceptionIncident.UUID, userSessionMap.get("EXCEPTION_UUID").toString());
142 reducedMap.put(ExceptionIncident.COMPONENT_NAME, userSessionMap.get("EXCEPTION_COMPONENT_NAME").toString());
143 reducedMap.put(ExceptionIncident.EXCEPTION_REPORT_SUBJECT, userSessionMap.get("EXCEPTION_EXCEPTION_REPORT_SUBJECT").toString());
144 reducedMap.put(ExceptionIncident.EXCEPTION_MESSAGE, userSessionMap.get("EXCEPTION_EXCEPTION_MESSAGE").toString());
145 reducedMap.put(ExceptionIncident.STACK_TRACE, userSessionMap.get("EXCEPTION_STACK_TRACE").toString());
146
147 } else {
148 reducedMap.put(ExceptionIncident.STACK_TRACE,"Not available.");
149 }
150
151 KualiExceptionIncident exceptionIncident = reporterService
152 .getExceptionIncident(reducedMap);
153
154
155 reporterService.report(exceptionIncident);
156 } else {
157
158 ActionForward cancelForward = mapping
159 .findForward(KRADConstants.MAPPING_CANCEL);
160 if (cancelForward == null) {
161 cancelForward = returnForward;
162 } else {
163 returnForward = cancelForward;
164 }
165 }
166 }
167 } else {
168
169 returnForward = processException(mapping, form, request, e);
170 }
171
172
173 if (returnForward == null) {
174 returnForward = mapping.findForward(KRADConstants.MAPPING_CLOSE);
175 }
176
177 if (LOG.isDebugEnabled()) {
178 String lm = String.format("EXIT %s",
179 (returnForward == null) ? "null" : returnForward.getPath());
180 LOG.debug(lm);
181 }
182
183 return returnForward;
184 }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201 @SuppressWarnings("unchecked")
202 protected ActionForward processException(ActionMapping mapping,
203 ActionForm form, HttpServletRequest request, Exception exception)
204 throws Exception {
205
206
207 KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb
208 .getKualiExceptionIncidentService();
209
210 Map<String, String> properties = (Map<String, String>) request
211 .getAttribute(IncidentReportUtils.EXCEPTION_PROPERTIES);
212
213 KualiExceptionIncident ei = reporterService.getExceptionIncident(
214 exception, properties);
215
216
217 String exceptionTimeStamp = String.valueOf(System.currentTimeMillis());
218 GlobalVariables.getUserSession().addObject("EXCEPTION_TIME_STAMP", exceptionTimeStamp);
219 GlobalVariables.getUserSession().addObject("EXCEPTION_DOCUMENT_ID", ei.getProperty(ExceptionIncident.DOCUMENT_ID));
220 GlobalVariables.getUserSession().addObject("EXCEPTION_USER_EMAIL", ei.getProperty(ExceptionIncident.USER_EMAIL));
221 GlobalVariables.getUserSession().addObject("EXCEPTION_USER_NAME", ei.getProperty(ExceptionIncident.USER_NAME));
222 GlobalVariables.getUserSession().addObject("EXCEPTION_UUID", ei.getProperty(ExceptionIncident.UUID));
223 GlobalVariables.getUserSession().addObject("EXCEPTION_COMPONENT_NAME", ei.getProperty(ExceptionIncident.COMPONENT_NAME));
224 GlobalVariables.getUserSession().addObject("EXCEPTION_EXCEPTION_REPORT_SUBJECT", ei.getProperty(ExceptionIncident.EXCEPTION_REPORT_SUBJECT));
225 GlobalVariables.getUserSession().addObject("EXCEPTION_EXCEPTION_MESSAGE", ei.getProperty(ExceptionIncident.EXCEPTION_MESSAGE));
226 GlobalVariables.getUserSession().addObject("EXCEPTION_STACK_TRACE", ei.getProperty(ExceptionIncident.STACK_TRACE));
227
228
229 if(ConfigContext.getCurrentContextConfig().isProductionEnvironment()) {
230 Map<String, String> prodProperties = ei.toProperties();
231 prodProperties.put(ExceptionIncident.DOCUMENT_ID, "");
232 prodProperties.put(ExceptionIncident.USER_EMAIL, "");
233 prodProperties.put(ExceptionIncident.USER_NAME, "");
234 prodProperties.put(ExceptionIncident.UUID, "");
235 prodProperties.put(ExceptionIncident.COMPONENT_NAME, "");
236 prodProperties.put(ExceptionIncident.EXCEPTION_REPORT_SUBJECT, "");
237 prodProperties.put(ExceptionIncident.EXCEPTION_MESSAGE, "");
238 prodProperties.put(ExceptionIncident.STACK_TRACE, exceptionTimeStamp);
239 ei = reporterService.getExceptionIncident(
240 null, prodProperties);
241 }
242
243
244 request.setAttribute(KualiExceptionHandlerAction.class
245 .getSimpleName(), ei.toProperties());
246 return mapping.findForward(RiceConstants.MAPPING_BASIC);
247 }
248 }