@Test public void testDoFilterCallsFilterChainDoFilterIfRequestURIDoesNotMatch() throws Exception { expect(requestMatcher.matches(servletRequest)).andReturn(false); filterChain.doFilter(servletRequest, servletResponse); expectLastCall(); replay(requestMatcher, statusProvider, servletRequest, servletResponse, filterChain); LogsearchFilter filter = new LogsearchFilter(requestMatcher, statusProvider); filter.doFilter(servletRequest, servletResponse, filterChain); verify(requestMatcher, statusProvider, servletRequest, servletResponse, filterChain); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; if (requestMatcher.matches(request)) { StatusMessage errorResponse = statusProvider.getStatusMessage(request.getRequestURI()); if (errorResponse != null) { logger.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMessage()); HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setStatus(errorResponse.getStatusCode()); resp.setContentType("application/json"); resp.getWriter().print(toJson(errorResponse)); return; } } filterChain.doFilter(servletRequest, servletResponse); }
LogsearchFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; if (requestMatcher.matches(request)) { StatusMessage errorResponse = statusProvider.getStatusMessage(request.getRequestURI()); if (errorResponse != null) { logger.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMessage()); HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setStatus(errorResponse.getStatusCode()); resp.setContentType("application/json"); resp.getWriter().print(toJson(errorResponse)); return; } } filterChain.doFilter(servletRequest, servletResponse); } }
LogsearchFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; if (requestMatcher.matches(request)) { StatusMessage errorResponse = statusProvider.getStatusMessage(request.getRequestURI()); if (errorResponse != null) { logger.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMessage()); HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setStatus(errorResponse.getStatusCode()); resp.setContentType("application/json"); resp.getWriter().print(toJson(errorResponse)); return; } } filterChain.doFilter(servletRequest, servletResponse); } LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider);  LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider, boolean enabled); }
LogsearchFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; if (requestMatcher.matches(request)) { StatusMessage errorResponse = statusProvider.getStatusMessage(request.getRequestURI()); if (errorResponse != null) { logger.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMessage()); HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setStatus(errorResponse.getStatusCode()); resp.setContentType("application/json"); resp.getWriter().print(toJson(errorResponse)); return; } } filterChain.doFilter(servletRequest, servletResponse); } LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider);  LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider, boolean enabled); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); @Override void destroy(); }
LogsearchFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; if (requestMatcher.matches(request)) { StatusMessage errorResponse = statusProvider.getStatusMessage(request.getRequestURI()); if (errorResponse != null) { logger.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMessage()); HttpServletResponse resp = (HttpServletResponse) servletResponse; resp.setStatus(errorResponse.getStatusCode()); resp.setContentType("application/json"); resp.getWriter().print(toJson(errorResponse)); return; } } filterChain.doFilter(servletRequest, servletResponse); } LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider);  LogsearchFilter(RequestMatcher requestMatcher, StatusProvider statusProvider, boolean enabled); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); @Override void destroy();  }