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 java.util.List;
18  
19  import org.springframework.web.bind.ServletRequestUtils;
20  import org.springframework.web.servlet.ModelAndView;
21  
22  import psiprobe.beans.ContainerListenerBean;
23  import psiprobe.controllers.AbstractTomcatContainerController;
24  import psiprobe.model.Connector;
25  
26  /**
27   * The Class BaseGetConnectorController.
28   */
29  public class BaseGetConnectorController extends AbstractTomcatContainerController {
30  
31    /** The container listener bean. */
32    @Inject
33    private ContainerListenerBean containerListenerBean;
34  
35    /**
36     * Gets the container listener bean.
37     *
38     * @return the container listener bean
39     */
40    public ContainerListenerBean getContainerListenerBean() {
41      return containerListenerBean;
42    }
43  
44    /**
45     * Sets the container listener bean.
46     *
47     * @param containerListenerBean the new container listener bean
48     */
49    public void setContainerListenerBean(ContainerListenerBean containerListenerBean) {
50      this.containerListenerBean = containerListenerBean;
51    }
52  
53    @Override
54    protected ModelAndView handleRequestInternal(HttpServletRequest request,
55        HttpServletResponse response) throws Exception {
56      String connectorName = ServletRequestUtils.getStringParameter(request, "cn");
57      Connector connector = null;
58  
59      if (connectorName != null) {
60        List<Connector> connectors = containerListenerBean.getConnectors(false);
61        for (Connector conn : connectors) {
62          if (connectorName.equals(conn.getProtocolHandler())) {
63            connector = conn;
64            break;
65          }
66        }
67      }
68  
69      return new ModelAndView(getViewName(), "connector", connector);
70    }
71  
72  }