1 28 29 package com.caucho.server.security; 30 31 import javax.servlet.Filter ; 32 import javax.servlet.FilterChain ; 33 import javax.servlet.FilterConfig ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.ServletRequest ; 36 import javax.servlet.ServletResponse ; 37 import javax.servlet.http.HttpServletResponse ; 38 import java.io.IOException ; 39 40 public class ErrorFilter implements Filter { 41 private FilterConfig _config; 42 private int _errorCode; 43 private ServletException _exception; 44 45 public void setErrorCode(int code) 46 { 47 _errorCode = code; 48 } 49 50 public void setException(ServletException exception) 51 { 52 _exception = exception; 53 } 54 55 public void init(FilterConfig config) 56 { 57 _config = config; 58 } 59 60 public void destroy() 61 { 62 } 63 64 public void doFilter(ServletRequest request, 65 ServletResponse response, 66 FilterChain chain) 67 throws ServletException , IOException 68 { 69 HttpServletResponse res = (HttpServletResponse ) response; 70 71 if (_exception != null) 72 throw _exception; 73 else if (_errorCode != 0) 74 res.sendError(_errorCode, null); 75 else 76 res.sendError(500, "configuration error"); 77 } 78 } 79 | Popular Tags |