1
2
3
4
5
6
7
8
9
10
11 package psiprobe;
12
13 import jakarta.servlet.ServletConfig;
14 import jakarta.servlet.ServletException;
15 import jakarta.servlet.annotation.WebServlet;
16 import jakarta.servlet.http.HttpServletRequest;
17 import jakarta.servlet.http.HttpServletResponse;
18
19 import java.nio.charset.StandardCharsets;
20
21 import org.apache.catalina.ContainerServlet;
22 import org.apache.catalina.Wrapper;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.web.servlet.DispatcherServlet;
26
27 import psiprobe.beans.ContainerWrapperBean;
28
29
30
31
32
33
34 @WebServlet
35 public class ProbeServlet extends DispatcherServlet implements ContainerServlet {
36
37
38 private static final long serialVersionUID = 1L;
39
40
41 private static final Logger logger = LoggerFactory.getLogger(ProbeServlet.class);
42
43
44 private transient Wrapper wrapper;
45
46 @Override
47 public Wrapper getWrapper() {
48 return wrapper;
49 }
50
51 @Override
52 public void setWrapper(Wrapper wrapper) {
53 this.wrapper = wrapper;
54 logger.info("setWrapper() called");
55 }
56
57
58
59
60
61
62
63
64 @Override
65 public void init(ServletConfig config) throws ServletException {
66 super.init(config);
67 if (wrapper == null) {
68 throw new ServletException("Wrapper is null");
69 }
70 getContainerWrapperBean().setWrapper(wrapper);
71 }
72
73
74
75
76
77
78
79
80
81
82 @Override
83 protected void doDispatch(HttpServletRequest httpServletRequest,
84 HttpServletResponse httpServletResponse) throws Exception {
85 httpServletRequest.setCharacterEncoding(StandardCharsets.UTF_8.name());
86 super.doDispatch(httpServletRequest, httpServletResponse);
87 }
88
89 @Override
90 public void destroy() {
91 getContainerWrapperBean().setWrapper(null);
92 super.destroy();
93 }
94
95
96
97
98
99
100 protected ContainerWrapperBean getContainerWrapperBean() {
101 return (ContainerWrapperBean) getWebApplicationContext().getBean("containerWrapper");
102 }
103
104 }