Skip to content

ServletEndpoints do not consider server.servlet.path #13124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.web.ExposableServletEndpoint;
import org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
* {@link ManagementContextConfiguration} for servlet endpoints.
Expand All @@ -36,15 +39,6 @@
@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
public class ServletEndpointManagementContextConfiguration {

@Bean
public ServletEndpointRegistrar servletEndpointRegistrar(
WebEndpointProperties properties,
ServletEndpointsSupplier servletEndpointsSupplier) {
return new ServletEndpointRegistrar(properties.getBasePath(),
servletEndpointsSupplier.getEndpoints());
}

@Bean
public ExposeExcludePropertyEndpointFilter<ExposableServletEndpoint> servletExposeExcludePropertyEndpointFilter(
WebEndpointProperties properties) {
Expand All @@ -53,4 +47,35 @@ public ExposeExcludePropertyEndpointFilter<ExposableServletEndpoint> servletExpo
exposure.getInclude(), exposure.getExclude());
}

@Configuration
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
static class DifferentContextServletEndpointManagementContextConfiguration {
@Bean
public ServletEndpointRegistrar servletEndpointRegistrar(
WebEndpointProperties properties,
ServletEndpointsSupplier servletEndpointsSupplier) {
return new ServletEndpointRegistrar(properties.getBasePath(),
servletEndpointsSupplier.getEndpoints());
}
}

@Configuration
@ConditionalOnManagementPort(ManagementPortType.SAME)
static class SameContextServletEndpointManagementContextConfiguration {
@Bean
public ServletEndpointRegistrar servletEndpointRegistrar(
Environment environment,
WebEndpointProperties properties,
ServletEndpointsSupplier servletEndpointsSupplier) {
String servletPath = environment.getProperty("server.servlet.path");
if (servletPath == null) {
servletPath = "";
}
else if (servletPath.endsWith("/")) {
servletPath = servletPath.substring(0, servletPath.length() - 1);
}
return new ServletEndpointRegistrar(servletPath + properties.getBasePath(),
servletEndpointsSupplier.getEndpoints());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class WebEndpointProperties {
private final Exposure exposure = new Exposure();

/**
* Base path for Web endpoints. Relative to server.servlet.context-path or
* Base path for Web endpoints. Relative to server.servlet.context-path and server.servlet.path, or
* management.server.servlet.context-path if management.server.port is configured.
*/
private String basePath = "/actuator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ The preceding `application.properties` example changes the endpoint from
NOTE: Unless the management port has been configured to
<<production-ready-customizing-management-server-port,expose endpoints by using a
different HTTP port>>, `management.endpoints.web.base-path` is relative to
`server.servlet.context-path`. If `management.server.port` is configured,
`server.servlet.context-path` and `server.servlet.path`. If `management.server.port` is configured,
`management.endpoints.web.base-path` is relative to
`management.server.servlet.context-path`.

Expand Down