use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.
the class StatViewSerlvetTest_allow method test_allow_1.
public void test_allow_1() throws Exception {
MockServletConfig servletConfig = new MockServletConfig();
servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2,xx");
StatViewServlet servlet = new StatViewServlet();
servlet.init(servletConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("128.242.127.2");
Assert.assertTrue(servlet.isPermittedRequest(request));
Assert.assertFalse(servlet.isPermittedRequest("128.242.127.3"));
}
use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.
the class StatViewServletTest_resetEnable method test_resetEnable_true.
public void test_resetEnable_true() throws Exception {
Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
MockServletConfig servletConfig = new MockServletConfig();
servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_RESET_ENABLE, "true");
StatViewServlet servlet = new StatViewServlet();
servlet.init(servletConfig);
Assert.assertTrue(DruidStatService.getInstance().isResetEnable());
}
use of com.alibaba.druid.support.http.StatViewServlet in project druid by alibaba.
the class DruidStatViewServletConfiguration method statViewServletRegistrationBean.
@Bean
public ServletRegistrationBean statViewServletRegistrationBean(DruidStatProperties properties) {
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean();
registrationBean.setServlet(new StatViewServlet());
registrationBean.addUrlMappings(config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*");
if (config.getAllow() != null) {
registrationBean.addInitParameter("allow", config.getAllow());
} else {
registrationBean.addInitParameter("allow", DEFAULT_ALLOW_IP);
}
if (config.getDeny() != null) {
registrationBean.addInitParameter("deny", config.getDeny());
}
if (config.getLoginUsername() != null) {
registrationBean.addInitParameter("loginUsername", config.getLoginUsername());
}
if (config.getLoginPassword() != null) {
registrationBean.addInitParameter("loginPassword", config.getLoginPassword());
}
if (config.getResetEnable() != null) {
registrationBean.addInitParameter("resetEnable", config.getResetEnable());
}
return registrationBean;
}
Aggregations