Commit b99faba3 by darkius Committed by Ryan Baxter

Fix management context path in URL (#2702) (#2769)

parent 57a6693d
......@@ -71,6 +71,10 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
private String refineManagementContextPath(String serverContextPath, String managementContextPath,
Integer managementPort) {
// management context path is relative to server context path when no management port is set
if (managementContextPath != null && managementPort == null) {
return serverContextPath + managementContextPath;
}
if(managementContextPath != null) {
return managementContextPath;
}
......@@ -86,7 +90,8 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
if (!contextPath.endsWith("/")) {
contextPath = contextPath + "/";
}
URL base = new URL(scheme, hostname, port, contextPath);
String refinedContextPath = '/' + StringUtils.trimLeadingCharacter(contextPath, '/') ;
URL base = new URL(scheme, hostname, port, refinedContextPath);
String refinedStatusPath = StringUtils.trimLeadingCharacter(statusPath, '/');
return new URL(base, refinedStatusPath).toString();
} catch (MalformedURLException e) {
......
......@@ -108,6 +108,20 @@ public class DefaultManagementMetadataProviderTest {
Integer managementPort = null;
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath, managementPort);
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/Server/Management/health");
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:7777/Server/Management/info");
assertThat(actual.getManagementPort()).isEqualTo(7777);
}
@Test
public void serverPortManagementContextPath() throws Exception {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
Integer managementPort = null;
ManagementMetadata actual = provider.get(INSTANCE, serverPort, serverContextPath, managementContextPath, managementPort);
assertThat(actual.getHealthCheckUrl()).isEqualTo("http://host:7777/Management/health");
assertThat(actual.getSecureHealthCheckUrl()).isNullOrEmpty();
assertThat(actual.getStatusPageUrl()).isEqualTo("http://host:7777/Management/info");
......
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