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.beans.factory.annotation.Value;
20 import org.springframework.security.core.Authentication;
21 import org.springframework.security.core.context.SecurityContextHolder;
22 import org.springframework.stereotype.Controller;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import psiprobe.controllers.AbstractContextHandlerController;
27
28
29
30
31 @Controller
32 public class AjaxReloadContextController extends AbstractContextHandlerController {
33
34
35 private static final Logger logger = LoggerFactory.getLogger(AjaxReloadContextController.class);
36
37 @RequestMapping(path = "/app/reload.ajax")
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 handleContext(String contextName, Context context,
46 HttpServletRequest request, HttpServletResponse response) throws Exception {
47
48 if (context != null && !request.getContextPath().equals(contextName)) {
49 try {
50 logger.info("{} requested RELOAD of {}", request.getRemoteAddr(), contextName);
51 context.reload();
52
53 Authentication auth = SecurityContextHolder.getContext().getAuthentication();
54
55 String name = auth.getName();
56 logger.info(getMessageSourceAccessor().getMessage("probe.src.log.reload"), name,
57 contextName);
58 } catch (Exception e) {
59 logger.error("Error during ajax request to RELOAD of '{}'", contextName, e);
60 }
61 }
62 return new ModelAndView(getViewName(), "available",
63 context != null && getContainerWrapper().getTomcatContainer().getAvailable(context));
64 }
65
66 @Value("ajax/context_status")
67 @Override
68 public void setViewName(String viewName) {
69 super.setViewName(viewName);
70 }
71
72 }