@Test public void testDoFilter() throws ServletException, IOException { setProperty(Parameter.DISPLAYED_COUNTERS, "sql"); try { setUp(); HttpServletRequest request = createNiceMock(HttpServletRequest.class); doFilter(request); setProperty(Parameter.DISPLAYED_COUNTERS, ""); setUp(); request = createNiceMock(HttpServletRequest.class); doFilter(request); setProperty(Parameter.DISPLAYED_COUNTERS, "unknown"); try { setUp(); request = createNiceMock(HttpServletRequest.class); doFilter(request); } catch (final IllegalArgumentException e) { assertNotNull("ok", e); } } finally { setProperty(Parameter.DISPLAYED_COUNTERS, null); } setProperty(Parameter.URL_EXCLUDE_PATTERN, ".*"); try { setUp(); final HttpServletRequest request = createNiceMock(HttpServletRequest.class); doFilter(request); } finally { setProperty(Parameter.URL_EXCLUDE_PATTERN, ""); } setUp(); HttpServletRequest request = createNiceMock(HttpServletRequest.class); doFilter(request); setUp(); setProperty(Parameter.LOG, TRUE); try { ((Logger) org.slf4j.LoggerFactory.getLogger(FILTER_NAME)).setLevel(Level.WARN); request = createNiceMock(HttpServletRequest.class); doFilter(request); ((Logger) org.slf4j.LoggerFactory.getLogger(FILTER_NAME)).setLevel(Level.DEBUG); request = createNiceMock(HttpServletRequest.class); doFilter(request); request = createNiceMock(HttpServletRequest.class); expect(request.getHeader("X-Forwarded-For")).andReturn("me").anyTimes(); expect(request.getQueryString()).andReturn("param1=1").anyTimes(); doFilter(request); } finally { setProperty(Parameter.LOG, null); } request = createNiceMock(HttpServletRequest.class); expect(request.getHeader("X-Requested-With")).andReturn("XMLHttpRequest"); doFilter(request); request = createNiceMock(HttpServletRequest.class); expect(request .getAttribute("org.springframework.web.servlet.HandlerMapping.bestMatchingPattern")) .andReturn("/testspringmvc").anyTimes(); doFilter(request); setProperty(Parameter.LOG, TRUE); try { final String test = "test"; request = createNiceMock(HttpServletRequest.class); doFilter(request, new UnknownError(test)); request = createNiceMock(HttpServletRequest.class); doFilter(request, new IllegalStateException(test)); } finally { setProperty(Parameter.LOG, null); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse) || monitoringDisabled || !instanceEnabled) { chain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getRequestURI().equals(getMonitoringUrl(httpRequest))) { doMonitoring(httpRequest, httpResponse); return; } if (!httpCounter.isDisplayed() || isRequestExcluded((HttpServletRequest) request)) { chain.doFilter(request, response); return; } doFilter(chain, httpRequest, httpResponse); }
MonitoringFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse) || monitoringDisabled || !instanceEnabled) { chain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getRequestURI().equals(getMonitoringUrl(httpRequest))) { doMonitoring(httpRequest, httpResponse); return; } if (!httpCounter.isDisplayed() || isRequestExcluded((HttpServletRequest) request)) { chain.doFilter(request, response); return; } doFilter(chain, httpRequest, httpResponse); } }
MonitoringFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse) || monitoringDisabled || !instanceEnabled) { chain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getRequestURI().equals(getMonitoringUrl(httpRequest))) { doMonitoring(httpRequest, httpResponse); return; } if (!httpCounter.isDisplayed() || isRequestExcluded((HttpServletRequest) request)) { chain.doFilter(request, response); return; } doFilter(chain, httpRequest, httpResponse); } MonitoringFilter(); }
MonitoringFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse) || monitoringDisabled || !instanceEnabled) { chain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getRequestURI().equals(getMonitoringUrl(httpRequest))) { doMonitoring(httpRequest, httpResponse); return; } if (!httpCounter.isDisplayed() || isRequestExcluded((HttpServletRequest) request)) { chain.doFilter(request, response); return; } doFilter(chain, httpRequest, httpResponse); } MonitoringFilter(); String getApplicationType(); void setApplicationType(final String applicationType); @Override void init(FilterConfig config); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); static void registerApplicationNodeInCollectServer(String applicationName,
			URL collectServerUrl, URL applicationNodeUrl); static void unregisterApplicationNodeInCollectServer(); }
MonitoringFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse) || monitoringDisabled || !instanceEnabled) { chain.doFilter(request, response); return; } final HttpServletRequest httpRequest = (HttpServletRequest) request; final HttpServletResponse httpResponse = (HttpServletResponse) response; if (httpRequest.getRequestURI().equals(getMonitoringUrl(httpRequest))) { doMonitoring(httpRequest, httpResponse); return; } if (!httpCounter.isDisplayed() || isRequestExcluded((HttpServletRequest) request)) { chain.doFilter(request, response); return; } doFilter(chain, httpRequest, httpResponse); } MonitoringFilter(); String getApplicationType(); void setApplicationType(final String applicationType); @Override void init(FilterConfig config); @Override void destroy(); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); static void registerApplicationNodeInCollectServer(String applicationName,
			URL collectServerUrl, URL applicationNodeUrl); static void unregisterApplicationNodeInCollectServer();  }