@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)
				|| monitoringDisabled || !instanceEnabled) {
			// si ce n'est pas une requête http ou si le monitoring est désactivé, on fait suivre
			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)) {
			// si cette url est exclue ou si le counter http est désactivé, on ne monitore pas cette requête http
			chain.doFilter(request, response);
			return;
		}

		doFilter(chain, httpRequest, httpResponse);
	}
@Test
	public void testDoFilter() throws ServletException, IOException {
		// displayed-counters
		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);
		}

		// url exclue
		setProperty(Parameter.URL_EXCLUDE_PATTERN, ".*");
		try {
			setUp();
			final HttpServletRequest request = createNiceMock(HttpServletRequest.class);
			doFilter(request);
		} finally {
			setProperty(Parameter.URL_EXCLUDE_PATTERN, "");
		}

		// standard
		setUp();
		HttpServletRequest request = createNiceMock(HttpServletRequest.class);
		doFilter(request);

		// log
		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);
		}

		// ajax
		request = createNiceMock(HttpServletRequest.class);
		expect(request.getHeader("X-Requested-With")).andReturn("XMLHttpRequest");
		doFilter(request);

		// spring mvc with @RequestMapping (read in CounterRequestContext.getHttpRequestName())
		request = createNiceMock(HttpServletRequest.class);
		expect(request
				.getAttribute("org.springframework.web.servlet.HandlerMapping.bestMatchingPattern"))
						.andReturn("/testspringmvc").anyTimes();
		doFilter(request);

		// erreur système http, avec log
		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));
			// pas possibles:
			//			doFilter(createNiceMock(HttpServletRequest.class), new IOException(test));
			//			doFilter(createNiceMock(HttpServletRequest.class), new ServletException(test));
			//			doFilter(createNiceMock(HttpServletRequest.class), new Exception(test));
		} finally {
			setProperty(Parameter.LOG, null);
		}
	}