1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.apps;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.apache.catalina.Context;
20 import org.springframework.beans.factory.annotation.Value;
21 import org.springframework.stereotype.Controller;
22 import org.springframework.web.bind.ServletRequestUtils;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import psiprobe.controllers.AbstractTomcatContainerController;
27 import psiprobe.model.Application;
28 import psiprobe.tools.ApplicationUtils;
29 import psiprobe.tools.SecurityUtils;
30
31
32
33
34 @Controller
35 public class ListWebappsController extends AbstractTomcatContainerController {
36
37 @RequestMapping(path = "/index.htm")
38 @Override
39 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
40 throws Exception {
41 return super.handleRequest(request, response);
42 }
43
44 @Override
45 protected ModelAndView handleRequestInternal(HttpServletRequest request,
46 HttpServletResponse response) throws Exception {
47
48 boolean calcSize = ServletRequestUtils.getBooleanParameter(request, "size", false)
49 && SecurityUtils.hasAttributeValueRole(getServletContext());
50
51 List<Context> apps;
52 try {
53 apps = getContainerWrapper().getTomcatContainer().findContexts();
54 } catch (NullPointerException ex) {
55 throw new IllegalStateException(
56 "No container found for your server: " + getServletContext().getServerInfo(), ex);
57 }
58 List<Application> applications = new ArrayList<>(apps.size());
59 boolean showResources = getContainerWrapper().getResourceResolver().supportsPrivateResources();
60 for (Context appContext : apps) {
61
62 if (appContext.getName() != null) {
63 applications.add(ApplicationUtils.getApplication(appContext,
64 getContainerWrapper().getResourceResolver(), calcSize, getContainerWrapper()));
65 }
66 }
67 if (!applications.isEmpty() && !showResources) {
68 request.setAttribute("no_resources", Boolean.TRUE);
69 }
70 return new ModelAndView(getViewName(), "apps", applications);
71 }
72
73 @Value("applications")
74 @Override
75 public void setViewName(String viewName) {
76 super.setViewName(viewName);
77 }
78 }