Skip to content

Commit 702c951

Browse files
Apply management server base path to webflux application registrations with management port, resolves #2169 (#2170)
1 parent 320eab1 commit 702c951

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spring-boot-admin-client/src/main/java/de/codecentric/boot/admin/client/registration/ReactiveApplicationFactory.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
2222
import org.springframework.boot.autoconfigure.web.ServerProperties;
2323
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
24+
import org.springframework.boot.web.server.Ssl;
25+
import org.springframework.util.StringUtils;
2426
import org.springframework.web.util.UriComponentsBuilder;
2527

2628
import de.codecentric.boot.admin.client.config.InstanceProperties;
2729
import de.codecentric.boot.admin.client.registration.metadata.MetadataContributor;
2830

2931
public class ReactiveApplicationFactory extends DefaultApplicationFactory {
3032

33+
private ManagementServerProperties management;
34+
35+
private final ServerProperties server;
36+
3137
private WebFluxProperties webflux;
3238

3339
private InstanceProperties instance;
@@ -36,6 +42,8 @@ public ReactiveApplicationFactory(InstanceProperties instance, ManagementServerP
3642
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
3743
MetadataContributor metadataContributor, WebFluxProperties webFluxProperties) {
3844
super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
45+
this.management = management;
46+
this.server = server;
3947
this.webflux = webFluxProperties;
4048
this.instance = instance;
4149
}
@@ -50,6 +58,27 @@ protected String getServiceUrl() {
5058
.toUriString();
5159
}
5260

61+
@Override
62+
protected String getManagementBaseUrl() {
63+
String baseUrl = this.instance.getManagementBaseUrl();
64+
65+
if (StringUtils.hasText(baseUrl)) {
66+
return baseUrl;
67+
}
68+
69+
if (isManagementPortEqual()) {
70+
return this.getServiceUrl();
71+
}
72+
73+
Ssl ssl = (this.management.getSsl() != null) ? this.management.getSsl() : this.server.getSsl();
74+
return UriComponentsBuilder.newInstance().scheme(getScheme(ssl)).host(getManagementHost())
75+
.port(getLocalManagementPort()).path(getManagementContextPath()).toUriString();
76+
}
77+
78+
protected String getManagementContextPath() {
79+
return management.getBasePath();
80+
}
81+
5382
protected String getWebfluxBasePath() {
5483
return webflux.getBasePath();
5584
}

spring-boot-admin-client/src/test/java/de/codecentric/boot/admin/client/registration/ReactiveApplicationFactoryTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ public void test_noBasePath() {
109109
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/");
110110
}
111111

112+
@Test
113+
public void test_mgmtBasePath_mgmtPortPath() {
114+
webflux.setBasePath("/app");
115+
management.setBasePath("/mgnt");
116+
when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
117+
publishApplicationReadyEvent(factory, 8080, 8081);
118+
119+
Application app = factory.createApplication();
120+
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/mgnt/actuator");
121+
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/mgnt/actuator/health");
122+
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
123+
}
124+
112125
private String getHostname() {
113126
try {
114127
return InetAddress.getLocalHost().getCanonicalHostName();

0 commit comments

Comments
 (0)