1
2
3
4
5
6
7
8
9
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
32
33 @Controller
34 public class ToggleConnectorStatusController extends ParameterizableViewController {
35
36
37 private static final Logger logger =
38 LoggerFactory.getLogger(ToggleConnectorStatusController.class);
39
40
41 @Inject
42 private ConnectorStatsCollectorBean collectorBean;
43
44
45 @Inject
46 private ContainerListenerBean containerListener;
47
48
49
50
51
52
53 public ConnectorStatsCollectorBean getCollectorBean() {
54 return collectorBean;
55 }
56
57
58
59
60
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 }