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.datasources;
12  
13  import java.util.List;
14  
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  
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  
23  import psiprobe.controllers.AbstractTomcatContainerController;
24  import psiprobe.model.ApplicationResource;
25  
26  /**
27   * Creates a list of all configured datasources for all web applications within the container.
28   */
29  @Controller
30  public class ListAllJdbcResourcesController extends AbstractTomcatContainerController {
31  
32    @RequestMapping(path = "/datasources.htm")
33    @Override
34    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
35        throws Exception {
36      return super.handleRequest(request, response);
37    }
38  
39    @Override
40    protected ModelAndView handleRequestInternal(HttpServletRequest request,
41        HttpServletResponse httpServletResponse) throws Exception {
42  
43      boolean supportsGlobal = getContainerWrapper().getResourceResolver().supportsGlobalResources();
44      boolean supportsPrivate =
45          getContainerWrapper().getResourceResolver().supportsPrivateResources();
46      boolean supportsDataSourceLookup =
47          getContainerWrapper().getResourceResolver().supportsDataSourceLookup();
48      List<ApplicationResource> privateResources = getContainerWrapper().getPrivateDataSources();
49      List<ApplicationResource> globalResources = getContainerWrapper().getGlobalDataSources();
50      return new ModelAndView(getViewName()).addObject("supportsGlobal", supportsGlobal)
51          .addObject("supportsPrivate", supportsPrivate)
52          .addObject("supportsDSLookup", supportsDataSourceLookup)
53          .addObject("privateResources", privateResources)
54          .addObject("globalResources", globalResources);
55    }
56  
57    @Value("datasources")
58    @Override
59    public void setViewName(String viewName) {
60      super.setViewName(viewName);
61    }
62  
63  }