1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import org.apache.catalina.Context;
17 import org.springframework.web.bind.ServletRequestUtils;
18 import org.springframework.web.servlet.ModelAndView;
19
20
21
22
23 public abstract class AbstractContextHandlerController extends AbstractTomcatContainerController {
24
25 @Override
26 protected ModelAndView handleRequestInternal(HttpServletRequest request,
27 HttpServletResponse response) throws Exception {
28
29 String contextName = ServletRequestUtils.getStringParameter(request, "webapp");
30 Context context = null;
31 if (contextName != null) {
32 contextName = getContainerWrapper().getTomcatContainer().formatContextName(contextName);
33 context = getContainerWrapper().getTomcatContainer().findContext(contextName);
34 }
35
36 if (context != null || isContextOptional()) {
37 return handleContext(contextName, context, request, response);
38 }
39 if (contextName != null) {
40 request.setAttribute("errorMessage", getMessageSourceAccessor()
41 .getMessage("probe.src.contextDoesntExist", new Object[] {contextName}));
42 }
43
44 return new ModelAndView("errors/paramerror");
45 }
46
47
48
49
50
51
52 protected boolean isContextOptional() {
53 return false;
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68 protected abstract ModelAndView handleContext(String contextName, Context context,
69 HttpServletRequest request, HttpServletResponse response) throws Exception;
70 }