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 39 42 public class SingleThreadServletFilterChain implements FilterChain { 43 private ServletConfigImpl _config; 45 private Servlet _servlet; 47 48 53 public SingleThreadServletFilterChain(ServletConfigImpl config) 54 { 55 if (config == null) 56 throw new NullPointerException (); 57 58 _config = config; 59 } 60 61 69 public void doFilter(ServletRequest request, 70 ServletResponse response) 71 throws ServletException , IOException 72 { 73 Servlet servlet = null; 74 75 synchronized (this) { 76 servlet = _servlet; 77 _servlet = null; 78 } 79 80 if (servlet == null) { 81 try { 82 servlet = (Servlet ) _config.createServlet(true); 83 } catch (ServletException e) { 84 throw e; 85 } catch (Exception e) { 86 throw new ServletException (e); 87 } 88 } 89 90 try { 91 servlet.service(request, response); 92 } catch (UnavailableException e) { 93 _config.setInitException(e); 94 96 throw e; 97 } 98 99 synchronized (this) { 100 if (_servlet == null) { 101 _servlet = servlet; 102 servlet = null; 103 } 104 } 105 106 if (servlet != null) 107 servlet.destroy(); 108 } 109 } 110 | Popular Tags |