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.connectors;
12  
13  import jakarta.inject.Inject;
14  import jakarta.servlet.http.HttpServletRequest;
15  import jakarta.servlet.http.HttpServletResponse;
16  
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  import org.springframework.beans.factory.annotation.Value;
20  import org.springframework.stereotype.Controller;
21  import org.springframework.web.bind.ServletRequestUtils;
22  import org.springframework.web.bind.annotation.RequestMapping;
23  import org.springframework.web.servlet.ModelAndView;
24  import org.springframework.web.servlet.mvc.ParameterizableViewController;
25  import org.springframework.web.servlet.view.RedirectView;
26  
27  import psiprobe.beans.ContainerListenerBean;
28  import psiprobe.beans.stats.collectors.ConnectorStatsCollectorBean;
29  
30  /**
31   * The Class to use toggle connector status, like STATED, STOPPED.
32   */
33  @Controller
34  public class ToggleConnectorStatusController extends ParameterizableViewController {
35  
36    /** The static logger. */
37    private static final Logger logger =
38        LoggerFactory.getLogger(ToggleConnectorStatusController.class);
39  
40    /** The collector bean. */
41    @Inject
42    private ConnectorStatsCollectorBean collectorBean;
43  
44    /** The container listener. */
45    @Inject
46    private ContainerListenerBean containerListener;
47  
48    /**
49     * Gets the collector bean.
50     *
51     * @return the collector bean
52     */
53    public ConnectorStatsCollectorBean getCollectorBean() {
54      return collectorBean;
55    }
56  
57    /**
58     * Sets the collector bean.
59     *
60     * @param collectorBean the new collector bean
61     */
62    public void setCollectorBean(ConnectorStatsCollectorBean collectorBean) {
63      this.collectorBean = collectorBean;
64    }
65  
66    @RequestMapping(path = "/app/connectorStatus.htm")
67    @Override
68    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
69        throws Exception {
70      return super.handleRequest(request, response);
71    }
72  
73    @Override
74    protected ModelAndView handleRequestInternal(HttpServletRequest request,
75        HttpServletResponse response) throws Exception {
76  
77      String connectorName = ServletRequestUtils.getRequiredStringParameter(request, "cn");
78  
79      String port = ServletRequestUtils.getRequiredStringParameter(request, "port");
80  
81      String operation = ServletRequestUtils.getRequiredStringParameter(request, "operation");
82  
83      containerListener.toggleConnectorStatus(operation, port);
84  
85      logger.info("Connector status toggled for {}", connectorName);
86      return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
87    }
88  
89    @Value("/connectors.htm")
90    @Override
91    public void setViewName(String viewName) {
92      super.setViewName(viewName);
93    }
94  
95  }