public void init(FilterConfig filterConfig) throws ServletException { final ServletContext servletContext = filterConfig.getServletContext(); // Store servlet context in a weakreference, for injection UpdatedGuiceFilter.servletContext = new WeakReference<ServletContext>(servletContext); // In the default pipeline, this is a noop. However, if replaced // by a managed pipeline, a lazy init will be triggered the first time // dispatch occurs. FilterPipeline filterPipeline = getFilterPipeline(); filterPipeline.initPipeline(servletContext); }
public void destroy() { try { // Destroy all registered filters & servlets in that order FilterPipeline filterPipeline = getFilterPipeline(); filterPipeline.destroyPipeline(); } finally { reset(); servletContext.clear(); } }
public void doFilter( ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { FilterPipeline filterPipeline = getFilterPipeline(); Context previous = UpdatedGuiceFilter.localContext.get(); HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; HttpServletRequest originalRequest = (previous != null) ? previous.getOriginalRequest() : request; localContext.set(new Context(originalRequest, request, response)); try { // dispatch across the servlet pipeline, ensuring web.xml's // filterchain is honored filterPipeline.dispatch(servletRequest, servletResponse, filterChain); } finally { localContext.set(previous); } }