1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.system;
12
13 import jakarta.inject.Inject;
14 import jakarta.servlet.http.HttpServletRequest;
15 import jakarta.servlet.http.HttpServletResponse;
16
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.springframework.web.servlet.ModelAndView;
23
24 import psiprobe.beans.RuntimeInfoAccessorBean;
25 import psiprobe.controllers.AbstractTomcatContainerController;
26 import psiprobe.model.SystemInformation;
27 import psiprobe.tools.SecurityUtils;
28
29
30
31
32 public class BaseSysInfoController extends AbstractTomcatContainerController {
33
34
35 private List<String> filterOutKeys = new ArrayList<>();
36
37
38 @Inject
39 private RuntimeInfoAccessorBean runtimeInfoAccessor;
40
41
42 private long collectionPeriod;
43
44
45
46
47
48
49 public List<String> getFilterOutKeys() {
50 return filterOutKeys;
51 }
52
53
54
55
56
57
58 public void setFilterOutKeys(List<String> filterOutKeys) {
59 this.filterOutKeys = filterOutKeys;
60 }
61
62
63
64
65
66
67 public RuntimeInfoAccessorBean getRuntimeInfoAccessor() {
68 return runtimeInfoAccessor;
69 }
70
71
72
73
74
75
76 public void setRuntimeInfoAccessor(RuntimeInfoAccessorBean runtimeInfoAccessor) {
77 this.runtimeInfoAccessor = runtimeInfoAccessor;
78 }
79
80
81
82
83
84
85 public long getCollectionPeriod() {
86 return collectionPeriod;
87 }
88
89
90
91
92
93
94 public void setCollectionPeriod(long collectionPeriod) {
95 this.collectionPeriod = collectionPeriod;
96 }
97
98 @Override
99 protected ModelAndView handleRequestInternal(HttpServletRequest request,
100 HttpServletResponse response) throws Exception {
101
102 SystemInformation systemInformation = new SystemInformation();
103 systemInformation
104 .setAppBase(getContainerWrapper().getTomcatContainer().getAppBase().getAbsolutePath());
105 systemInformation.setConfigBase(getContainerWrapper().getTomcatContainer().getConfigBase());
106
107 Map<String, String> sysProps = new HashMap<>();
108 for (String propertyName : System.getProperties().stringPropertyNames()) {
109 String propertyValue = System.getProperty(propertyName);
110 sysProps.put(propertyName, propertyValue);
111 }
112
113 if (!SecurityUtils.hasAttributeValueRole(getServletContext())) {
114 for (String key : filterOutKeys) {
115 sysProps.remove(key);
116 }
117 }
118
119 systemInformation.setSystemProperties(sysProps);
120
121 ModelAndView mv = new ModelAndView(getViewName());
122 mv.addObject("systemInformation", systemInformation);
123 mv.addObject("runtime", getRuntimeInfoAccessor().getRuntimeInformation());
124 mv.addObject("collectionPeriod", getCollectionPeriod());
125 return mv;
126 }
127
128 }