Skip to content

Commit

Permalink
Apply management server base path to webflux application registration…
Browse files Browse the repository at this point in the history
…s with management port, resolves #2169 (#2170)
  • Loading branch information
rainerfrey-inxmail committed Dec 2, 2022
1 parent 320eab1 commit 702c951
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
import org.springframework.boot.actuate.endpoint.web.PathMappedEndpoints;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.boot.web.server.Ssl;
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponentsBuilder;

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

public class ReactiveApplicationFactory extends DefaultApplicationFactory {

private ManagementServerProperties management;

private final ServerProperties server;

private WebFluxProperties webflux;

private InstanceProperties instance;
Expand All @@ -36,6 +42,8 @@ public ReactiveApplicationFactory(InstanceProperties instance, ManagementServerP
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
MetadataContributor metadataContributor, WebFluxProperties webFluxProperties) {
super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
this.management = management;
this.server = server;
this.webflux = webFluxProperties;
this.instance = instance;
}
Expand All @@ -50,6 +58,27 @@ protected String getServiceUrl() {
.toUriString();
}

@Override
protected String getManagementBaseUrl() {
String baseUrl = this.instance.getManagementBaseUrl();

if (StringUtils.hasText(baseUrl)) {
return baseUrl;
}

if (isManagementPortEqual()) {
return this.getServiceUrl();
}

Ssl ssl = (this.management.getSsl() != null) ? this.management.getSsl() : this.server.getSsl();
return UriComponentsBuilder.newInstance().scheme(getScheme(ssl)).host(getManagementHost())
.port(getLocalManagementPort()).path(getManagementContextPath()).toUriString();
}

protected String getManagementContextPath() {
return management.getBasePath();
}

protected String getWebfluxBasePath() {
return webflux.getBasePath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ public void test_noBasePath() {
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/");
}

@Test
public void test_mgmtBasePath_mgmtPortPath() {
webflux.setBasePath("/app");
management.setBasePath("/mgnt");
when(pathMappedEndpoints.getPath(EndpointId.of("health"))).thenReturn("/actuator/health");
publishApplicationReadyEvent(factory, 8080, 8081);

Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/mgnt/actuator");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/mgnt/actuator/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
}

private String getHostname() {
try {
return InetAddress.getLocalHost().getCanonicalHostName();
Expand Down

0 comments on commit 702c951

Please sign in to comment.