Deduplicates context path in health-check-url
fixes gh-3809
This commit is contained in:
@@ -123,7 +123,7 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
String refinedContextPath = '/'
|
||||
+ StringUtils.trimLeadingCharacter(contextPath, '/');
|
||||
URL base = new URL(scheme, hostname, port, refinedContextPath);
|
||||
String refinedStatusPath = StringUtils.trimLeadingCharacter(statusPath, '/');
|
||||
String refinedStatusPath = refinedStatusPath(statusPath, contextPath);
|
||||
return new URL(base, refinedStatusPath).toString();
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
@@ -133,6 +133,13 @@ public class DefaultManagementMetadataProvider implements ManagementMetadataProv
|
||||
}
|
||||
}
|
||||
|
||||
private String refinedStatusPath(String statusPath, String contextPath) {
|
||||
if (statusPath.startsWith(contextPath) && !"/".equals(contextPath)) {
|
||||
statusPath = StringUtils.replace(statusPath, contextPath, "");
|
||||
}
|
||||
return StringUtils.trimLeadingCharacter(statusPath, '/');
|
||||
}
|
||||
|
||||
private String getErrorMessage(String scheme, String hostname, int port,
|
||||
String contextPath, String statusPath) {
|
||||
return String.format(
|
||||
|
||||
@@ -325,6 +325,20 @@ public class EurekaClientAutoConfigurationTests {
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthCheckUrlPathWithServerPortAndContextPathKebobCase() {
|
||||
TestPropertyValues.of("server.port=8989",
|
||||
"server.servlet.context-path=/servletContextPath",
|
||||
"eureka.instance.health-check-url-path=${server.servlet.context-path:}/myHealthCheck")
|
||||
.applyTo(this.context);
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
assertThat(instance.getHealthCheckUrl())
|
||||
.as("Wrong health check: " + instance.getHealthCheckUrl())
|
||||
.endsWith(":8989/servletContextPath/myHealthCheck");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageUrlPathAndManagementPortKabobCase() {
|
||||
TestPropertyValues
|
||||
|
||||
Reference in New Issue
Block a user