set proper status and health eureka urls if prefer ip address is set
This commit is contained in:
committed by
Ryan Baxter
parent
94358489ef
commit
9deab33dc1
@@ -135,6 +135,7 @@ public class EurekaClientAutoConfiguration {
|
||||
String hostname = eurekaPropertyResolver.getProperty("hostname");
|
||||
|
||||
boolean preferIpAddress = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("preferIpAddress"));
|
||||
String ipAddress = eurekaPropertyResolver.getProperty("ipAddress");
|
||||
boolean isSecurePortEnabled = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("securePortEnabled"));
|
||||
String serverContextPath = propertyResolver.getProperty("server.contextPath", "/");
|
||||
int serverPort = Integer.valueOf(propertyResolver.getProperty("server.port", propertyResolver.getProperty("port", "8080")));
|
||||
@@ -147,6 +148,9 @@ public class EurekaClientAutoConfiguration {
|
||||
instance.setNonSecurePort(serverPort);
|
||||
instance.setInstanceId(getDefaultInstanceId(propertyResolver));
|
||||
instance.setPreferIpAddress(preferIpAddress);
|
||||
if (StringUtils.hasText(ipAddress)) {
|
||||
instance.setIpAddress(ipAddress);
|
||||
}
|
||||
|
||||
if(isSecurePortEnabled) {
|
||||
instance.setSecurePort(serverPort);
|
||||
|
||||
@@ -289,6 +289,25 @@ public class EurekaClientAutoConfigurationTests {
|
||||
|
||||
assertEquals("statusPageUrl is wrong", "http://" + instance.getIpAddress() + ":9999/info",
|
||||
instance.getStatusPageUrl());
|
||||
assertEquals("healthCheckUrl is wrong", "http://" + instance.getIpAddress() + ":9999/health",
|
||||
instance.getHealthCheckUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusPageAndHealthCheckUrlsShouldSetUserDefinedIpAddress() {
|
||||
addEnvironment(this.context, "server.port=8989",
|
||||
"management.port=9999", "eureka.instance.hostname=foo",
|
||||
"eureka.instance.ipAddress:192.168.13.90",
|
||||
"eureka.instance.preferIpAddress:true");
|
||||
|
||||
setupContext(RefreshAutoConfiguration.class);
|
||||
EurekaInstanceConfigBean instance = this.context
|
||||
.getBean(EurekaInstanceConfigBean.class);
|
||||
|
||||
assertEquals("statusPageUrl is wrong", "http://192.168.13.90:9999/info",
|
||||
instance.getStatusPageUrl());
|
||||
assertEquals("healthCheckUrl is wrong", "http://192.168.13.90:9999/health",
|
||||
instance.getHealthCheckUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user