1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.logs;
12
13 import jakarta.inject.Inject;
14 import jakarta.servlet.http.HttpServletRequest;
15 import jakarta.servlet.http.HttpServletResponse;
16
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import org.springframework.web.bind.ServletRequestUtils;
20 import org.springframework.web.servlet.ModelAndView;
21 import org.springframework.web.servlet.mvc.ParameterizableViewController;
22
23 import psiprobe.beans.LogResolverBean;
24 import psiprobe.tools.logging.LogDestination;
25
26
27
28
29 public abstract class AbstractLogHandlerController extends ParameterizableViewController {
30
31
32 private static final Logger logger = LoggerFactory.getLogger(AbstractLogHandlerController.class);
33
34
35 @Inject
36 private LogResolverBean logResolver;
37
38
39
40
41
42
43 public LogResolverBean getLogResolver() {
44 return logResolver;
45 }
46
47
48
49
50
51
52 public void setLogResolver(LogResolverBean logResolver) {
53 this.logResolver = logResolver;
54 }
55
56 @Override
57 protected ModelAndView handleRequestInternal(HttpServletRequest request,
58 HttpServletResponse response) throws Exception {
59
60 String logType = ServletRequestUtils.getStringParameter(request, "logType");
61 String webapp = ServletRequestUtils.getStringParameter(request, "webapp");
62 boolean context = ServletRequestUtils.getBooleanParameter(request, "context", false);
63 boolean root = ServletRequestUtils.getBooleanParameter(request, "root", false);
64 String logName = ServletRequestUtils.getStringParameter(request, "logName");
65 String logIndex = ServletRequestUtils.getStringParameter(request, "logIndex");
66
67 LogDestination dest =
68 logResolver.getLogDestination(logType, webapp, context, root, logName, logIndex);
69
70 ModelAndView modelAndView = null;
71 boolean logFound = false;
72 if (dest != null) {
73 if (dest.getFile() != null && dest.getFile().exists()) {
74 modelAndView = handleLogFile(request, response, dest);
75 logFound = true;
76 } else {
77 logger.error("{}: file not found", dest.getFile());
78 }
79 } else {
80 logger.error("{}{} log{} not found", logType, root ? " root" : "",
81 root ? "" : " '" + logName + "'");
82 }
83 if (!logFound) {
84 response.sendError(404);
85 }
86 return modelAndView;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100 protected abstract ModelAndView handleLogFile(HttpServletRequest request,
101 HttpServletResponse response, LogDestination logDest) throws Exception;
102
103 }