Search in sources :

Example 16 with WebStatFilter

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

the class DruidConfiguration 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 17 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project flybiner-sso by youyouxi.

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/*");
    filterRegistrationBean.addInitParameter("profileEnable", "true");
    filterRegistrationBean.addInitParameter("principalCookieName", "USER_COOKIE");
    filterRegistrationBean.addInitParameter("principalSessionName", "USER_SESSION");
    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 18 with WebStatFilter

use of com.alibaba.druid.support.http.WebStatFilter in project neweagle-api by apgzs.

the class DruidConfiguration 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 19 with WebStatFilter

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

the class DruidStatServiceTest method test_statService_getWebURIList.

public void test_statService_getWebURIList() throws Exception {
    String uri = "/";
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    WebStatFilter filter = new WebStatFilter();
    filter.init(filterConfig);
    // first request test
    MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    filter.doFilter(request, response, chain);
    String result = DruidStatService.getInstance().service("/weburi.json");
    Map<String, Object> resultMap = (Map<String, Object>) JSONUtils.parse(result);
    List<Map<String, Object>> webURIList = (List<Map<String, Object>>) resultMap.get("Content");
    assertThat(webURIList.size(), equalTo(1));
    Map<String, Object> webURI = webURIList.get(0);
    assertThat((String) webURI.get("URI"), equalTo(uri));
    assertThat((Integer) webURI.get("RequestCount"), equalTo(1));
    // second request test
    MockHttpServletRequest request2 = new MockHttpServletRequest("GET", uri);
    MockHttpServletResponse response2 = new MockHttpServletResponse();
    MockFilterChain chain2 = new MockFilterChain();
    filter.doFilter(request2, response2, chain2);
    result = DruidStatService.getInstance().service("/weburi.json");
    resultMap = (Map<String, Object>) JSONUtils.parse(result);
    webURIList = (List<Map<String, Object>>) resultMap.get("Content");
    assertThat(webURIList.size(), equalTo(1));
    webURI = webURIList.get(0);
    assertThat((String) webURI.get("URI"), equalTo(uri));
    assertThat((Integer) webURI.get("RequestCount"), equalTo(2));
    filter.destroy();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) List(java.util.List) MockFilterChain(org.springframework.mock.web.MockFilterChain) Map(java.util.Map) 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)

Example 20 with WebStatFilter

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

the class DruidWebStatFilterConfiguration method webStatFilterRegistrationBean.

@Bean
public FilterRegistrationBean webStatFilterRegistrationBean(DruidStatProperties properties) {
    DruidStatProperties.WebStatFilter config = properties.getWebStatFilter();
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    WebStatFilter filter = new WebStatFilter();
    registrationBean.setFilter(filter);
    registrationBean.addUrlPatterns(config.getUrlPattern() != null ? config.getUrlPattern() : "/*");
    registrationBean.addInitParameter("exclusions", config.getExclusions() != null ? config.getExclusions() : "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
    if (config.getSessionStatEnable() != null) {
        registrationBean.addInitParameter("sessionStatEnable", config.getSessionStatEnable());
    }
    if (config.getSessionStatMaxCount() != null) {
        registrationBean.addInitParameter("sessionStatMaxCount", config.getSessionStatMaxCount());
    }
    if (config.getPrincipalSessionName() != null) {
        registrationBean.addInitParameter("principalSessionName", config.getPrincipalSessionName());
    }
    if (config.getPrincipalCookieName() != null) {
        registrationBean.addInitParameter("principalCookieName", config.getPrincipalCookieName());
    }
    if (config.getProfileEnable() != null) {
        registrationBean.addInitParameter("profileEnable", config.getProfileEnable());
    }
    return registrationBean;
}
Also used : DruidStatProperties(com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

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