Skip to content

Commit

Permalink
Fix AdminClientProperties not obtaining hostname from management.addr…
Browse files Browse the repository at this point in the history
…ess if set
  • Loading branch information
weeniearms committed Oct 11, 2016
1 parent a1e3d15 commit 5407f81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Expand Up @@ -95,16 +95,16 @@ && getServiceUrl() != null) {
"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());
}

Expand Down Expand Up @@ -133,13 +133,13 @@ public String getServiceUrl() {
"serviceUrl must be set when deployed to servlet-container");
}

InetAddress address = getHostAddress();
if (preferIp) {
InetAddress address = getHostAddress();
return append(createLocalUri(address.getHostAddress(), serverPort),
server.getContextPath());

}
return append(createLocalUri(getHostAddress().getCanonicalHostName(), serverPort),
return append(createLocalUri(address.getCanonicalHostName(), serverPort),
server.getContextPath());
}

Expand Down
Expand Up @@ -182,6 +182,22 @@ public void test_serveraddress() {
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() {
Expand Down

0 comments on commit 5407f81

Please sign in to comment.