1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.servlets;
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.annotation.RequestMapping;
23 import org.springframework.web.servlet.ModelAndView;
24
25 import psiprobe.controllers.AbstractContextHandlerController;
26 import psiprobe.model.ServletMapping;
27 import psiprobe.tools.ApplicationUtils;
28
29
30
31
32
33 @Controller
34 public class ListServletMapsController extends AbstractContextHandlerController {
35
36 @RequestMapping(path = "/servletmaps.htm")
37 @Override
38 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
39 throws Exception {
40 return super.handleRequest(request, response);
41 }
42
43 @Override
44 protected ModelAndView handleContext(String contextName, Context context,
45 HttpServletRequest request, HttpServletResponse response) throws Exception {
46
47 List<Context> ctxs;
48 if (context == null) {
49 ctxs = getContainerWrapper().getTomcatContainer().findContexts();
50 } else {
51 ctxs = new ArrayList<>();
52 ctxs.add(context);
53 }
54
55 List<ServletMapping> servletMaps = new ArrayList<>();
56 for (Context ctx : ctxs) {
57 servletMaps.addAll(ApplicationUtils.getApplicationServletMaps(ctx));
58 }
59
60 return new ModelAndView(getViewName(), "servletMaps", servletMaps);
61 }
62
63 @Override
64 protected boolean isContextOptional() {
65 return true;
66 }
67
68 @Value("servletmaps")
69 @Override
70 public void setViewName(String viewName) {
71 super.setViewName(viewName);
72 }
73
74 }