|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+package com.chinaitop.depot;
|
|
|
2
|
+
|
|
|
3
|
+import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
|
|
4
|
+import com.alibaba.druid.util.Utils;
|
|
|
5
|
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
6
|
+import org.springframework.context.annotation.Bean;
|
|
|
7
|
+import org.springframework.context.annotation.Configuration;
|
|
|
8
|
+import javax.servlet.*;
|
|
|
9
|
+import java.io.IOException;
|
|
|
10
|
+
|
|
|
11
|
+/**
|
|
|
12
|
+ * druid配置
|
|
|
13
|
+ *
|
|
|
14
|
+ * @date 2024/06/05
|
|
|
15
|
+ **/
|
|
|
16
|
+@Configuration
|
|
|
17
|
+public class DruidConfigure {
|
|
|
18
|
+
|
|
|
19
|
+ /**
|
|
|
20
|
+ * 去除druid监控页面广告
|
|
|
21
|
+ */
|
|
|
22
|
+ @SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
23
|
+ @Bean
|
|
|
24
|
+ public FilterRegistrationBean removeDruidAdFilterRegistrationBean(DruidStatProperties properties)
|
|
|
25
|
+ {
|
|
|
26
|
+ // 获取web监控页面的参数
|
|
|
27
|
+ DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
|
|
28
|
+ // 提取common.js的配置路径
|
|
|
29
|
+ String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
|
|
|
30
|
+ String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
|
|
31
|
+ final String filePath = "support/http/resources/js/common.js";
|
|
|
32
|
+ // 创建filter进行过滤
|
|
|
33
|
+ Filter filter = new Filter()
|
|
|
34
|
+ {
|
|
|
35
|
+ @Override
|
|
|
36
|
+ public void init(FilterConfig filterConfig) throws ServletException
|
|
|
37
|
+ {
|
|
|
38
|
+ }
|
|
|
39
|
+ @Override
|
|
|
40
|
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
41
|
+ throws IOException, ServletException
|
|
|
42
|
+ {
|
|
|
43
|
+ chain.doFilter(request, response);
|
|
|
44
|
+ // 重置缓冲区,响应头不会被重置
|
|
|
45
|
+ response.resetBuffer();
|
|
|
46
|
+ // 获取common.js
|
|
|
47
|
+ String text = Utils.readFromResource(filePath);
|
|
|
48
|
+ // 正则替换banner, 除去底部的广告信息
|
|
|
49
|
+ text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
|
|
50
|
+ text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
|
|
51
|
+ response.getWriter().write(text);
|
|
|
52
|
+ }
|
|
|
53
|
+ @Override
|
|
|
54
|
+ public void destroy()
|
|
|
55
|
+ {
|
|
|
56
|
+ }
|
|
|
57
|
+ };
|
|
|
58
|
+ FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
|
|
59
|
+ registrationBean.setFilter(filter);
|
|
|
60
|
+ registrationBean.addUrlPatterns(commonJsPattern);
|
|
|
61
|
+ return registrationBean;
|
|
|
62
|
+ }
|
|
|
63
|
+}
|