|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.web.reactive;
|
18 | 18 |
|
19 |
| -import java.io.File; |
20 | 19 | import java.util.Collections;
|
21 | 20 | import java.util.Map;
|
22 | 21 |
|
23 |
| -import org.apache.catalina.Valve; |
24 |
| -import org.apache.catalina.valves.AccessLogValve; |
25 |
| -import org.eclipse.jetty.server.CustomRequestLog; |
26 |
| -import org.eclipse.jetty.server.RequestLog; |
27 |
| -import org.eclipse.jetty.server.RequestLogWriter; |
28 |
| -import org.eclipse.jetty.server.Server; |
29 |
| - |
30 | 22 | import org.springframework.beans.factory.ListableBeanFactory;
|
31 | 23 | import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
|
32 | 24 | import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
|
33 | 25 | import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
|
34 | 26 | import org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer;
|
35 |
| -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
36 | 27 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
37 | 28 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
38 |
| -import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory; |
39 |
| -import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; |
40 |
| -import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory; |
41 | 29 | import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
42 |
| -import org.springframework.boot.web.server.WebServerFactoryCustomizer; |
43 | 30 | import org.springframework.context.ApplicationContext;
|
44 | 31 | import org.springframework.context.annotation.Bean;
|
45 |
| -import org.springframework.core.Ordered; |
46 | 32 | import org.springframework.http.server.reactive.ContextPathCompositeHandler;
|
47 | 33 | import org.springframework.http.server.reactive.HttpHandler;
|
48 | 34 | import org.springframework.util.StringUtils;
|
@@ -79,122 +65,4 @@ public HttpHandler httpHandler(ApplicationContext applicationContext, Management
|
79 | 65 | return httpHandler;
|
80 | 66 | }
|
81 | 67 |
|
82 |
| - @Bean |
83 |
| - @ConditionalOnClass(name = "io.undertow.Undertow") |
84 |
| - UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(ManagementServerProperties properties) { |
85 |
| - return new UndertowAccessLogCustomizer(properties); |
86 |
| - } |
87 |
| - |
88 |
| - @Bean |
89 |
| - @ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve") |
90 |
| - TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(ManagementServerProperties properties) { |
91 |
| - return new TomcatAccessLogCustomizer(properties); |
92 |
| - } |
93 |
| - |
94 |
| - @Bean |
95 |
| - @ConditionalOnClass(name = "org.eclipse.jetty.server.Server") |
96 |
| - JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) { |
97 |
| - return new JettyAccessLogCustomizer(properties); |
98 |
| - } |
99 |
| - |
100 |
| - abstract static class AccessLogCustomizer implements Ordered { |
101 |
| - |
102 |
| - private final ManagementServerProperties properties; |
103 |
| - |
104 |
| - AccessLogCustomizer(ManagementServerProperties properties) { |
105 |
| - this.properties = properties; |
106 |
| - } |
107 |
| - |
108 |
| - protected String customizePrefix(String prefix) { |
109 |
| - prefix = (prefix != null) ? prefix : ""; |
110 |
| - if (prefix.startsWith(this.properties.getAccesslog().getPrefix())) { |
111 |
| - return prefix; |
112 |
| - } |
113 |
| - return this.properties.getAccesslog().getPrefix() + prefix; |
114 |
| - } |
115 |
| - |
116 |
| - @Override |
117 |
| - public int getOrder() { |
118 |
| - return 1; |
119 |
| - } |
120 |
| - |
121 |
| - } |
122 |
| - |
123 |
| - static class TomcatAccessLogCustomizer extends AccessLogCustomizer |
124 |
| - implements WebServerFactoryCustomizer<TomcatReactiveWebServerFactory> { |
125 |
| - |
126 |
| - TomcatAccessLogCustomizer(ManagementServerProperties properties) { |
127 |
| - super(properties); |
128 |
| - } |
129 |
| - |
130 |
| - @Override |
131 |
| - public void customize(TomcatReactiveWebServerFactory factory) { |
132 |
| - AccessLogValve accessLogValve = findAccessLogValve(factory); |
133 |
| - if (accessLogValve == null) { |
134 |
| - return; |
135 |
| - } |
136 |
| - accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); |
137 |
| - } |
138 |
| - |
139 |
| - private AccessLogValve findAccessLogValve(TomcatReactiveWebServerFactory factory) { |
140 |
| - for (Valve engineValve : factory.getEngineValves()) { |
141 |
| - if (engineValve instanceof AccessLogValve accessLogValve) { |
142 |
| - return accessLogValve; |
143 |
| - } |
144 |
| - } |
145 |
| - return null; |
146 |
| - } |
147 |
| - |
148 |
| - } |
149 |
| - |
150 |
| - static class UndertowAccessLogCustomizer extends AccessLogCustomizer |
151 |
| - implements WebServerFactoryCustomizer<UndertowReactiveWebServerFactory> { |
152 |
| - |
153 |
| - UndertowAccessLogCustomizer(ManagementServerProperties properties) { |
154 |
| - super(properties); |
155 |
| - } |
156 |
| - |
157 |
| - @Override |
158 |
| - public void customize(UndertowReactiveWebServerFactory factory) { |
159 |
| - factory.setAccessLogPrefix(customizePrefix(factory.getAccessLogPrefix())); |
160 |
| - } |
161 |
| - |
162 |
| - } |
163 |
| - |
164 |
| - static class JettyAccessLogCustomizer extends AccessLogCustomizer |
165 |
| - implements WebServerFactoryCustomizer<JettyReactiveWebServerFactory> { |
166 |
| - |
167 |
| - JettyAccessLogCustomizer(ManagementServerProperties properties) { |
168 |
| - super(properties); |
169 |
| - } |
170 |
| - |
171 |
| - @Override |
172 |
| - public void customize(JettyReactiveWebServerFactory factory) { |
173 |
| - factory.addServerCustomizers(this::customizeServer); |
174 |
| - } |
175 |
| - |
176 |
| - private void customizeServer(Server server) { |
177 |
| - RequestLog requestLog = server.getRequestLog(); |
178 |
| - if (requestLog instanceof CustomRequestLog customRequestLog) { |
179 |
| - customizeRequestLog(customRequestLog); |
180 |
| - } |
181 |
| - } |
182 |
| - |
183 |
| - private void customizeRequestLog(CustomRequestLog requestLog) { |
184 |
| - if (requestLog.getWriter() instanceof RequestLogWriter requestLogWriter) { |
185 |
| - customizeRequestLogWriter(requestLogWriter); |
186 |
| - } |
187 |
| - } |
188 |
| - |
189 |
| - private void customizeRequestLogWriter(RequestLogWriter writer) { |
190 |
| - String filename = writer.getFileName(); |
191 |
| - if (StringUtils.hasLength(filename)) { |
192 |
| - File file = new File(filename); |
193 |
| - file = new File(file.getParentFile(), customizePrefix(file.getName())); |
194 |
| - writer.setFilename(file.getPath()); |
195 |
| - } |
196 |
| - } |
197 |
| - |
198 |
| - } |
199 |
| - |
200 | 68 | }
|
0 commit comments