IgnoredPathsFilter implements HttpServletRequestFilter { public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler) throws IOException { if (!passThrough) { String path = request.getServletPath(); String pathInfo = request.getPathInfo(); if (pathInfo != null) path += pathInfo; for (Pattern p : ignoredPatterns) { if (p.matcher(path).matches()) return false; } } return handler.service(request, response); } IgnoredPathsFilter(Collection<String> configuration); boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler handler);  }
@Test public void no_match() throws IOException { HttpServletRequest request = mockHttpServletRequest(); HttpServletResponse response = mockHttpServletResponse(); HttpServletRequestHandler handler = mockHttpServletRequestHandler(); train_getServletPath(request, "/"); train_getPathInfo(request, "barney"); train_service(handler, request, response, true); List<String> configuration = CollectionFactory.newList("/fred"); replay(); HttpServletRequestFilter filter = new IgnoredPathsFilter(configuration); assertTrue(filter.service(request, response, handler)); verify(); }
@Test public void no_path_info() throws Exception { HttpServletRequest request = mockHttpServletRequest(); HttpServletResponse response = mockHttpServletResponse(); HttpServletRequestHandler handler = mockHttpServletRequestHandler(); train_getServletPath(request, "/"); train_getPathInfo(request, null); train_service(handler, request, response, true); List<String> configuration = CollectionFactory.newList("/fred"); replay(); HttpServletRequestFilter filter = new IgnoredPathsFilter(configuration); assertTrue(filter.service(request, response, handler)); verify(); }
@Test public void path_excluded() throws Exception { HttpServletRequest request = mockHttpServletRequest(); HttpServletResponse response = mockHttpServletResponse(); HttpServletRequestHandler handler = mockHttpServletRequestHandler(); train_getServletPath(request, "/"); train_getPathInfo(request, "barney/rubble"); List<String> configuration = CollectionFactory.newList("/barney.*"); replay(); HttpServletRequestFilter filter = new IgnoredPathsFilter(configuration); assertFalse(filter.service(request, response, handler)); verify(); }