@Test public void testWatched() throws Exception { doReturn(true).when(registry).isWatched(Matchers.<PirasoEntryPoint>any()); filter.doFilterInternal(request, response, chain); verify(chain, times(0)).doFilter(request, response); verify(chain, times(1)).doFilter(Matchers.<ServletRequest>any(), Matchers.<ServletResponse>any()); }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try { if(requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if(request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch(RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch(Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if(requestIsWatched) { responseEntry.getElapseTime().stop(); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } }
PirasoFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try { if(requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if(request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch(RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch(Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if(requestIsWatched) { responseEntry.getElapseTime().stop(); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } } }
PirasoFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try { if(requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if(request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch(RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch(Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if(requestIsWatched) { responseEntry.getElapseTime().stop(); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } }  }
PirasoFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try { if(requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if(request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch(RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch(Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if(requestIsWatched) { responseEntry.getElapseTime().stop(); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } }  LoggerRegistry getRegistry(); }
PirasoFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { boolean requestIsWatched = getRegistry().isWatched(new PirasoHttpServletRequest(request)); HttpResponseEntry responseEntry = new HttpResponseEntry(); try { if(requestIsWatched) { responseEntry.getElapseTime().start(); ReferenceRequestEntry ref = null; try { if(request.getHeader(REQUEST_ID_HEADER) != null && request.getHeader(GROUP_ID_HEADER) != null) { ref = new ReferenceRequestEntry(); ref.setRemoteAddress(request.getRemoteAddr()); ref.setRequestId(Long.valueOf(request.getHeader(REQUEST_ID_HEADER))); ref.setGroupId(request.getHeader(GROUP_ID_HEADER)); ref.setServerName(request.getRemoteHost()); } } catch(RuntimeException e) { ref = null; } response = new PirasoResponseWrapper(response, responseEntry); PirasoContext context = new PirasoContext(new PirasoHttpServletRequest(request), getRegistry(), ref); PirasoContextHolder.setContext(context); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("request", request.hashCode()), WebEntryUtils.toEntry(request)); } } catch(Exception e) { LOG.warn(e.getMessage(), e); } try { chain.doFilter(request, response); } finally { if(requestIsWatched) { responseEntry.getElapseTime().stop(); ContextLogDispatcher.forward(Level.SCOPED, new GroupChainId("response", request.hashCode()), responseEntry); PirasoContextHolder.removeContext(); } } }  LoggerRegistry getRegistry();  }