Commit e8d80584 by weeniearms Committed by Johannes Edmeier

Use hostname of server/management.adress if set

If server.address or management.adress is set use it's value to resolve the hostname used for management-/service-url.
parent 03624266
......@@ -95,16 +95,16 @@ public class AdminClientProperties {
"serviceUrl must be set when deployed to servlet-container");
}
InetAddress address = management.getAddress();
if (address == null) {
address = getHostAddress();
}
if (preferIp) {
InetAddress address = management.getAddress();
if (address == null) {
address = getHostAddress();
}
return append(append(createLocalUri(address.getHostAddress(), managementPort),
server.getContextPath()), management.getContextPath());
}
return append(createLocalUri(getHostAddress().getCanonicalHostName(), managementPort),
return append(createLocalUri(address.getCanonicalHostName(), managementPort),
management.getContextPath());
}
......@@ -133,16 +133,13 @@ public class AdminClientProperties {
"serviceUrl must be set when deployed to servlet-container");
}
InetAddress address = getHostAddress();
if (preferIp) {
InetAddress address = server.getAddress();
if (address == null) {
address = getHostAddress();
}
return append(createLocalUri(address.getHostAddress(), serverPort),
server.getContextPath());
}
return append(createLocalUri(getHostAddress().getCanonicalHostName(), serverPort),
return append(createLocalUri(address.getCanonicalHostName(), serverPort),
server.getContextPath());
}
......@@ -183,7 +180,8 @@ public class AdminClientProperties {
private InetAddress getHostAddress() {
try {
return InetAddress.getLocalHost();
InetAddress address = server.getAddress();
return address != null ? address : InetAddress.getLocalHost();
} catch (UnknownHostException ex) {
throw new IllegalArgumentException(ex.getMessage(), ex);
}
......
......@@ -173,6 +173,33 @@ public class AdminClientPropertiesTest {
assertThat(clientProperties.getServiceUrl(), is("http://127.0.0.1:8080"));
}
@Test
public void test_serveraddress() {
load("server.address=127.0.0.2", "local.server.port=8080");
AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getServiceUrl(), is("http://127.0.0.2:8080"));
assertThat(clientProperties.getManagementUrl(), is("http://127.0.0.2:8080"));
assertThat(clientProperties.getHealthUrl(), is("http://127.0.0.2:8080/health"));
}
@Test
public void test_managementaddress() {
load("server.address=127.0.0.2", "management.address=127.0.0.3", "local.server.port=8080",
"local.management.port=8081");
AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getServiceUrl(), is("http://127.0.0.2:8080"));
assertThat(clientProperties.getManagementUrl(), is("http://127.0.0.3:8081"));
assertThat(clientProperties.getHealthUrl(), is("http://127.0.0.3:8081/health"));
}
private String getHostname() {
try {
return InetAddress.getLocalHost().getCanonicalHostName();
......
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