1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.logs;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.io.File;
17
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.springframework.beans.factory.annotation.Value;
21 import org.springframework.stereotype.Controller;
22 import org.springframework.web.bind.ServletRequestUtils;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.servlet.ModelAndView;
25
26 import psiprobe.Utils;
27 import psiprobe.tools.logging.LogDestination;
28
29
30
31
32 @Controller
33 public class DownloadLogController extends AbstractLogHandlerController {
34
35
36 private static final Logger logger = LoggerFactory.getLogger(DownloadLogController.class);
37
38 @RequestMapping(path = "/download")
39 @Override
40 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
41 throws Exception {
42 return super.handleRequest(request, response);
43 }
44
45 @Override
46 protected ModelAndView handleLogFile(HttpServletRequest request, HttpServletResponse response,
47 LogDestination logDest) throws Exception {
48
49 boolean compressed =
50 "true".equals(ServletRequestUtils.getStringParameter(request, "compressed"));
51
52 File file = logDest.getFile();
53 logger.info("Sending {}{} to {} ({})", file, compressed ? " compressed" : "",
54 request.getRemoteAddr(), request.getRemoteUser());
55 if (compressed) {
56 Utils.sendCompressedFile(response, file);
57 } else {
58 Utils.sendFile(request, response, file);
59 }
60 return null;
61 }
62
63 @Value("")
64 @Override
65 public void setViewName(String viewName) {
66 super.setViewName(viewName);
67 }
68
69 }