1
2
3
4
5
6
7
8
9
10
11 package psiprobe;
12
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Locale;
18 import java.util.Map;
19 import java.util.Properties;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.FactoryBean;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.beans.factory.config.PropertiesFactoryBean;
26 import org.springframework.context.MessageSource;
27 import org.springframework.context.annotation.Bean;
28 import org.springframework.context.annotation.ComponentScan;
29 import org.springframework.context.annotation.Configuration;
30 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
31 import org.springframework.context.support.ReloadableResourceBundleMessageSource;
32 import org.springframework.core.io.ClassPathResource;
33 import org.springframework.web.servlet.HandlerMapping;
34 import org.springframework.web.servlet.LocaleResolver;
35 import org.springframework.web.servlet.ThemeResolver;
36 import org.springframework.web.servlet.ViewResolver;
37 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
38 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
39 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
40 import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
41 import org.springframework.web.servlet.i18n.CookieLocaleResolver;
42 import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
43 import org.springframework.web.servlet.theme.FixedThemeResolver;
44 import org.springframework.web.servlet.view.InternalResourceViewResolver;
45 import org.springframework.web.servlet.view.JstlView;
46
47 import psiprobe.beans.ClusterWrapperBean;
48 import psiprobe.beans.ContainerListenerBean;
49 import psiprobe.beans.ContainerWrapperBean;
50 import psiprobe.beans.JBossResourceResolverBean;
51 import psiprobe.beans.JvmMemoryInfoAccessorBean;
52 import psiprobe.beans.LogResolverBean;
53 import psiprobe.beans.ResourceResolver;
54 import psiprobe.beans.ResourceResolverBean;
55 import psiprobe.beans.RuntimeInfoAccessorBean;
56 import psiprobe.tools.Mailer;
57
58
59
60
61 @EnableWebMvc
62 @Configuration
63 @ComponentScan(basePackages = {"psiprobe"})
64 public class ProbeConfig implements WebMvcConfigurer {
65
66
67 private static final Logger logger = LoggerFactory.getLogger(ProbeConfig.class);
68
69
70
71
72
73
74 @Bean(name = "containerListener")
75 public ContainerListenerBean getContainerListenerBean() {
76 logger.debug("Instantiated containerListener");
77 return new ContainerListenerBean();
78 }
79
80
81
82
83
84
85 @Bean(name = "containerWrapper")
86 public ContainerWrapperBean getContainerWrapperBean() {
87 logger.debug("Instantiated containerWrapper");
88 return new ContainerWrapperBean();
89 }
90
91
92
93
94
95
96 @Bean(name = "clusterWrapper")
97 public ClusterWrapperBean getClusterWrapperBean() {
98 logger.debug("Instantiated clusterWrapper");
99 return new ClusterWrapperBean();
100 }
101
102
103
104
105
106
107 @Bean(name = "mailer")
108 public Mailer getMailer() {
109 logger.debug("Instantiated mailer");
110 return new Mailer();
111 }
112
113
114
115
116
117
118 @Bean(name = "datasourceMappers")
119 public List<String> getDefaultRes() {
120 logger.debug("Instantiated datasourceMappers");
121 List<String> list = new ArrayList<>();
122 list.add("psiprobe.beans.accessors.C3P0DatasourceAccessor");
123 list.add("psiprobe.beans.accessors.Dbcp2DatasourceAccessor");
124 list.add("psiprobe.beans.accessors.HikariCpDatasourceAccessor");
125 list.add("psiprobe.beans.accessors.OracleDatasourceAccessor");
126 list.add("psiprobe.beans.accessors.OracleUcpDatasourceAccessor");
127 list.add("psiprobe.beans.accessors.OpenEjbBasicDatasourceAccessor");
128 list.add("psiprobe.beans.accessors.OpenEjbManagedDatasourceAccessor");
129 list.add("psiprobe.beans.accessors.Tomcat10DbcpDatasourceAccessor");
130 list.add("psiprobe.beans.accessors.Tomcat11DbcpDatasourceAccessor");
131 list.add("psiprobe.beans.accessors.TomcatJdbcPoolDatasourceAccessor");
132 list.add("psiprobe.beans.accessors.TomEeJdbcPoolDatasourceAccessor");
133 list.add("psiprobe.beans.accessors.ViburCpDatasourceAccessor");
134 return list;
135 }
136
137
138
139
140
141
142 @Bean(name = "default")
143 public ResourceResolverBean getResourceResolverBean() {
144 logger.debug("Instantiated default resourceResolverBean");
145 return new ResourceResolverBean();
146 }
147
148
149
150
151
152
153 @Bean(name = "jboss")
154 public JBossResourceResolverBean getJBossResourceResolverBean() {
155 logger.debug("Instantiated jbossResourceResolverBean");
156 return new JBossResourceResolverBean();
157 }
158
159
160
161
162
163
164
165
166
167 @Bean(name = "resourceResolvers")
168 public Map<String, ResourceResolver> getResourceResolvers(
169 @Autowired JBossResourceResolverBean jbossResourceResolverBean,
170 @Autowired ResourceResolverBean resourceResolverBean) {
171 logger.debug("Instantiated resourceResolvers");
172 Map<String, ResourceResolver> map = new HashMap<>();
173 map.put("jboss", jbossResourceResolverBean);
174 map.put("default", resourceResolverBean);
175 return map;
176 }
177
178
179
180
181
182
183 @Bean(name = "adapterClasses")
184 public List<String> getAdapterClasses() {
185 logger.debug("Instantiated adapterClasses");
186 List<String> list = new ArrayList<>();
187 try {
188 Properties properties = adapters().getObject();
189 if (properties == null) {
190 return Collections.emptyList();
191 }
192 for (Object adapter : properties.values()) {
193 list.add((String) adapter);
194 }
195 } catch (Exception e) {
196 logger.error("", e);
197 }
198 return list;
199 }
200
201
202
203
204
205
206 @Bean(name = "stdoutFiles")
207 public List<String> getStdoutFiles() {
208 logger.debug("Instantiated stdoutFiles");
209 List<String> list = new ArrayList<>();
210 try {
211 Properties properties = stdout().getObject();
212 if (properties == null) {
213 return Collections.emptyList();
214 }
215 for (Object stdout : properties.values()) {
216 list.add((String) stdout);
217 }
218 } catch (Exception e) {
219 logger.error("", e);
220 }
221 return list;
222 }
223
224
225
226
227
228
229 @Bean(name = "stdout")
230 public FactoryBean<Properties> stdout() {
231 logger.debug("Instantiated stdout");
232 PropertiesFactoryBean bean = new PropertiesFactoryBean();
233 bean.setLocation(new ClassPathResource("stdout.properties"));
234 return bean;
235 }
236
237
238
239
240
241
242 @Bean(name = "adapters")
243 public FactoryBean<Properties> adapters() {
244 logger.debug("Instantiated adapters");
245 PropertiesFactoryBean bean = new PropertiesFactoryBean();
246 bean.setLocation(new ClassPathResource("adapters.properties"));
247 return bean;
248 }
249
250
251
252
253
254
255 @Bean(name = "logResolver")
256 public LogResolverBean getLogResolverBean() {
257 logger.debug("Instantiated logResolver");
258 return new LogResolverBean();
259 }
260
261
262
263
264
265
266 @Bean(name = "jvmMemoryInfoAccessor")
267 public JvmMemoryInfoAccessorBean getJvmMemoryInfoAccessorBean() {
268 logger.debug("Instantiated jvmMemoryInfoAccessorBean");
269 return new JvmMemoryInfoAccessorBean();
270 }
271
272
273
274
275
276
277 @Bean(name = "runtimeInfoAccessor")
278 public RuntimeInfoAccessorBean getRuntimeInfoAccessorBean() {
279 logger.debug("Instantiated runtimeInfoAccessorBean");
280 return new RuntimeInfoAccessorBean();
281 }
282
283
284
285
286
287
288 @Bean(name = "jspViewResolver")
289 public ViewResolver getViewResolver() {
290 logger.debug("Instantiated internalResourceViewResolver");
291 InternalResourceViewResolver resolver = new InternalResourceViewResolver();
292 resolver.setViewClass(JstlView.class);
293 resolver.setPrefix("/WEB-INF/jsp/");
294 resolver.setSuffix(".jsp");
295 return resolver;
296 }
297
298
299
300
301
302
303 @Bean(name = "themeResolver")
304 public ThemeResolver getThemeResolver() {
305 logger.debug("Instantiated fixedThemeResolver");
306 FixedThemeResolver resolver = new FixedThemeResolver();
307 resolver.setDefaultThemeName("theme-classic");
308 return resolver;
309 }
310
311
312
313
314
315
316 @Bean(name = "messageSource")
317 public MessageSource getMessageSource() {
318 logger.debug("Instantiated reloadableResourceBundleMessageSource");
319 ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
320 source.setBasename("/WEB-INF/messages");
321 source.setCacheSeconds(1);
322 source.setFallbackToSystemLocale(false);
323 return source;
324 }
325
326
327
328
329
330
331 @Bean(name = "localeResolver")
332 public LocaleResolver getLocaleResolver() {
333 logger.debug("Instantiated cookieLocaleResolver");
334 CookieLocaleResolver resolver = new CookieLocaleResolver();
335 resolver.setDefaultLocale(Locale.ENGLISH);
336 resolver.setCookieSecure(true);
337 resolver.setCookieHttpOnly(true);
338 return resolver;
339 }
340
341
342
343
344
345
346
347
348 @Bean(name = "handlerMapping")
349 public HandlerMapping getHandlerMapping(@Autowired LocaleChangeInterceptor interceptor) {
350 logger.debug("Instantiated beanNameUrlHandlerMapping");
351 BeanNameUrlHandlerMapping mapping = new BeanNameUrlHandlerMapping();
352 mapping.setAlwaysUseFullPath(true);
353 mapping.setInterceptors(interceptor);
354 return mapping;
355 }
356
357 @Override
358 public void addInterceptors(InterceptorRegistry registry) {
359 logger.debug("Registering localeChangeInterceptor");
360 registry.addInterceptor(getLocaleChangeInterceptor());
361 }
362
363
364
365
366
367
368 @Bean(name = "localeChangeInterceptor")
369 public LocaleChangeInterceptor getLocaleChangeInterceptor() {
370 logger.debug("Instantiated localeChangeInterceptor");
371 LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
372 interceptor.setParamName("lang");
373 return interceptor;
374 }
375
376
377
378
379
380
381 @Bean(name = "propertySourcesPlaceholderConfigurer")
382 public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() {
383 logger.debug("Instantiated propertySourcesPlaceholderConfigurer");
384 PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
385 configurer.setLocation(new ClassPathResource("stats.properties"));
386 configurer.setNullValue("NULL");
387
388 Properties properties = new Properties();
389 properties.put("psiprobe.tools.mail.to", "NULL");
390 properties.put("psiprobe.tools.mail.subjectPrefix", "[PSI Probe]");
391 configurer.setProperties(properties);
392 return configurer;
393 }
394
395
396
397
398
399
400 @Bean(name = "version")
401 public PropertiesFactoryBean version() {
402 logger.debug("Instantiated version");
403 PropertiesFactoryBean bean = new PropertiesFactoryBean();
404 bean.setLocation(new ClassPathResource("version.properties"));
405 return bean;
406 }
407
408 }