Search in sources :

Example 21 with StatViewServlet

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 22 with StatViewServlet

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());
}
Also used : MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Example 23 with StatViewServlet

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;
}
Also used : DruidStatProperties(com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

StatViewServlet (com.alibaba.druid.support.http.StatViewServlet)23 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)13 Bean (org.springframework.context.annotation.Bean)13 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)11 MockServletConfig (org.springframework.mock.web.MockServletConfig)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 HashMap (java.util.HashMap)2 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)2 DruidStatProperties (com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties)1 ServletListenerRegistrationBean (org.springframework.boot.web.servlet.ServletListenerRegistrationBean)1