Search in sources :

Example 1 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project tesla by linking12.

the class DruidDBConfig method filterRegistrationBean.

@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new WebStatFilter());
    filterRegistrationBean.addUrlPatterns("/*");
    filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    filterRegistrationBean.addInitParameter("profileEnable", "true");
    filterRegistrationBean.addInitParameter("principalCookieName", "USER_COOKIE");
    filterRegistrationBean.addInitParameter("principalSessionName", "USER_SESSION");
    filterRegistrationBean.addInitParameter("DruidWebStatFilter", "/*");
    return filterRegistrationBean;
}
Also used : WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project Ganster-CMS by Gangster-trio.

the class DruidConfig method filterRegistrationBean.

@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    filterRegistrationBean.setFilter(new WebStatFilter());
    filterRegistrationBean.addUrlPatterns("/*");
    filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    return filterRegistrationBean;
}
Also used : WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project elephant by yanghuijava.

the class DruidConfiguration method filterRegistrationBean.

@Bean
public FilterRegistrationBean filterRegistrationBean() {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
    filterRegistrationBean.addUrlPatterns("/*");
    filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    return filterRegistrationBean;
}
Also used : WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project springboot_op by SnailFastGo.

the class DruidConfiguration method statFilter.

@Bean
public FilterRegistrationBean statFilter() {
    // 创建过滤器
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
    // 设置过滤器过滤路径
    filterRegistrationBean.addUrlPatterns("/*");
    // 忽略过滤的形式
    filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    return filterRegistrationBean;
}
Also used : WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project druid by alibaba.

the class WebStatFilterTest2 method test_lru.

public void test_lru() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filterConfig.addInitParameter(WebStatFilter.PARAM_NAME_SESSION_STAT_MAX_COUNT, "3");
    WebStatFilter filter = new WebStatFilter();
    filter.init(filterConfig);
    WebAppStat appStat = filter.getWebAppStat();
    Assert.assertEquals(3, filter.getSessionStatMaxCount());
    Assert.assertEquals(0, appStat.getSessionStatDataList().size());
    final MockHttpSession session_0 = new MockHttpSession(servletContext);
    final MockHttpSession session_1 = new MockHttpSession(servletContext);
    final MockHttpSession session_2 = new MockHttpSession(servletContext);
    final MockHttpSession session_3 = new MockHttpSession(servletContext);
    final MockHttpSession session_4 = new MockHttpSession(servletContext);
    // 第一个session请求2次
    {
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_0);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(1, appStat.getSessionStatDataList().size());
        Assert.assertEquals(1, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertTrue(appStat.getSessionStat(session_0.getId()).getLastAccessTimeMillis() > 0);
    }
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_0);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(1, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
    }
    // 第2个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_1);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(2, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
    }
    // 第3个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_2);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
    }
    // 第4个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_3);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_3.getId()).getRequestCount());
    }
    // 第5个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_4);
            }
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        Assert.assertNull(appStat.getSessionStat(session_1.getId()));
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_3.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_4.getId()).getRequestCount());
    }
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Aggregations

WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)20 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)12 Bean (org.springframework.context.annotation.Bean)12 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)11 MockFilterChain (org.springframework.mock.web.MockFilterChain)8 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 MockServletContext (org.springframework.mock.web.MockServletContext)8 Map (java.util.Map)5 List (java.util.List)4 WebAppStat (com.alibaba.druid.support.http.stat.WebAppStat)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)3 DruidStatProperties (com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties)1 UserService (com.alibaba.druid.stat.spring.UserService)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashMap (java.util.HashMap)1 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)1