Commit afba8fed authored by Stephane Nicoll's avatar Stephane Nicoll

Harmonize management.server.context-path property

This commit moves management.server.context-path to
management.server.servlet.context-path to align with the configuration
key for the application's main context path.

Closes gh-11359
parent 53285084
......@@ -36,7 +36,7 @@ public class WebEndpointProperties {
/**
* Base path for Web endpoints. Relative to server.servlet.context-path or
* management.server.context-path if management.server.port is configured.
* management.server.servlet.context-path if management.server.port is configured.
*/
private String basePath = "/actuator";
......
......@@ -43,20 +43,16 @@ public class ManagementServerProperties implements SecurityPrerequisite {
*/
private Integer port;
@NestedConfigurationProperty
private Ssl ssl;
/**
* Network address that to which the management endpoints should bind to. Requires a
* custom management.server.port.
*/
private InetAddress address;
/**
* Management endpoint context-path. For instance, '/actuator'. Requires a custom
* management.server.port.
*/
private String contextPath = "";
private final Servlet servlet = new Servlet();
@NestedConfigurationProperty
private Ssl ssl;
/**
* Add the "X-Application-Context" HTTP header in each response.
......@@ -82,6 +78,14 @@ public class ManagementServerProperties implements SecurityPrerequisite {
this.port = port;
}
public InetAddress getAddress() {
return this.address;
}
public void setAddress(InetAddress address) {
this.address = address;
}
public Ssl getSsl() {
return this.ssl;
}
......@@ -90,14 +94,29 @@ public class ManagementServerProperties implements SecurityPrerequisite {
this.ssl = ssl;
}
public InetAddress getAddress() {
return this.address;
public Servlet getServlet() {
return this.servlet;
}
public void setAddress(InetAddress address) {
this.address = address;
public boolean getAddApplicationContextHeader() {
return this.addApplicationContextHeader;
}
public void setAddApplicationContextHeader(boolean addApplicationContextHeader) {
this.addApplicationContextHeader = addApplicationContextHeader;
}
/**
* Servlet properties.
*/
public class Servlet {
/**
* Management endpoint context-path. For instance, '/management'. Requires a
* custom management.server.port.
*/
private String contextPath = "";
/**
* Return the context path with no trailing slash (i.e. the '/' root context is
* represented as the empty string).
......@@ -119,12 +138,6 @@ public class ManagementServerProperties implements SecurityPrerequisite {
return contextPath;
}
public boolean getAddApplicationContextHeader() {
return this.addApplicationContextHeader;
}
public void setAddApplicationContextHeader(boolean addApplicationContextHeader) {
this.addApplicationContextHeader = addApplicationContextHeader;
}
}
......@@ -103,7 +103,8 @@ class ServletManagementChildContextConfiguration {
ServerProperties serverProperties) {
super.customize(webServerFactory, managementServerProperties,
serverProperties);
webServerFactory.setContextPath(managementServerProperties.getContextPath());
webServerFactory.setContextPath(
managementServerProperties.getServlet().getContextPath());
}
}
......
......@@ -1112,7 +1112,7 @@
"description": "Management endpoint context-path.",
"defaultValue": "",
"deprecation": {
"replacement": "management.server.context-path",
"replacement": "management.server.servlet.context-path",
"level": "error"
}
},
......
......@@ -46,7 +46,7 @@ public class ManagementServerPropertiesTests {
public void defaultManagementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties();
assertThat(properties.getPort()).isNull();
assertThat(properties.getContextPath()).isEqualTo("");
assertThat(properties.getServlet().getContextPath()).isEqualTo("");
assertThat(properties.getAddApplicationContextHeader()).isEqualTo(false);
}
......@@ -54,23 +54,23 @@ public class ManagementServerPropertiesTests {
public void definedManagementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setPort(123);
properties.setContextPath("/foo");
properties.getServlet().setContextPath("/foo");
assertThat(properties.getPort()).isEqualTo(123);
assertThat(properties.getContextPath()).isEqualTo("/foo");
assertThat(properties.getServlet().getContextPath()).isEqualTo("/foo");
}
@Test
public void trailingSlashOfContextPathIsRemoved() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setContextPath("/foo/");
assertThat(properties.getContextPath()).isEqualTo("/foo");
properties.getServlet().setContextPath("/foo/");
assertThat(properties.getServlet().getContextPath()).isEqualTo("/foo");
}
@Test
public void slashOfContextPathIsDefaultValue() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setContextPath("/");
assertThat(properties.getContextPath()).isEqualTo("");
properties.getServlet().setContextPath("/");
assertThat(properties.getServlet().getContextPath()).isEqualTo("");
}
public ManagementServerProperties load(String... environment) {
......
......@@ -1080,8 +1080,8 @@ content into your application. Rather, pick only the properties that you need.
# MANAGEMENT HTTP SERVER ({sc-spring-boot-actuator-autoconfigure}/web/server/ManagementServerProperties.{sc-ext}[ManagementServerProperties])
management.server.add-application-context-header=false # Add the "X-Application-Context" HTTP header in each response. Requires a custom management.server.port.
management.server.address= # Network address that to which the management endpoints should bind. Requires a custom management.server.port.
management.server.context-path= # Management endpoint context-path. For instance, `/actuator`. Requires a custom management.server.port
management.server.port= # Management endpoint HTTP port. Uses the same port as the application by default. Configure a different port to use management-specific SSL.
management.server.servlet.context-path= # Management endpoint context-path. For instance, `/management`. Requires a custom management.server.port
management.server.ssl.ciphers= # Supported SSL ciphers. Requires a custom management.port.
management.server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. Requires a custom management.server.port.
management.server.ssl.enabled= # Whether to enable SSL support. Requires a custom management.server.port.
......@@ -1117,7 +1117,7 @@ content into your application. Rather, pick only the properties that you need.
management.endpoints.web.enabled=true # Whether web endpoints are enabled
management.endpoints.web.expose=info,health # Endpoint IDs that should be exposed or '*' for all.
management.endpoints.web.exclude= # Endpoint IDs that should be excluded.
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.context-path if management.server.port is configured.
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.servlet.context-path if management.server.port is configured.
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them.
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/servlet/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties])
......
......@@ -691,7 +691,8 @@ NOTE: Unless the management port has been configured to
<<production-ready-customizing-management-server-port,expose endpoints using a different
HTTP port>>, `management.endpoints.web.base-path` is relative to
`server.servlet.context-path`. If `management.server.port` is configured,
`management.endpoints.web.base-path` is relative to `management.server.context-path`.
`management.endpoints.web.base-path` is relative to
`management.server.servlet.context-path`.
......
......@@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.server.port=0", "management.server.context-path=/management" })
"management.server.port=0", "management.server.servlet.context-path=/management" })
public class ManagementPortAndPathSampleActuatorApplicationTests {
@LocalServerPort
......
......@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.server.port=0", "management.server.address=127.0.0.1",
"management.server.context-path:/admin" })
"management.server.servlet.context-path:/admin" })
public class ManagementAddressActuatorApplicationTests {
@LocalServerPort
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment