View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
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   * The Class StopJvmController.
28   */
29  @Controller
30  public class StopJvmController extends PostParameterizableViewController {
31  
32    /** The Constant logger. */
33    private static final Logger logger = LoggerFactory.getLogger(StopJvmController.class);
34  
35    /** The stop exit code. */
36    private int stopExitCode = 1;
37  
38    /**
39     * Gets the stop exit code.
40     *
41     * @return the stop exit code
42     */
43    public int getStopExitCode() {
44      return stopExitCode;
45    }
46  
47    /**
48     * Sets the stop exit code.
49     *
50     * @param stopExitCode the new stop exit code
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  }