List of usage examples for javax.servlet Filter doFilter
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException;
doFilter
method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. 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 . ja v a 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, 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); }
From source file:org.ppwcode.vernacular.l10n_III.dojo.DojoDjConfigFilterTest.java
private void testDojoDjConfigFilterHelper(String type, String input, String output, String bestLocale) throws UnsupportedEncodingException, IOException, ServletException { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index.html"); MockHttpServletResponse response = new MockHttpServletResponse(); Servlet testServlet = new SimpleServlet(type, input); PassThroughFilterChain chain = new PassThroughFilterChain(testServlet); HttpSession session = request.getSession(); session.setAttribute(HttpRequestLocaleFilter.ATTRIBUTE_PREFERRED_LOCALE, LocaleHelpers.constructLocaleFromString(bestLocale)); Filter djConfigFilter = new DojoDjConfigFilter(); djConfigFilter.doFilter(request, response, chain); LOG.debug("input\n" + input); LOG.debug("output\n" + response.getContentAsString()); Assert.assertEquals(output, response.getContentAsString()); Assert.assertEquals(output.length(), response.getContentLength()); }
From source file:org.springframework.security.web.authentication.www.DigestAuthenticationFilterTests.java
private MockHttpServletResponse executeFilterInContainerSimulator(Filter filter, final ServletRequest request, final boolean expectChainToProceed) throws ServletException, IOException { final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain chain = mock(FilterChain.class); filter.doFilter(request, response, chain); verify(chain, times(expectChainToProceed ? 1 : 0)).doFilter(request, response); return response; }