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 org.apache.catalina.Context;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.springframework.web.servlet.ModelAndView;
20 import org.springframework.web.servlet.view.InternalResourceView;
21 import org.springframework.web.servlet.view.RedirectView;
22
23 import psiprobe.controllers.AbstractContextHandlerController;
24
25
26
27
28 public abstract class AbstractNoSelfContextHandlerController
29 extends AbstractContextHandlerController {
30
31
32 private static final Logger logger =
33 LoggerFactory.getLogger(AbstractNoSelfContextHandlerController.class);
34
35
36 private boolean passQueryString;
37
38
39
40
41
42
43 public boolean isPassQueryString() {
44 return passQueryString;
45 }
46
47
48
49
50
51
52 public void setPassQueryString(boolean passQueryString) {
53 this.passQueryString = passQueryString;
54 }
55
56 @Override
57 protected ModelAndView handleContext(String contextName, Context context,
58 HttpServletRequest request, HttpServletResponse response) throws Exception {
59
60 try {
61 if (request.getContextPath().equals(contextName)) {
62 throw new IllegalStateException(
63 getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
64 }
65
66 executeAction(contextName);
67 } catch (Exception e) {
68 request.setAttribute("errorMessage", e.getMessage());
69 logger.error("Error during invocation", e);
70 return new ModelAndView(new InternalResourceView(getViewName()));
71 }
72 return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()
73 + (isPassQueryString() ? "?" + request.getQueryString() : "")));
74 }
75
76
77
78
79
80
81
82
83 protected abstract void executeAction(String contextName) throws Exception;
84
85 }