1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.deploy;
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.security.core.Authentication;
20 import org.springframework.security.core.context.SecurityContextHolder;
21 import org.springframework.web.servlet.ModelAndView;
22 import org.springframework.web.servlet.view.InternalResourceView;
23 import org.springframework.web.servlet.view.RedirectView;
24
25 import psiprobe.controllers.AbstractContextHandlerController;
26
27
28
29
30 public class BaseUndeployContextController extends AbstractContextHandlerController {
31
32
33 private static final Logger logger = LoggerFactory.getLogger(BaseUndeployContextController.class);
34
35
36 private String failureViewName;
37
38
39
40
41
42
43 public String getFailureViewName() {
44 return failureViewName;
45 }
46
47
48
49
50
51
52 public void setFailureViewName(String failureViewName) {
53 this.failureViewName = failureViewName;
54 }
55
56 @Override
57 protected ModelAndView handleContext(String contextName, Context context,
58 HttpServletRequest request, HttpServletResponse response) throws Exception {
59 try {
60 if (request.getContextPath().equals(contextName)) {
61 throw new IllegalStateException(
62 getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
63 }
64
65 getContainerWrapper().getTomcatContainer().remove(contextName);
66
67 Authentication auth = SecurityContextHolder.getContext().getAuthentication();
68
69 String name = auth.getName();
70 logger.info(getMessageSourceAccessor().getMessage("probe.src.log.undeploy"), name,
71 contextName);
72
73 } catch (Exception e) {
74 request.setAttribute("errorMessage", e.getMessage());
75 logger.error("Error during undeploy of '{}'", contextName, e);
76 return new ModelAndView(new InternalResourceView(
77 getFailureViewName() == null ? getViewName() : getFailureViewName()));
78 }
79 return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
80 }
81
82
83
84
85
86
87
88
89 protected void executeAction(String contextName) throws Exception {
90
91 }
92
93 }