0
|
1 package nabble.view.lib;
|
|
2
|
|
3 import java.io.IOException;
|
|
4
|
|
5 import javax.servlet.Filter;
|
|
6 import javax.servlet.FilterChain;
|
|
7 import javax.servlet.FilterConfig;
|
|
8 import javax.servlet.ServletException;
|
|
9 import javax.servlet.ServletRequest;
|
|
10 import javax.servlet.ServletResponse;
|
|
11
|
|
12 public class NabbleErrorFilter implements Filter {
|
|
13 public static final String WORK_AROUND_ERROR_EXCEPTION = "work-around.error.exception";
|
|
14
|
|
15 public void destroy() { }
|
|
16
|
|
17 public void doFilter(ServletRequest req, ServletResponse res,
|
|
18 FilterChain chain) throws IOException, ServletException {
|
|
19
|
|
20 try {
|
|
21 chain.doFilter(req, res);
|
|
22 } catch(Exception e) {
|
|
23 req.setAttribute(WORK_AROUND_ERROR_EXCEPTION, e);
|
|
24
|
|
25 if(e instanceof RuntimeException) {
|
|
26 RuntimeException th = (RuntimeException)e;
|
|
27 throw th;
|
|
28 }
|
|
29 else if(e instanceof IOException) {
|
|
30 IOException th = (IOException)e;
|
|
31 throw th;
|
|
32 } else {
|
|
33 ServletException th = (ServletException)e;
|
|
34 if( MinorServletException.isIn(th) )
|
|
35 throw new IOException(th);
|
|
36 throw th;
|
|
37 }
|
|
38 }
|
|
39 }
|
|
40
|
|
41 public void init(FilterConfig arg0) throws ServletException { }
|
|
42
|
|
43 }
|