Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc65995

Browse files
authored
Allow null values for healthcheck (Netflix#1402)
1 parent 17ea7ca commit dc65995

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,15 @@ public Builder setHealthCheckUrls(String relativeUrl,
669669
if (explicitUrl != null) {
670670
result.healthCheckUrl = explicitUrl.replace(
671671
hostNameInterpolationExpression, result.hostName);
672-
} else if (result.isUnsecurePortEnabled) {
672+
} else if (result.isUnsecurePortEnabled && relativeUrl != null) {
673673
result.healthCheckUrl = HTTP_PROTOCOL + result.hostName + COLON
674674
+ result.port + relativeUrl;
675675
}
676676

677677
if (secureExplicitUrl != null) {
678678
result.secureHealthCheckUrl = secureExplicitUrl.replace(
679679
hostNameInterpolationExpression, result.hostName);
680-
} else if (result.isSecurePortEnabled) {
680+
} else if (result.isSecurePortEnabled && relativeUrl != null) {
681681
result.secureHealthCheckUrl = HTTPS_PROTOCOL + result.hostName
682682
+ COLON + result.securePort + relativeUrl;
683683
}

eureka-client/src/test/java/com/netflix/appinfo/InstanceInfoTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ public void testHealthCheckSetContainsValidUrlEntries() throws Exception {
106106
assertThat(instanceInfo.getHealthCheckUrls().size(), is(equalTo(2)));
107107
}
108108

109+
@Test
110+
public void testNullUrlEntries() throws Exception {
111+
Builder builder = newBuilder()
112+
.setAppName("test")
113+
.setNamespace("eureka.")
114+
.setHostName("localhost")
115+
.setPort(80)
116+
.setSecurePort(443)
117+
.setHealthCheckUrls(null, null, null)
118+
.setStatusPageUrl(null, null)
119+
.setHomePageUrl(null, null)
120+
.enablePort(PortType.SECURE, true);
121+
122+
// No URLs for healthcheck , status , homepage
123+
InstanceInfo noHealtcheckInstanceInfo = builder.build();
124+
assertThat(noHealtcheckInstanceInfo.getHealthCheckUrls().size(), is(equalTo(0)));
125+
assertThat(noHealtcheckInstanceInfo.getStatusPageUrl(), nullValue());
126+
assertThat(noHealtcheckInstanceInfo.getHomePageUrl(), nullValue());
127+
}
128+
109129
@Test
110130
public void testGetIdWithInstanceIdUsed() {
111131
InstanceInfo baseline = InstanceInfoGenerator.takeOne();

0 commit comments

Comments
 (0)