1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.system;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Value;
19 import org.springframework.stereotype.Controller;
20 import org.springframework.web.bind.ServletRequestUtils;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.servlet.ModelAndView;
23 import org.springframework.web.servlet.mvc.ParameterizableViewController;
24 import org.springframework.web.servlet.view.RedirectView;
25
26
27
28
29 @Controller
30 public class AdviseGarbageCollectionController extends ParameterizableViewController {
31
32
33 private static final Logger logger =
34 LoggerFactory.getLogger(AdviseGarbageCollectionController.class);
35
36
37 private String replacePattern;
38
39
40
41
42
43
44 public String getReplacePattern() {
45 return replacePattern;
46 }
47
48
49
50
51
52
53 @Value("^http(s)?://[a-zA-Z\\-\\.0-9]+(:[0-9]+)?")
54 public void setReplacePattern(String replacePattern) {
55 this.replacePattern = replacePattern;
56 }
57
58 @RequestMapping(path = "/adm/advisegc.htm")
59 @Override
60 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
61 throws Exception {
62 return super.handleRequest(request, response);
63 }
64
65 @Override
66 protected ModelAndView handleRequestInternal(HttpServletRequest request,
67 HttpServletResponse response) throws Exception {
68
69 boolean finalization = ServletRequestUtils.getBooleanParameter(request, "fin", false);
70
71 String referer = request.getHeader("Referer");
72 String redirectUrl;
73 if (referer != null) {
74 redirectUrl = referer.replaceAll(replacePattern, "");
75 } else {
76 redirectUrl = request.getContextPath() + getViewName();
77 }
78 if (finalization) {
79 Runtime.getRuntime().runFinalization();
80 logger.debug("Advised finalization");
81 } else {
82 Runtime.getRuntime().gc();
83 logger.debug("Advised Garbage Collection");
84 }
85 logger.debug("Redirected to {}", redirectUrl);
86 return new ModelAndView(new RedirectView(redirectUrl));
87 }
88
89 @Value("/sysinfo.htm")
90 @Override
91 public void setViewName(String viewName) {
92 super.setViewName(viewName);
93 }
94
95 }