Move server-specific knowledge out of general child context creation
Issue: 44200
This commit is contained in:
committed by
Phillip Webb
parent
0b225790d9
commit
778f58c9e1
@@ -62,6 +62,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")
|
||||
|
||||
@@ -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<TomcatReactiveWebServerFactory> {
|
||||
|
||||
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<UndertowReactiveWebServerFactory> {
|
||||
|
||||
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<JettyReactiveWebServerFactory> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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 <T> the {@link WebServerFactory} type that can be customized
|
||||
* @author Andy Wilkinson
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public abstract class AccessLogCustomizer<T extends WebServerFactory>
|
||||
implements WebServerFactoryCustomizer<T>, 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<ConfigurableJettyWebServerFactory>
|
||||
implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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;
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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 <T> the type of factory that can be customized
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class TomcatAccessLogCustomizer<T extends ConfigurableTomcatWebServerFactory> extends AccessLogCustomizer<T> {
|
||||
|
||||
private final Function<T, Collection<Valve>> engineValvesExtractor;
|
||||
|
||||
TomcatAccessLogCustomizer(ManagementServerProperties properties,
|
||||
Function<T, Collection<Valve>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<TomcatReactiveWebServerFactory> tomcatManagementAccessLogCustomizer(
|
||||
ManagementServerProperties properties) {
|
||||
return new TomcatAccessLogCustomizer<>(properties, TomcatReactiveWebServerFactory::getEngineValves);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<TomcatServletWebServerFactory> tomcatManagementAccessLogCustomizer(
|
||||
ManagementServerProperties properties) {
|
||||
return new TomcatAccessLogCustomizer<>(properties, TomcatServletWebServerFactory::getEngineValves);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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;
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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 <T> the type of factory that can be customized
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class UndertowAccessLogCustomizer<T extends ConfigurableUndertowWebServerFactory> extends AccessLogCustomizer<T> {
|
||||
|
||||
private final Function<T, String> accessLogPrefixExtractor;
|
||||
|
||||
UndertowAccessLogCustomizer(ManagementServerProperties properties, Function<T, String> accessLogPrefixExtractor) {
|
||||
super(properties.getUndertow().getAccesslog().getPrefix());
|
||||
this.accessLogPrefixExtractor = accessLogPrefixExtractor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(T factory) {
|
||||
factory.setAccessLogPrefix(customizePrefix(this.accessLogPrefixExtractor.apply(factory)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<UndertowReactiveWebServerFactory> undertowManagementAccessLogCustomizer(
|
||||
ManagementServerProperties properties) {
|
||||
return new UndertowAccessLogCustomizer<>(properties, UndertowReactiveWebServerFactory::getAccessLogPrefix);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<UndertowServletWebServerFactory> undertowManagementAccessLogCustomizer(
|
||||
ManagementServerProperties properties) {
|
||||
return new UndertowAccessLogCustomizer<>(properties, UndertowServletWebServerFactory::getAccessLogPrefix);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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;
|
||||
@@ -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<ConfigurableServletWebServerFactory> {
|
||||
|
||||
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<TomcatServletWebServerFactory> {
|
||||
|
||||
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<UndertowServletWebServerFactory> {
|
||||
|
||||
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<JettyServletWebServerFactory> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2012-2025 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<ConfigurableServletWebServerFactory> {
|
||||
|
||||
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 : "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user