diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index 0311652c2cf..149d0056191 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -78,6 +78,7 @@ dependencies { optional("io.r2dbc:r2dbc-pool") optional("io.r2dbc:r2dbc-proxy") optional("io.r2dbc:r2dbc-spi") + optional("io.undertow:undertow-servlet") optional("jakarta.jms:jakarta.jms-api") optional("jakarta.persistence:jakarta.persistence-api") optional("jakarta.servlet:jakarta.servlet-api") diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java index 04f32a59365..4f90da68549 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java @@ -16,33 +16,19 @@ package org.springframework.boot.actuate.autoconfigure.web.reactive; -import java.io.File; import java.util.Collections; import java.util.Map; -import org.apache.catalina.Valve; -import org.apache.catalina.valves.AccessLogValve; -import org.eclipse.jetty.server.CustomRequestLog; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.RequestLogWriter; -import org.eclipse.jetty.server.Server; - import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory; -import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; -import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory; import org.springframework.boot.web.server.ConfigurableWebServerFactory; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.core.Ordered; import org.springframework.http.server.reactive.ContextPathCompositeHandler; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.util.StringUtils; @@ -80,127 +66,4 @@ public class ReactiveManagementChildContextConfiguration { return httpHandler; } - @Bean - @ConditionalOnClass(name = "io.undertow.Undertow") - UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new UndertowAccessLogCustomizer(properties); - } - - @Bean - @ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve") - TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new TomcatAccessLogCustomizer(properties); - } - - @Bean - @ConditionalOnClass(name = "org.eclipse.jetty.server.Server") - JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new JettyAccessLogCustomizer(properties); - } - - abstract static class AccessLogCustomizer implements Ordered { - - private final String prefix; - - AccessLogCustomizer(String prefix) { - this.prefix = prefix; - } - - protected String customizePrefix(String existingPrefix) { - if (this.prefix == null) { - return existingPrefix; - } - if (existingPrefix == null) { - return this.prefix; - } - if (existingPrefix.startsWith(this.prefix)) { - return existingPrefix; - } - return this.prefix + existingPrefix; - } - - @Override - public int getOrder() { - return 1; - } - - } - - static class TomcatAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - TomcatAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getTomcat().getAccesslog().getPrefix()); - } - - @Override - public void customize(TomcatReactiveWebServerFactory factory) { - AccessLogValve accessLogValve = findAccessLogValve(factory); - if (accessLogValve == null) { - return; - } - accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); - } - - private AccessLogValve findAccessLogValve(TomcatReactiveWebServerFactory factory) { - for (Valve engineValve : factory.getEngineValves()) { - if (engineValve instanceof AccessLogValve accessLogValve) { - return accessLogValve; - } - } - return null; - } - - } - - static class UndertowAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - UndertowAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getUndertow().getAccesslog().getPrefix()); - } - - @Override - public void customize(UndertowReactiveWebServerFactory factory) { - factory.setAccessLogPrefix(customizePrefix(factory.getAccessLogPrefix())); - } - - } - - static class JettyAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - JettyAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getJetty().getAccesslog().getPrefix()); - } - - @Override - public void customize(JettyReactiveWebServerFactory factory) { - factory.addServerCustomizers(this::customizeServer); - } - - private void customizeServer(Server server) { - RequestLog requestLog = server.getRequestLog(); - if (requestLog instanceof CustomRequestLog customRequestLog) { - customizeRequestLog(customRequestLog); - } - } - - private void customizeRequestLog(CustomRequestLog requestLog) { - if (requestLog.getWriter() instanceof RequestLogWriter requestLogWriter) { - customizeRequestLogWriter(requestLogWriter); - } - } - - private void customizeRequestLogWriter(RequestLogWriter writer) { - String filename = writer.getFileName(); - if (StringUtils.hasLength(filename)) { - File file = new File(filename); - file = new File(file.getParentFile(), customizePrefix(file.getName())); - writer.setFilename(file.getPath()); - } - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/AccessLogCustomizer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/AccessLogCustomizer.java new file mode 100644 index 00000000000..fa1dba1c804 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/AccessLogCustomizer.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server; + +import org.springframework.boot.web.server.WebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.core.Ordered; + +/** + * Base class for a {@link WebServerFactoryCustomizer} that customizes the web server's + * access log. + * + * @param the {@link WebServerFactory} type that can be customized + * @author Andy Wilkinson + * @since 4.0.0 + */ +public abstract class AccessLogCustomizer + implements WebServerFactoryCustomizer, Ordered { + + private final String prefix; + + protected AccessLogCustomizer(String prefix) { + this.prefix = prefix; + } + + protected String customizePrefix(String existingPrefix) { + if (this.prefix == null) { + return existingPrefix; + } + if (existingPrefix == null) { + return this.prefix; + } + if (existingPrefix.startsWith(this.prefix)) { + return existingPrefix; + } + return this.prefix + existingPrefix; + } + + @Override + public int getOrder() { + return 1; + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyAccessLogCustomizer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyAccessLogCustomizer.java new file mode 100644 index 00000000000..d544a4db86b --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyAccessLogCustomizer.java @@ -0,0 +1,71 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.jetty; + +import java.io.File; + +import org.eclipse.jetty.server.CustomRequestLog; +import org.eclipse.jetty.server.RequestLog; +import org.eclipse.jetty.server.RequestLogWriter; +import org.eclipse.jetty.server.Server; + +import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.util.StringUtils; + +/** + * {@link AccessLogCustomizer} for Jetty. + * + * @author Andy Wilkinson + */ +class JettyAccessLogCustomizer extends AccessLogCustomizer + implements WebServerFactoryCustomizer { + + JettyAccessLogCustomizer(ManagementServerProperties properties) { + super(properties.getJetty().getAccesslog().getPrefix()); + } + + @Override + public void customize(ConfigurableJettyWebServerFactory factory) { + factory.addServerCustomizers(this::customizeServer); + } + + private void customizeServer(Server server) { + RequestLog requestLog = server.getRequestLog(); + if (requestLog instanceof CustomRequestLog customRequestLog) { + customizeRequestLog(customRequestLog); + } + } + + private void customizeRequestLog(CustomRequestLog requestLog) { + if (requestLog.getWriter() instanceof RequestLogWriter requestLogWriter) { + customizeRequestLogWriter(requestLogWriter); + } + } + + private void customizeRequestLogWriter(RequestLogWriter writer) { + String filename = writer.getFileName(); + if (StringUtils.hasLength(filename)) { + File file = new File(filename); + file = new File(file.getParentFile(), customizePrefix(file.getName())); + writer.setFilename(file.getPath()); + } + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyReactiveManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyReactiveManagementChildContextConfiguration.java new file mode 100644 index 00000000000..3fd6ce9073a --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyReactiveManagementChildContextConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.jetty; + +import org.eclipse.jetty.server.Server; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Jetty-based + * reactive web endpoint infrastructure when a separate management context running on a + * different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Server.class) +@ConditionalOnWebApplication(type = Type.REACTIVE) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class JettyReactiveManagementChildContextConfiguration { + + @Bean + JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) { + return new JettyAccessLogCustomizer(properties); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyServletManagementChildContextConfiguration.java new file mode 100644 index 00000000000..cabc2fe175a --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/JettyServletManagementChildContextConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.jetty; + +import org.eclipse.jetty.server.Server; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Jetty-based + * servlet web endpoint infrastructure when a separate management context running on a + * different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Server.class) +@ConditionalOnWebApplication(type = Type.SERVLET) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class JettyServletManagementChildContextConfiguration { + + @Bean + JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) { + return new JettyAccessLogCustomizer(properties); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/package-info.java new file mode 100644 index 00000000000..d773b75d730 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/jetty/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Actuator Jetty web server support. + */ +package org.springframework.boot.actuate.autoconfigure.web.server.jetty; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatAccessLogCustomizer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatAccessLogCustomizer.java new file mode 100644 index 00000000000..b6e3921e115 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatAccessLogCustomizer.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.tomcat; + +import java.util.Collection; +import java.util.function.Function; + +import org.apache.catalina.Valve; +import org.apache.catalina.valves.AccessLogValve; + +import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.web.embedded.tomcat.ConfigurableTomcatWebServerFactory; + +/** + * {@link AccessLogCustomizer} for Tomcat. + * + * @param the type of factory that can be customized + * @author Andy Wilkinson + */ +class TomcatAccessLogCustomizer extends AccessLogCustomizer { + + private final Function> engineValvesExtractor; + + TomcatAccessLogCustomizer(ManagementServerProperties properties, + Function> engineValvesExtractor) { + super(properties.getTomcat().getAccesslog().getPrefix()); + this.engineValvesExtractor = engineValvesExtractor; + } + + @Override + public void customize(T factory) { + AccessLogValve accessLogValve = findAccessLogValve(factory); + if (accessLogValve == null) { + return; + } + accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); + } + + private AccessLogValve findAccessLogValve(T factory) { + for (Valve engineValve : this.engineValvesExtractor.apply(factory)) { + if (engineValve instanceof AccessLogValve accessLogValve) { + return accessLogValve; + } + } + return null; + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatReactiveManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatReactiveManagementChildContextConfiguration.java new file mode 100644 index 00000000000..6ec7f8d992e --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatReactiveManagementChildContextConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.tomcat; + +import org.apache.catalina.startup.Tomcat; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Tomcat-based + * reactive web endpoint infrastructure when a separate management context running on a + * different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Tomcat.class) +@ConditionalOnWebApplication(type = Type.REACTIVE) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class TomcatReactiveManagementChildContextConfiguration { + + @Bean + TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer( + ManagementServerProperties properties) { + return new TomcatAccessLogCustomizer<>(properties, TomcatReactiveWebServerFactory::getEngineValves); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatServletManagementChildContextConfiguration.java new file mode 100644 index 00000000000..b6b9d7f5b41 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/TomcatServletManagementChildContextConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.tomcat; + +import org.apache.catalina.startup.Tomcat; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Tomcat-based + * servlet web endpoint infrastructure when a separate management context running on a + * different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Tomcat.class) +@ConditionalOnWebApplication(type = Type.SERVLET) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class TomcatServletManagementChildContextConfiguration { + + @Bean + TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer( + ManagementServerProperties properties) { + return new TomcatAccessLogCustomizer<>(properties, TomcatServletWebServerFactory::getEngineValves); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/package-info.java new file mode 100644 index 00000000000..ca5de677ff6 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/tomcat/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Actuator Tomcat web server support. + */ +package org.springframework.boot.actuate.autoconfigure.web.server.tomcat; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowAccessLogCustomizer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowAccessLogCustomizer.java new file mode 100644 index 00000000000..dfcac58238f --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowAccessLogCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.undertow; + +import java.util.function.Function; + +import org.springframework.boot.actuate.autoconfigure.web.server.AccessLogCustomizer; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.web.embedded.undertow.ConfigurableUndertowWebServerFactory; + +/** + * {@link AccessLogCustomizer} for Undertow. + * + * @param the type of factory that can be customized + * @author Andy Wilkinson + */ +class UndertowAccessLogCustomizer extends AccessLogCustomizer { + + private final Function accessLogPrefixExtractor; + + UndertowAccessLogCustomizer(ManagementServerProperties properties, Function accessLogPrefixExtractor) { + super(properties.getUndertow().getAccesslog().getPrefix()); + this.accessLogPrefixExtractor = accessLogPrefixExtractor; + } + + @Override + public void customize(T factory) { + factory.setAccessLogPrefix(customizePrefix(this.accessLogPrefixExtractor.apply(factory))); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowReactiveManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowReactiveManagementChildContextConfiguration.java new file mode 100644 index 00000000000..27d3d5a43f2 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowReactiveManagementChildContextConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.undertow; + +import io.undertow.Undertow; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for + * Undertow-based reactive web endpoint infrastructure when a separate management context + * running on a different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Undertow.class) +@ConditionalOnWebApplication(type = Type.REACTIVE) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class UndertowReactiveManagementChildContextConfiguration { + + @Bean + UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer( + ManagementServerProperties properties) { + return new UndertowAccessLogCustomizer<>(properties, UndertowReactiveWebServerFactory::getAccessLogPrefix); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowServletManagementChildContextConfiguration.java new file mode 100644 index 00000000000..65c7a3d788d --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/UndertowServletManagementChildContextConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.server.undertow; + +import io.undertow.Undertow; + +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; +import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.context.annotation.Bean; + +/** + * {@link ManagementContextConfiguration @ManagementContextConfiguration} for + * Undertow-based servlet web endpoint infrastructure when a separate management context + * running on a different port is required. + * + * @author Andy Wilkinson + */ +@ConditionalOnClass(Undertow.class) +@ConditionalOnWebApplication(type = Type.SERVLET) +@EnableConfigurationProperties(ManagementServerProperties.class) +@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false) +class UndertowServletManagementChildContextConfiguration { + + @Bean + UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer( + ManagementServerProperties properties) { + return new UndertowAccessLogCustomizer<>(properties, UndertowServletWebServerFactory::getAccessLogPrefix); + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/package-info.java new file mode 100644 index 00000000000..877feb1ab9b --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/undertow/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Actuator Undertow web server support. + */ +package org.springframework.boot.actuate.autoconfigure.web.server.undertow; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java index 8b1d756c02c..cada1d79dd9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java @@ -16,41 +16,23 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet; -import java.io.File; - import jakarta.servlet.Filter; -import org.apache.catalina.Valve; -import org.apache.catalina.valves.AccessLogValve; -import org.eclipse.jetty.server.CustomRequestLog; -import org.eclipse.jetty.server.RequestLog; -import org.eclipse.jetty.server.RequestLogWriter; -import org.eclipse.jetty.server.Server; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration; import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType; -import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; -import org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; -import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean; -import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; import org.springframework.security.config.BeanIds; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.util.StringUtils; /** * {@link ManagementContextConfiguration @ManagementContextConfiguration} for Servlet web @@ -74,24 +56,6 @@ class ServletManagementChildContextConfiguration { return new ServletManagementWebServerFactoryCustomizer(beanFactory); } - @Bean - @ConditionalOnClass(name = "io.undertow.Undertow") - UndertowAccessLogCustomizer undertowManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new UndertowAccessLogCustomizer(properties); - } - - @Bean - @ConditionalOnClass(name = "org.apache.catalina.valves.AccessLogValve") - TomcatAccessLogCustomizer tomcatManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new TomcatAccessLogCustomizer(properties); - } - - @Bean - @ConditionalOnClass(name = "org.eclipse.jetty.server.Server") - JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProperties properties) { - return new JettyAccessLogCustomizer(properties); - } - @Configuration(proxyBeanMethods = false) @ConditionalOnClass({ EnableWebSecurity.class, Filter.class }) @ConditionalOnBean(name = BeanIds.SPRING_SECURITY_FILTER_CHAIN, search = SearchStrategy.ANCESTORS) @@ -112,130 +76,4 @@ class ServletManagementChildContextConfiguration { } - static class ServletManagementWebServerFactoryCustomizer - extends ManagementWebServerFactoryCustomizer { - - ServletManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) { - super(beanFactory); - } - - @Override - protected void customize(ConfigurableServletWebServerFactory webServerFactory, - ManagementServerProperties managementServerProperties, ServerProperties serverProperties) { - super.customize(webServerFactory, managementServerProperties, serverProperties); - webServerFactory.setContextPath(getContextPath(managementServerProperties)); - } - - private String getContextPath(ManagementServerProperties managementServerProperties) { - String basePath = managementServerProperties.getBasePath(); - return StringUtils.hasText(basePath) ? basePath : ""; - } - - } - - abstract static class AccessLogCustomizer implements Ordered { - - private final String prefix; - - AccessLogCustomizer(String prefix) { - this.prefix = prefix; - } - - protected String customizePrefix(String existingPrefix) { - if (this.prefix == null) { - return existingPrefix; - } - if (existingPrefix == null) { - return this.prefix; - } - if (existingPrefix.startsWith(this.prefix)) { - return existingPrefix; - } - return this.prefix + existingPrefix; - } - - @Override - public int getOrder() { - return 1; - } - - } - - static class TomcatAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - TomcatAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getTomcat().getAccesslog().getPrefix()); - } - - @Override - public void customize(TomcatServletWebServerFactory factory) { - AccessLogValve accessLogValve = findAccessLogValve(factory); - if (accessLogValve == null) { - return; - } - accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix())); - } - - private AccessLogValve findAccessLogValve(TomcatServletWebServerFactory factory) { - for (Valve engineValve : factory.getEngineValves()) { - if (engineValve instanceof AccessLogValve accessLogValve) { - return accessLogValve; - } - } - return null; - } - - } - - static class UndertowAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - UndertowAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getUndertow().getAccesslog().getPrefix()); - } - - @Override - public void customize(UndertowServletWebServerFactory factory) { - factory.setAccessLogPrefix(customizePrefix(factory.getAccessLogPrefix())); - } - - } - - static class JettyAccessLogCustomizer extends AccessLogCustomizer - implements WebServerFactoryCustomizer { - - JettyAccessLogCustomizer(ManagementServerProperties properties) { - super(properties.getJetty().getAccesslog().getPrefix()); - } - - @Override - public void customize(JettyServletWebServerFactory factory) { - factory.addServerCustomizers(this::customizeServer); - } - - private void customizeServer(Server server) { - RequestLog requestLog = server.getRequestLog(); - if (requestLog instanceof CustomRequestLog customRequestLog) { - customizeRequestLog(customRequestLog); - } - } - - private void customizeRequestLog(CustomRequestLog requestLog) { - if (requestLog.getWriter() instanceof RequestLogWriter requestLogWriter) { - customizeRequestLogWriter(requestLogWriter); - } - } - - private void customizeRequestLogWriter(RequestLogWriter writer) { - String filename = writer.getFileName(); - if (StringUtils.hasLength(filename)) { - File file = new File(filename); - file = new File(file.getParentFile(), customizePrefix(file.getName())); - writer.setFilename(file.getPath()); - } - } - - } - } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementWebServerFactoryCustomizer.java new file mode 100644 index 00000000000..8bf19f31f74 --- /dev/null +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementWebServerFactoryCustomizer.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.actuate.autoconfigure.web.servlet; + +import org.springframework.beans.factory.ListableBeanFactory; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; +import org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.util.StringUtils; + +/** + * {@link ManagementWebServerFactoryCustomizer} for a servlet web server. + * + * @author Andy Wilkinson + */ +class ServletManagementWebServerFactoryCustomizer + extends ManagementWebServerFactoryCustomizer { + + ServletManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) { + super(beanFactory); + } + + @Override + protected void customize(ConfigurableServletWebServerFactory webServerFactory, + ManagementServerProperties managementServerProperties, ServerProperties serverProperties) { + super.customize(webServerFactory, managementServerProperties, serverProperties); + webServerFactory.setContextPath(getContextPath(managementServerProperties)); + } + + private String getContextPath(ManagementServerProperties managementServerProperties) { + String basePath = managementServerProperties.getBasePath(); + return StringUtils.hasText(basePath) ? basePath : ""; + } + +} diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports index 136ca597038..89877f105b2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports @@ -6,5 +6,11 @@ org.springframework.boot.actuate.autoconfigure.security.servlet.SecurityRequestM org.springframework.boot.actuate.autoconfigure.web.jersey.JerseySameManagementContextConfiguration org.springframework.boot.actuate.autoconfigure.web.jersey.JerseyChildManagementContextConfiguration org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.jetty.JettyReactiveManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.jetty.JettyServletManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.tomcat.TomcatReactiveManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.tomcat.TomcatServletManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.undertow.UndertowReactiveManagementChildContextConfiguration +org.springframework.boot.actuate.autoconfigure.web.server.undertow.UndertowServletManagementChildContextConfiguration org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration org.springframework.boot.actuate.autoconfigure.web.servlet.WebMvcEndpointChildContextConfiguration diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java index ce30fd72995..3cb9624b123 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfigurationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.web.reactive; import org.junit.jupiter.api.Test; -import org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration.AccessLogCustomizer; import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; @@ -31,23 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ class ReactiveManagementChildContextConfigurationTests { - @Test - void accessLogCustomizer() { - AccessLogCustomizer customizer = new AccessLogCustomizer("prefix") { - }; - assertThat(customizer.customizePrefix(null)).isEqualTo("prefix"); - assertThat(customizer.customizePrefix("existing")).isEqualTo("prefixexisting"); - assertThat(customizer.customizePrefix("prefixexisting")).isEqualTo("prefixexisting"); - } - - @Test - void accessLogCustomizerWithNullPrefix() { - AccessLogCustomizer customizer = new AccessLogCustomizer(null) { - }; - assertThat(customizer.customizePrefix(null)).isEqualTo(null); - assertThat(customizer.customizePrefix("existing")).isEqualTo("existing"); - } - @Test // gh-45857 void failsWithoutManagementServerPropertiesBeanFromParent() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java index 404ce09a220..6f8486b383d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfigurationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.web.servlet; import org.junit.jupiter.api.Test; import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; -import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration.AccessLogCustomizer; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -31,38 +30,13 @@ import static org.assertj.core.api.Assertions.assertThat; */ class ServletManagementChildContextConfigurationTests { - @Test - void accessLogCustomizer() { - AccessLogCustomizer customizer = new AccessLogCustomizer("prefix") { - }; - assertThat(customizer.customizePrefix(null)).isEqualTo("prefix"); - assertThat(customizer.customizePrefix("existing")).isEqualTo("prefixexisting"); - assertThat(customizer.customizePrefix("prefixexisting")).isEqualTo("prefixexisting"); - } - - @Test - void accessLogCustomizerWithNullPrefix() { - AccessLogCustomizer customizer = new AccessLogCustomizer(null) { - }; - assertThat(customizer.customizePrefix(null)).isEqualTo(null); - assertThat(customizer.customizePrefix("existing")).isEqualTo("existing"); - } - - @Test - // gh-45857 - void failsWithoutManagementServerPropertiesBeanFromParent() { - new WebApplicationContextRunner().run((parent) -> new WebApplicationContextRunner().withParent(parent) - .withUserConfiguration(ServletManagementChildContextConfiguration.class) - .run((context) -> assertThat(context).hasFailed())); - } - - @Test - // gh-45857 - void succeedsWithManagementServerPropertiesBeanFromParent() { + @Test // gh-45857 + void doesNotCreateManagementServerPropertiesInChildContext() { new WebApplicationContextRunner().withBean(ManagementServerProperties.class) .run((parent) -> new WebApplicationContextRunner().withParent(parent) .withUserConfiguration(ServletManagementChildContextConfiguration.class) - .run((context) -> assertThat(context).hasNotFailed())); + .run((context) -> assertThat(context.getBean(ManagementServerProperties.class)) + .isSameAs(parent.getBean(ManagementServerProperties.class)))); } }