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