1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.wrapper;
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.annotation.RequestMapping;
21 import org.springframework.web.servlet.ModelAndView;
22 import org.tanukisoftware.wrapper.WrapperManager;
23
24 import psiprobe.PostParameterizableViewController;
25
26
27
28
29 @Controller
30 public class StopJvmController extends PostParameterizableViewController {
31
32
33 private static final Logger logger = LoggerFactory.getLogger(StopJvmController.class);
34
35
36 private int stopExitCode = 1;
37
38
39
40
41
42
43 public int getStopExitCode() {
44 return stopExitCode;
45 }
46
47
48
49
50
51
52 public void setStopExitCode(int stopExitCode) {
53 this.stopExitCode = stopExitCode;
54 }
55
56 @RequestMapping(path = "/adm/stopvm.ajax")
57 @Override
58 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
59 throws Exception {
60 return super.handleRequest(request, response);
61 }
62
63 @Override
64 protected ModelAndView handleRequestInternal(HttpServletRequest request,
65 HttpServletResponse response) throws Exception {
66
67 boolean done = false;
68 try {
69 Class.forName("org.tanukisoftware.wrapper.WrapperManager");
70 logger.info("JVM is STOPPED by {}", request.getRemoteAddr());
71 WrapperManager.stop(stopExitCode);
72 done = true;
73 } catch (ClassNotFoundException e) {
74 logger.info("WrapperManager not found. Do you have wrapper.jar in the classpath?");
75 logger.trace("", e);
76 }
77 return new ModelAndView(getViewName(), "done", done);
78 }
79
80 @Value("ajax/jvm_stopped")
81 @Override
82 public void setViewName(String viewName) {
83 super.setViewName(viewName);
84 }
85
86 }