1 28 29 package com.caucho.server.webapp; 30 31 import com.caucho.log.Log; 32 33 import javax.servlet.FilterChain ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.ServletRequest ; 36 import javax.servlet.ServletRequestEvent ; 37 import javax.servlet.ServletRequestListener ; 38 import javax.servlet.ServletResponse ; 39 import java.io.IOException ; 40 import java.util.logging.Logger ; 41 42 46 public class DispatchFilterChain implements FilterChain { 47 private static final Logger log = Log.open(DispatchFilterChain.class); 48 49 private FilterChain _next; 51 52 private WebApp _app; 54 private ClassLoader _classLoader; 56 57 private ServletRequestListener []_requestListeners; 58 59 65 public DispatchFilterChain(FilterChain next, WebApp app) 66 { 67 _next = next; 68 _app = app; 69 _classLoader = app.getClassLoader(); 70 _requestListeners = app.getRequestListeners(); 71 } 72 73 81 public void doFilter(ServletRequest request, 82 ServletResponse response) 83 throws ServletException , IOException 84 { 85 Thread thread = Thread.currentThread(); 86 ClassLoader oldLoader = thread.getContextClassLoader(); 87 88 try { 89 thread.setContextClassLoader(_classLoader); 90 91 for (int i = 0; i < _requestListeners.length; i++) { 92 ServletRequestEvent event = new ServletRequestEvent (_app, request); 93 94 _requestListeners[i].requestInitialized(event); 95 } 96 97 _next.doFilter(request, response); 98 } finally { 99 for (int i = _requestListeners.length - 1; i >= 0; i--) { 100 ServletRequestEvent event = new ServletRequestEvent (_app, request); 101 102 _requestListeners[i].requestDestroyed(event); 103 } 104 105 thread.setContextClassLoader(oldLoader); 106 } 107 } 108 } 109 | Popular Tags |