1 28 29 package com.caucho.server.dispatch; 30 31 import javax.servlet.FilterChain ; 32 import javax.servlet.Servlet ; 33 import javax.servlet.ServletException ; 34 import javax.servlet.ServletRequest ; 35 import javax.servlet.ServletResponse ; 36 import javax.servlet.UnavailableException ; 37 import java.io.IOException ; 38 import java.util.HashMap ; 39 40 43 public class ServletFilterChain implements FilterChain { 44 public static String SERVLET_NAME = "javax.servlet.error.servlet_name"; 45 46 private ServletConfigImpl _config; 48 private Servlet _servlet; 50 51 56 public ServletFilterChain(ServletConfigImpl config) 57 { 58 if (config == null) 59 throw new NullPointerException (); 60 61 _config = config; 62 } 63 64 67 public String getServletName() 68 { 69 return _config.getServletName(); 70 } 71 72 75 public HashMap <String ,String > getRoleMap() 76 { 77 return _config.getRoleMap(); 78 } 79 80 88 public void doFilter(ServletRequest request, 89 ServletResponse response) 90 throws ServletException , IOException 91 { 92 if (_servlet == null) { 93 try { 94 _servlet = (Servlet ) _config.createServlet(false); 95 } catch (ServletException e) { 96 throw e; 97 } catch (Exception e) { 98 throw new ServletException (e); 99 } 100 } 101 102 try { 103 _servlet.service(request, response); 104 } catch (UnavailableException e) { 105 _servlet = null; 106 _config.setInitException(e); 107 _config.killServlet(); 108 request.setAttribute(SERVLET_NAME, _config.getServletName()); 109 throw e; 110 } catch (ServletException e) { 111 request.setAttribute(SERVLET_NAME, _config.getServletName()); 112 throw e; 113 } catch (IOException e) { 114 request.setAttribute(SERVLET_NAME, _config.getServletName()); 115 throw e; 116 } catch (RuntimeException e) { 117 request.setAttribute(SERVLET_NAME, _config.getServletName()); 118 throw e; 119 } 120 } 121 } 122 | Popular Tags |