MonitoringFilter implements Filter { private void doMonitoring(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { if (isRumMonitoring(httpRequest, httpResponse)) { return; } if (!isAllowed(httpRequest, httpResponse)) { return; } final Collector collector = filterContext.getCollector(); final MonitoringController monitoringController = new MonitoringController(collector, null); monitoringController.doActionIfNeededAndReport(httpRequest, httpResponse, filterConfig.getServletContext()); if ("stop".equalsIgnoreCase(HttpParameter.COLLECTOR.getParameterFrom(httpRequest))) { for (final Counter counter : collector.getCounters()) { counter.clear(); } if (!collector.isStopped()) { LOG.debug( "Stopping the javamelody collector in this webapp, because a collector server from " + httpRequest.getRemoteAddr() + " wants to collect the data itself"); filterContext.stopCollector(); } } } 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();  }
@Test public void testDoMonitoring() throws ServletException, IOException { monitoring(Collections.<HttpParameter, String> emptyMap()); monitoring(Collections.singletonMap(HttpParameter.FORMAT, "html")); monitoring(Collections.singletonMap(HttpParameter.FORMAT, "htmlbody")); setProperty(Parameter.DISABLED, Boolean.TRUE.toString()); try { setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); } finally { setProperty(Parameter.DISABLED, Boolean.FALSE.toString()); } setProperty(Parameter.NO_DATABASE, Boolean.TRUE.toString()); try { setUp(); monitoring(Collections.<HttpParameter, String> emptyMap()); } finally { setProperty(Parameter.NO_DATABASE, Boolean.FALSE.toString()); } setProperty(Parameter.ALLOWED_ADDR_PATTERN, "256.*"); try { setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); setProperty(Parameter.ALLOWED_ADDR_PATTERN, ".*"); setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); } finally { setProperty(Parameter.ALLOWED_ADDR_PATTERN, null); } setProperty(Parameter.AUTHORIZED_USERS, "admin:password, "); try { setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); setProperty(Parameter.AUTHORIZED_USERS, ""); setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); } finally { setProperty(Parameter.AUTHORIZED_USERS, null); } setProperty(Parameter.MONITORING_PATH, "/admin/monitoring"); try { setUp(); monitoring(Collections.<HttpParameter, String> emptyMap(), false); } finally { setProperty(Parameter.MONITORING_PATH, "/monitoring"); } try { setProperty(Parameter.JMX_EXPOSE_ENABLED, Boolean.TRUE.toString()); setUp(); monitoring(Collections.<HttpParameter, String> emptyMap()); } finally { setProperty(Parameter.JMX_EXPOSE_ENABLED, null); } }