1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.shale.examples.test.view; |
18 | |
|
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import javax.faces.component.UIViewRoot; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
|
25 | |
import org.apache.shale.view.AbstractViewController; |
26 | |
import org.apache.shale.view.faces.FacesConstants; |
27 | |
|
28 | 0 | public class Error extends AbstractViewController { |
29 | |
|
30 | 0 | private String httpErrorCode = null; |
31 | |
|
32 | 0 | private String exceptionType = null; |
33 | |
|
34 | 0 | private String message = null; |
35 | |
|
36 | 0 | private String requestUri = null; |
37 | |
|
38 | 0 | private String servletName = null; |
39 | |
|
40 | 0 | private Recorder recorder = null; |
41 | |
|
42 | |
public void prerender() { |
43 | 0 | System.out.println("Error - Removing exceptions stack"); |
44 | |
|
45 | 0 | Map requestMap = getRequestMap(); |
46 | |
|
47 | 0 | Exception exception = (Exception) requestMap |
48 | |
.get("javax.servlet.error.exception"); |
49 | |
|
50 | 0 | FacesContext facesContext = getFacesContext(); |
51 | 0 | if (facesContext == null) return; |
52 | |
|
53 | 0 | UIViewRoot root = facesContext.getViewRoot(); |
54 | 0 | if (root == null) return; |
55 | |
|
56 | 0 | List exceptions = (List) requestMap.get(FacesConstants.EXCEPTIONS_LIST); |
57 | 0 | if (exception != null && exceptions != null) { |
58 | |
|
59 | 0 | getFacesContext().getViewRoot().getAttributes().put("errors", exceptions); |
60 | 0 | requestMap.remove(FacesConstants.EXCEPTIONS_LIST); |
61 | |
|
62 | |
|
63 | 0 | Integer errorCode = (Integer) requestMap.get("javax.servlet.error.status_code"); |
64 | 0 | if (errorCode != null) { |
65 | 0 | setHttpErrorCode(errorCode.toString()); |
66 | |
} |
67 | |
|
68 | 0 | Object clazz = requestMap.get("javax.servlet.error.exception_type"); |
69 | 0 | if (clazz != null) { |
70 | 0 | setExceptionType(clazz.toString()); |
71 | |
} |
72 | 0 | setMessage((String) requestMap.get("javax.servlet.error.message")); |
73 | 0 | setRequestUri((String) requestMap |
74 | |
.get("javax.servlet.error.request_uri")); |
75 | 0 | setServletName((String) requestMap |
76 | |
.get("javax.servlet.error.servlet_name")); |
77 | |
|
78 | 0 | setRecorder((Recorder) getBean("recorder")); |
79 | |
} |
80 | |
|
81 | 0 | } |
82 | |
|
83 | |
public String getExceptionType() { |
84 | 0 | return exceptionType; |
85 | |
} |
86 | |
|
87 | |
public void setExceptionType(String exceptionType) { |
88 | 0 | this.exceptionType = exceptionType; |
89 | 0 | } |
90 | |
|
91 | |
public String getHttpErrorCode() { |
92 | 0 | return httpErrorCode; |
93 | |
} |
94 | |
|
95 | |
public void setHttpErrorCode(String httpErrorCode) { |
96 | 0 | this.httpErrorCode = httpErrorCode; |
97 | 0 | } |
98 | |
|
99 | |
public String getMessage() { |
100 | 0 | return message; |
101 | |
} |
102 | |
|
103 | |
public void setMessage(String message) { |
104 | 0 | this.message = message; |
105 | 0 | } |
106 | |
|
107 | |
public String getRequestUri() { |
108 | 0 | return requestUri; |
109 | |
} |
110 | |
|
111 | |
public void setRequestUri(String requestUri) { |
112 | 0 | this.requestUri = requestUri; |
113 | 0 | } |
114 | |
|
115 | |
public String getServletName() { |
116 | 0 | return servletName; |
117 | |
} |
118 | |
|
119 | |
public void setServletName(String servletName) { |
120 | 0 | this.servletName = servletName; |
121 | 0 | } |
122 | |
|
123 | |
public Recorder getRecorder() { |
124 | 0 | return recorder; |
125 | |
} |
126 | |
|
127 | |
public void setRecorder(Recorder recorder) { |
128 | 0 | this.recorder = recorder; |
129 | 0 | } |
130 | |
|
131 | |
public String getStackTrace() { |
132 | 0 | StringBuffer buff = new StringBuffer(); |
133 | 0 | Exception e = (Exception) getBean("e"); |
134 | 0 | for (int i = 0; i < e.getStackTrace().length; i++) { |
135 | 0 | buff.append(e.getStackTrace()[i].toString()) |
136 | |
.append("\n"); |
137 | |
} |
138 | 0 | return buff.toString(); |
139 | |
} |
140 | |
} |