1
2
3
4
5 package pt.digitalis.dif.controller;
6
7 import pt.digitalis.dif.controller.interfaces.IDIFRequest;
8 import pt.digitalis.dif.controller.interfaces.IDIFResponse;
9 import pt.digitalis.dif.controller.interfaces.IDispatcherErrorHandler;
10 import pt.digitalis.dif.exception.controller.BusinessFlowException;
11 import pt.digitalis.dif.exception.controller.ControllerException;
12
13
14
15
16
17 abstract public class AbstractControllerErrorHandler implements IDispatcherErrorHandler {
18
19
20
21
22
23
24
25
26
27
28
29
30 abstract protected IDIFResponse buildDynamicErrorResponse(IDIFRequest originalrequest, String errorStageID,
31 Exception exception);
32
33
34
35
36
37
38
39
40
41
42 abstract protected IDIFResponse buildStaticErrorResponse(IDIFRequest originalrequest, Exception exception);
43
44
45
46
47
48 public IDIFResponse processException(IDIFRequest originalRequest, BusinessFlowException businessFlowException)
49 {
50
51 return buildDynamicErrorResponse(originalRequest, ExceptionHandlers.getExceptionHandler(businessFlowException),
52 businessFlowException);
53 }
54
55
56
57
58
59 public IDIFResponse processException(IDIFRequest originalRequest, ControllerException controllerException)
60 {
61 if (controllerException.isGeneratedFromException())
62 return buildStaticErrorResponse(originalRequest, controllerException);
63 else
64 return buildDynamicErrorResponse(originalRequest, ExceptionHandlers
65 .getExceptionHandler(controllerException), controllerException);
66 }
67
68
69
70
71
72 public IDIFResponse processException(IDIFRequest originalRequest, RuntimeException runtimeException)
73 {
74 return buildDynamicErrorResponse(originalRequest, ExceptionHandlers.getExceptionHandler(runtimeException),
75 runtimeException);
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public IDIFResponse responseWithContext(IDIFResponse response, IDIFRequest originalRequest, Exception exception)
91 {
92 response.addStageResult(IDispatcherErrorHandler.ORIGINAL_REQUEST, originalRequest);
93 response.addStageResult(IDispatcherErrorHandler.EXCEPTION, exception);
94
95 if (response.getRequest() != null)
96 response.getRequest().addAttribute(ExceptionHandlers.RAISED_EXCEPTION_ATTRIBUTE, exception);
97
98 return response;
99 }
100 }