List of usage examples for javax.servlet Filter destroy
default public void destroy()
Called by the web container to indicate to a filter that it is being taken out of service.
This method is only called once all threads within the filter's doFilter method have exited or after a timeout period has passed.
From source file:base.StripesTestFixture.java
/** * This method is invoked by JUnit. <b>Do not invoke it yourself!</b> */// w w w.j a va 2 s . c om @AfterClass public static void tearDown() { for (Filter filter : CTX.getFilters()) { filter.destroy(); } }
From source file:org.ireland.jnetty.dispatch.filter.FilterManager.java
public void destroy() { ArrayList<Filter> filterList = new ArrayList<Filter>(); for (int i = 0; i < filterList.size(); i++) { Filter filter = filterList.get(i); try {//w w w .jav a 2 s . c om filter.destroy(); } catch (Throwable e) { log.warn(e.toString(), e); } } }
From source file:org.apache.catalina.core.ApplicationFilterConfig.java
/** * Set the filter definition we are configured for. This has the side * effect of instantiating an instance of the corresponding filter class. * * @param filterDef The new filter definition * * @exception ClassCastException if the specified class does not implement * the <code>javax.servlet.Filter</code> interface * @exception ClassNotFoundException if the filter class cannot be found * @exception IllegalAccessException if the filter class cannot be * publicly instantiated/*from ww w .ja v a 2s .com*/ * @exception InstantiationException if an exception occurs while * instantiating the filter object * @exception ServletException if thrown by the filter's init() method */ void setFilterDef(FilterDef filterDef) throws ClassCastException, ClassNotFoundException, IllegalAccessException, InstantiationException, ServletException { this.filterDef = filterDef; if (filterDef == null) { // Release any previously allocated filter instance if (this.filter != null) { if (System.getSecurityManager() != null) { try { SecurityUtil.doAsPrivilege("destroy", filter); SecurityUtil.remove(filter); } catch (java.lang.Exception ex) { log.error("ApplicationFilterConfig.doAsPrivilege", ex); } } else { filter.destroy(); } } this.filter = null; } else { // Allocate a new filter instance Filter filter = getFilter(); } }
From source file:org.openmrs.module.web.WebModuleUtil.java
/** * This method will destroy and remove all filters that were registered by the passed * {@link Module}/*from w w w .j a v a2s . c o m*/ * * @param module - The Module for which you want to remove and destroy filters. */ public static void unloadFilters(Module module) { // Unload Filter Mappings for (java.util.Iterator<ModuleFilterMapping> mapIter = moduleFilterMappings.iterator(); mapIter .hasNext();) { ModuleFilterMapping mapping = mapIter.next(); if (module.equals(mapping.getModule())) { mapIter.remove(); log.debug("Removed ModuleFilterMapping: " + mapping); } } // unload Filters Collection<Filter> filters = moduleFilters.get(module); if (filters != null) { try { for (Filter f : filters) { f.destroy(); } } catch (Exception e) { log.warn("An error occurred while trying to destroy and remove module Filter.", e); } log.debug("Module: " + module.getModuleId() + " successfully unloaded " + filters.size() + " filters."); moduleFilters.remove(module); for (Iterator<String> i = moduleFiltersByName.keySet().iterator(); i.hasNext();) { String filterName = i.next(); Filter filterVal = moduleFiltersByName.get(filterName); if (filters.contains(filterVal)) { i.remove(); } } } }
From source file:org.ops4j.pax.web.service.internal.FilterTest.java
@Test public void filterIsCalledOnUrlPattern() throws NamespaceException, ServletException, IOException { Servlet servlet = createMock(Servlet.class); servlet.init((ServletConfig) notNull()); servlet.destroy();/* w ww .j a va 2 s. c o m*/ Filter filter = createMock(Filter.class); filter.init((FilterConfig) notNull()); filter.doFilter((ServletRequest) notNull(), (ServletResponse) notNull(), (FilterChain) notNull()); filter.destroy(); replay(servlet, filter); HttpContext context = m_httpService.createDefaultHttpContext(); m_httpService.registerServlet("/test", servlet, null, context); m_httpService.registerFilter(filter, new String[] { "/*" }, null, context); HttpMethod method = new GetMethod("http://localhost:8080/test"); m_client.executeMethod(method); method.releaseConnection(); m_httpService.unregister("/test"); m_httpService.unregisterFilter(filter); verify(servlet, filter); }
From source file:org.ops4j.pax.web.service.internal.FilterTest.java
@Test public void filterIsCalledOnServlet() throws NamespaceException, ServletException, IOException { Servlet servlet = createMock(Servlet.class); servlet.init((ServletConfig) notNull()); servlet.destroy();//from w w w.j a v a2 s . c om Filter filter = createMock(Filter.class); filter.init((FilterConfig) notNull()); filter.doFilter((ServletRequest) notNull(), (ServletResponse) notNull(), (FilterChain) notNull()); filter.destroy(); replay(servlet, filter); HttpContext context = m_httpService.createDefaultHttpContext(); m_httpService.registerServlet("/test", servlet, null, context); m_httpService.registerFilter(filter, null, new String[] { "/test" }, context); HttpMethod method = new GetMethod("http://localhost:8080/test"); m_client.executeMethod(method); method.releaseConnection(); m_httpService.unregister("/test"); m_httpService.unregisterFilter(filter); verify(servlet, filter); }