Commit 7e32dfcc by Johannes Edmeier

Update to Spring Boot 2.0.0.M4

parent 232bb5f1
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M3</version> <version>2.0.0.M4</version>
<relativePath/> <relativePath/>
</parent> </parent>
<groupId>de.codecentric</groupId> <groupId>de.codecentric</groupId>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<main.basedir>${basedir}</main.basedir> <main.basedir>${basedir}</main.basedir>
<spring-boot.version>2.0.0.M3</spring-boot.version> <spring-boot.version>2.0.0.M4</spring-boot.version>
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version> <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
<build-plugin.jacoco.version>0.7.9</build-plugin.jacoco.version> <build-plugin.jacoco.version>0.7.9</build-plugin.jacoco.version>
<build-plugin.coveralls.version>4.3.0</build-plugin.coveralls.version> <build-plugin.coveralls.version>4.3.0</build-plugin.coveralls.version>
......
...@@ -31,6 +31,9 @@ import org.springframework.context.annotation.Profile; ...@@ -31,6 +31,9 @@ import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration @Configuration
@EnableAutoConfiguration @EnableAutoConfiguration
...@@ -61,9 +64,28 @@ public class SpringBootAdminApplication { ...@@ -61,9 +64,28 @@ public class SpringBootAdminApplication {
// Enable so that the clients can authenticate via HTTP basic for registering // Enable so that the clients can authenticate via HTTP basic for registering
http.httpBasic(); http.httpBasic();
} }
@Bean
@Override
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("user").password("pass").build());
return manager;
}
} }
// end::configuration-spring-security[] // end::configuration-spring-security[]
@Profile("insecure")
@Configuration
public static class DisableSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/**").permitAll();
}
}
@Configuration @Configuration
public static class NotifierConfig { public static class NotifierConfig {
private final InstanceRepository repository; private final InstanceRepository repository;
......
...@@ -25,30 +25,17 @@ spring: ...@@ -25,30 +25,17 @@ spring:
spring: spring:
profiles: insecure profiles: insecure
management:
security:
enabled: false
security:
basic:
enabled: false
--- ---
spring: spring:
profiles: secure profiles: secure
boot: boot:
admin: admin:
client: client:
username: "${security.user.name}" #These two are needed so that the client username: "user" #These two are needed so that the client
password: "${security.user.password}" #can register at the protected server api password: "pass" #can register at the protected server api
instance: instance:
metadata: metadata:
user.name: "${security.user.name}" #These two are needed so that the server user.name: "user" #These two are needed so that the server
user.password: "${security.user.password}" #can access the proteceted client endpoints user.password: "pass" #can access the proteceted client endpoints
security:
user:
name: user
password: pass
...@@ -29,7 +29,7 @@ import java.util.List; ...@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy { public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy {
...@@ -50,7 +50,7 @@ public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy { ...@@ -50,7 +50,7 @@ public class QueryIndexEndpointStrategy implements EndpointDetectionStrategy {
.filter(response -> response.statusCode().is2xxSuccessful() && .filter(response -> response.statusCode().is2xxSuccessful() &&
response.headers() response.headers()
.contentType() .contentType()
.map(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON::isCompatibleWith) .map(ActuatorMediaType.V2_JSON::isCompatibleWith)
.orElse(false)) .orElse(false))
.flatMap(r -> r.bodyToMono(Response.class)) .flatMap(r -> r.bodyToMono(Response.class))
.flatMap(this::convert); .flatMap(this::convert);
......
...@@ -24,7 +24,7 @@ import java.net.URI; ...@@ -24,7 +24,7 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -66,7 +66,7 @@ public class InstanceOperations { ...@@ -66,7 +66,7 @@ public class InstanceOperations {
public Mono<ClientResponse> exchange(HttpMethod method, Instance instance, URI uri) { public Mono<ClientResponse> exchange(HttpMethod method, Instance instance, URI uri) {
return webClient.method(method) return webClient.method(method)
.uri(uri) .uri(uri)
.accept(ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON, MediaType.APPLICATION_JSON) .accept(ActuatorMediaType.V2_JSON, MediaType.APPLICATION_JSON)
.headers(headers -> headers.putAll(httpHeadersProvider.getHeaders(instance))) .headers(headers -> headers.putAll(httpHeadersProvider.getHeaders(instance)))
.exchange() .exchange()
.doOnSubscribe((s) -> log.debug("Do {} on '{}' for {}", method, uri, instance)); .doOnSubscribe((s) -> log.debug("Do {} on '{}' for {}", method, uri, instance));
......
...@@ -132,7 +132,7 @@ public abstract class AbstractAdminApplicationTest { ...@@ -132,7 +132,7 @@ public abstract class AbstractAdminApplicationTest {
private Registration createRegistration() { private Registration createRegistration() {
return Registration.builder() return Registration.builder()
.name("Test-Instance") .name("Test-Instance")
.healthUrl("http://localhost:" + port + "/mgmt/health") .healthUrl("http://localhost:" + port + "/mgmt/status")
.managementUrl("http://localhost:" + port + "/mgmt") .managementUrl("http://localhost:" + port + "/mgmt")
.serviceUrl("http://localhost:" + port) .serviceUrl("http://localhost:" + port)
.build(); .build();
......
...@@ -42,7 +42,7 @@ public class AdminApplicationDiscoveryTest extends AbstractAdminApplicationTest ...@@ -42,7 +42,7 @@ public class AdminApplicationDiscoveryTest extends AbstractAdminApplicationTest
public void setUp() throws Exception { public void setUp() throws Exception {
instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class, instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--management.context-path=/mgmt", "--info.test=foobar", "--server.port=0", "--management.context-path=/mgmt", "--info.test=foobar",
"--management.security.enabled=false"); "--endpoints.health.enabled=true");
simpleDiscovery = instance.getBean(SimpleDiscoveryProperties.class); simpleDiscovery = instance.getBean(SimpleDiscoveryProperties.class);
......
...@@ -54,10 +54,10 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest ...@@ -54,10 +54,10 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
System.setProperty("hazelcast.wait.seconds.before.join", "0"); System.setProperty("hazelcast.wait.seconds.before.join", "0");
instance1 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class, instance1 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt", "--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt",
"--management.security.enabled=false", "--info.test=foobar"); "--info.test=foobar");
instance2 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class, instance2 = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt", "--server.port=0", "--spring.jmx.enabled=false", "--management.context-path=/mgmt",
"--management.security.enabled=false", "--info.test=foobar"); "--info.test=foobar");
super.setUp(instance1.getWebServer().getPort()); super.setUp(instance1.getWebServer().getPort());
this.webClient2 = createWebClient(instance2.getWebServer().getPort()); this.webClient2 = createWebClient(instance2.getWebServer().getPort());
...@@ -89,7 +89,7 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest ...@@ -89,7 +89,7 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
.getResponseBody() .getResponseBody()
.collect(Collectors.joining()); .collect(Collectors.joining());
StepVerifier.create(events1.and(events2)) StepVerifier.create(events1.zipWith(events2))
.assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2())) .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
.verifyComplete(); .verifyComplete();
} }
......
...@@ -30,8 +30,7 @@ public class AdminApplicationTest extends AbstractAdminApplicationTest { ...@@ -30,8 +30,7 @@ public class AdminApplicationTest extends AbstractAdminApplicationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class, instance = (ServletWebServerApplicationContext) SpringApplication.run(TestAdminApplication.class,
"--server.port=0", "--management.context-path=/mgmt", "--management.security.enabled=false", "--server.port=0", "--management.context-path=/mgmt", "--info.test=foobar");
"--info.test=foobar");
super.setUp(instance.getWebServer().getPort()); super.setUp(instance.getWebServer().getPort());
} }
......
...@@ -29,7 +29,7 @@ import java.util.HashMap; ...@@ -29,7 +29,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.actuate.endpoint.mvc.ActuatorMediaTypes; import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
...@@ -43,11 +43,10 @@ public class QueryIndexEndpointStrategyTest { ...@@ -43,11 +43,10 @@ public class QueryIndexEndpointStrategyTest {
private Mono<ClientResponse> responseNotFound = mockResponse(HttpStatus.NOT_FOUND, null, null); private Mono<ClientResponse> responseNotFound = mockResponse(HttpStatus.NOT_FOUND, null, null);
private Mono<ClientResponse> responseOkWrongContentType = mockResponse(HttpStatus.OK, MediaType.APPLICATION_JSON, private Mono<ClientResponse> responseOkWrongContentType = mockResponse(HttpStatus.OK, MediaType.APPLICATION_JSON,
null); null);
private Mono<ClientResponse> responseOk = mockResponse(HttpStatus.OK, private Mono<ClientResponse> responseOk = mockResponse(HttpStatus.OK, ActuatorMediaType.V2_JSON,
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON,
createBody("metrics=http://app/mgmt/stats", "info=http://app/mgmt/info", "self=http://app/mgmt")); createBody("metrics=http://app/mgmt/stats", "info=http://app/mgmt/info", "self=http://app/mgmt"));
private Mono<ClientResponse> responseOkEmpty = mockResponse(HttpStatus.OK, private Mono<ClientResponse> responseOkEmpty = mockResponse(HttpStatus.OK, ActuatorMediaType.V2_JSON,
ActuatorMediaTypes.APPLICATION_ACTUATOR_V2_JSON, createBody("self=http://app/mgmt")); createBody("self=http://app/mgmt"));
private Instance instance = Instance.create(InstanceId.of("id")) private Instance instance = Instance.create(InstanceId.of("id"))
.register(Registration.create("test", "http://app/mgmt/health") .register(Registration.create("test", "http://app/mgmt/health")
......
...@@ -23,8 +23,10 @@ import de.codecentric.boot.admin.client.registration.ServletApplicationFactory; ...@@ -23,8 +23,10 @@ import de.codecentric.boot.admin.client.registration.ServletApplicationFactory;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
...@@ -43,6 +45,7 @@ import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebA ...@@ -43,6 +45,7 @@ import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebA
@Configuration @Configuration
@EnableConfigurationProperties({ClientProperties.class, InstanceProperties.class}) @EnableConfigurationProperties({ClientProperties.class, InstanceProperties.class})
@Conditional(SpringBootAdminClientEnabledCondition.class) @Conditional(SpringBootAdminClientEnabledCondition.class)
@AutoConfigureAfter(WebMvcEndpointManagementContextConfiguration.class)
public class SpringBootAdminClientAutoConfiguration { public class SpringBootAdminClientAutoConfiguration {
@Configuration @Configuration
...@@ -53,9 +56,9 @@ public class SpringBootAdminClientAutoConfiguration { ...@@ -53,9 +56,9 @@ public class SpringBootAdminClientAutoConfiguration {
public ApplicationFactory applicationFactory(InstanceProperties instance, public ApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath, ServletContext servletContext,
ServletContext servletContext) { EndpointPathProvider endpointPathProvider) {
return new ServletApplicationFactory(instance, management, server, servletContext, healthEndpointPath); return new ServletApplicationFactory(instance, management, server, servletContext, endpointPathProvider);
} }
} }
...@@ -79,8 +82,8 @@ public class SpringBootAdminClientAutoConfiguration { ...@@ -79,8 +82,8 @@ public class SpringBootAdminClientAutoConfiguration {
public ApplicationFactory applicationFactory(InstanceProperties instance, public ApplicationFactory applicationFactory(InstanceProperties instance,
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
@Value("${endpoints.health.path:/${endpoints.health.id:health}}") String healthEndpointPath) { EndpointPathProvider endpointPathProvider) {
return new DefaultApplicationFactory(instance, management, server, healthEndpointPath); return new DefaultApplicationFactory(instance, management, server, endpointPathProvider);
} }
@Bean @Bean
......
...@@ -21,7 +21,8 @@ import de.codecentric.boot.admin.client.config.InstanceProperties; ...@@ -21,7 +21,8 @@ import de.codecentric.boot.admin.client.config.InstanceProperties;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map; import java.util.Map;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl;
...@@ -43,16 +44,16 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -43,16 +44,16 @@ public class DefaultApplicationFactory implements ApplicationFactory {
private ManagementServerProperties management; private ManagementServerProperties management;
private Integer localServerPort; private Integer localServerPort;
private Integer localManagementPort; private Integer localManagementPort;
private String healthEndpointPath; private EndpointPathProvider endpointPathProvider;
public DefaultApplicationFactory(InstanceProperties instance, public DefaultApplicationFactory(InstanceProperties instance,
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
String healthEndpointPath) { EndpointPathProvider endpointPathProvider) {
this.instance = instance; this.instance = instance;
this.management = management; this.management = management;
this.server = server; this.server = server;
this.healthEndpointPath = healthEndpointPath; this.endpointPathProvider = endpointPathProvider;
} }
@Override @Override
...@@ -89,7 +90,7 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -89,7 +90,7 @@ public class DefaultApplicationFactory implements ApplicationFactory {
.port(getLocalServerPort()); .port(getLocalServerPort());
} }
return builder.path("/").path(getServerContextPath()).path("/").toUriString(); return builder.path("/").path(getServerContextPath()).toUriString();
} }
protected String getServerContextPath() { protected String getServerContextPath() {
...@@ -101,22 +102,32 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -101,22 +102,32 @@ public class DefaultApplicationFactory implements ApplicationFactory {
return instance.getManagementUrl(); return instance.getManagementUrl();
} }
return UriComponentsBuilder.fromUriString(getManagementBaseUrl())
.path("/")
.path(getManagementContextPath())
.toUriString();
}
protected String getManagementBaseUrl() {
String baseUrl = instance.getManagementBaseUrl(); String baseUrl = instance.getManagementBaseUrl();
UriComponentsBuilder builder;
if (!StringUtils.isEmpty(baseUrl)) { if (!StringUtils.isEmpty(baseUrl)) {
builder = UriComponentsBuilder.fromUriString(baseUrl); return baseUrl;
} else if (isManagementPortEqual()) { }
builder = UriComponentsBuilder.fromHttpUrl(getServiceUrl()).path("/").path(getDispatcherServletPrefix());
} else { if (isManagementPortEqual()) {
Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl(); return UriComponentsBuilder.fromHttpUrl(getServiceUrl())
builder = UriComponentsBuilder.newInstance() .path("/")
.scheme(getScheme(ssl)) .path(getDispatcherServletPrefix())
.host(getManagementHost()) .toUriString();
.port(getLocalManagementPort());
} }
return builder.path("/").path(getManagementContextPath()).path("/").toUriString(); Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl();
return UriComponentsBuilder.newInstance()
.scheme(getScheme(ssl))
.host(getManagementHost())
.port(getLocalManagementPort())
.toUriString();
} }
protected String getDispatcherServletPrefix() { protected String getDispatcherServletPrefix() {
...@@ -135,10 +146,9 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -135,10 +146,9 @@ public class DefaultApplicationFactory implements ApplicationFactory {
if (instance.getHealthUrl() != null) { if (instance.getHealthUrl() != null) {
return instance.getHealthUrl(); return instance.getHealthUrl();
} }
return UriComponentsBuilder.fromHttpUrl(getManagementUrl()) return UriComponentsBuilder.fromHttpUrl(getManagementBaseUrl())
.path("/") .path("/")
.path(getHealthEndpointPath()) .path(getHealthEndpointPath())
.path("/")
.toUriString(); .toUriString();
} }
...@@ -179,7 +189,15 @@ public class DefaultApplicationFactory implements ApplicationFactory { ...@@ -179,7 +189,15 @@ public class DefaultApplicationFactory implements ApplicationFactory {
} }
protected String getHealthEndpointPath() { protected String getHealthEndpointPath() {
return healthEndpointPath; String health = endpointPathProvider.getPath("health");
if (StringUtils.hasText(health)) {
return health;
}
String status = endpointPathProvider.getPath("status");
if (StringUtils.hasText(status)) {
return status;
}
throw new IllegalStateException("Either health or status endpoint must be enabled!");
} }
protected String getScheme(Ssl ssl) { protected String getScheme(Ssl ssl) {
......
...@@ -19,7 +19,8 @@ package de.codecentric.boot.admin.client.registration; ...@@ -19,7 +19,8 @@ package de.codecentric.boot.admin.client.registration;
import de.codecentric.boot.admin.client.config.InstanceProperties; import de.codecentric.boot.admin.client.config.InstanceProperties;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
public class ServletApplicationFactory extends DefaultApplicationFactory { public class ServletApplicationFactory extends DefaultApplicationFactory {
...@@ -30,8 +31,8 @@ public class ServletApplicationFactory extends DefaultApplicationFactory { ...@@ -30,8 +31,8 @@ public class ServletApplicationFactory extends DefaultApplicationFactory {
ManagementServerProperties management, ManagementServerProperties management,
ServerProperties server, ServerProperties server,
ServletContext servletContext, ServletContext servletContext,
String healthEndpointPath) { EndpointPathProvider endpointPathProvider) {
super(instance, management, server, healthEndpointPath); super(instance, management, server, endpointPathProvider);
this.servletContext = servletContext; this.servletContext = servletContext;
this.servlet = server.getServlet(); this.servlet = server.getServlet();
} }
......
...@@ -42,7 +42,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify; ...@@ -42,7 +42,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
public class ClientServletApplicationTest { public class ClientServletApplicationTest {
private ConfigurableApplicationContext instance; private ConfigurableApplicationContext instance;
private WireMockServer wiremock; private WireMockServer wiremock;
...@@ -60,8 +59,8 @@ public class ClientServletApplicationTest { ...@@ -60,8 +59,8 @@ public class ClientServletApplicationTest {
stubFor(post(urlEqualTo("/instances")).willReturn(response)); stubFor(post(urlEqualTo("/instances")).willReturn(response));
instance = SpringApplication.run(TestClientApplication.class, "--spring.main.web-application-type=servlet", instance = SpringApplication.run(TestClientApplication.class, "--spring.main.web-application-type=servlet",
"--spring.application.name=Test-Client", "--server.port=0", "--management.port=0", "--spring.application.name=Test-Client", "--server.port=0", "--management.context-path=/mgmt",
"--management.context-path=/mgmt", "--endpoints.health.enabled=true",
"--spring.boot.admin.client.url=http://localhost:" + wiremock.port()); "--spring.boot.admin.client.url=http://localhost:" + wiremock.port());
} }
...@@ -71,8 +70,8 @@ public class ClientServletApplicationTest { ...@@ -71,8 +70,8 @@ public class ClientServletApplicationTest {
String serviceHost = "http://localhost:" + instance.getEnvironment().getProperty("local.server.port"); String serviceHost = "http://localhost:" + instance.getEnvironment().getProperty("local.server.port");
String managementHost = "http://localhost:" + instance.getEnvironment().getProperty("local.management.port"); String managementHost = "http://localhost:" + instance.getEnvironment().getProperty("local.management.port");
String body = "{ \"name\" : \"Test-Client\"," + // String body = "{ \"name\" : \"Test-Client\"," + //
" \"managementUrl\" : \"" + managementHost + "/mgmt/\"," + // " \"managementUrl\" : \"" + managementHost + "/mgmt\"," + //
" \"healthUrl\" : \"" + managementHost + "/mgmt/health/\"," + // " \"healthUrl\" : \"" + managementHost + "/mgmt/health\"," + //
" \"serviceUrl\" : \"" + serviceHost + "/\", " + // " \"serviceUrl\" : \"" + serviceHost + "/\", " + //
" \"metadata\" : {} }"; " \"metadata\" : {} }";
RequestPatternBuilder request = postRequestedFor(urlEqualTo("/instances")).withHeader("Content-Type", RequestPatternBuilder request = postRequestedFor(urlEqualTo("/instances")).withHeader("Content-Type",
......
...@@ -23,7 +23,8 @@ import java.net.UnknownHostException; ...@@ -23,7 +23,8 @@ import java.net.UnknownHostException;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl;
...@@ -39,8 +40,10 @@ public class DefaultApplicationFactoryTest { ...@@ -39,8 +40,10 @@ public class DefaultApplicationFactoryTest {
private InstanceProperties instanceProperties = new InstanceProperties(); private InstanceProperties instanceProperties = new InstanceProperties();
private ServerProperties server = new ServerProperties(); private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties(); private ManagementServerProperties management = new ManagementServerProperties();
private EndpointPathProvider endpointPathProvider = mock(EndpointPathProvider.class);
private DefaultApplicationFactory factory = new DefaultApplicationFactory(instanceProperties, management, server, private DefaultApplicationFactory factory = new DefaultApplicationFactory(instanceProperties, management, server,
"/health"); endpointPathProvider);
@Before @Before
public void setup() { public void setup() {
...@@ -50,24 +53,23 @@ public class DefaultApplicationFactoryTest { ...@@ -50,24 +53,23 @@ public class DefaultApplicationFactoryTest {
@Test @Test
public void test_mgmtPortPath() { public void test_mgmtPortPath() {
management.setContextPath("/admin"); management.setContextPath("/admin");
DefaultApplicationFactory factory = new DefaultApplicationFactory(instanceProperties, management, server, when(endpointPathProvider.getPath("health")).thenReturn("/admin/alive");
"/alive");
publishApplicationReadyEvent(factory, 8080, 8081); publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/alive/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/alive");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
} }
@Test @Test
public void test_default() { public void test_default() {
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, null); publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/application/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
} }
...@@ -75,11 +77,12 @@ public class DefaultApplicationFactoryTest { ...@@ -75,11 +77,12 @@ public class DefaultApplicationFactoryTest {
public void test_ssl() { public void test_ssl() {
server.setSsl(new Ssl()); server.setSsl(new Ssl());
server.getSsl().setEnabled(true); server.getSsl().setEnabled(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, null); publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":8080/application/"); assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":8080/application");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":8080/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":8080/application/health");
assertThat(app.getServiceUrl()).isEqualTo("https://" + getHostname() + ":8080/"); assertThat(app.getServiceUrl()).isEqualTo("https://" + getHostname() + ":8080/");
} }
...@@ -87,17 +90,19 @@ public class DefaultApplicationFactoryTest { ...@@ -87,17 +90,19 @@ public class DefaultApplicationFactoryTest {
public void test_ssl_management() { public void test_ssl_management() {
management.setSsl(new Ssl()); management.setSsl(new Ssl());
management.getSsl().setEnabled(true); management.getSsl().setEnabled(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, 9090); publishApplicationReadyEvent(factory, 8080, 9090);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":9090/application/"); assertThat(app.getManagementUrl()).isEqualTo("https://" + getHostname() + ":9090/application");
assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":9090/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("https://" + getHostname() + ":9090/application/alive");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/");
} }
@Test @Test
public void test_preferIpAddress_serveraddress_missing() { public void test_preferIpAddress_serveraddress_missing() {
instanceProperties.setPreferIp(true); instanceProperties.setPreferIp(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, null); publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
...@@ -107,11 +112,11 @@ public class DefaultApplicationFactoryTest { ...@@ -107,11 +112,11 @@ public class DefaultApplicationFactoryTest {
@Test @Test
public void test_preferIpAddress_managementaddress_missing() { public void test_preferIpAddress_managementaddress_missing() {
instanceProperties.setPreferIp(true); instanceProperties.setPreferIp(true);
when(endpointPathProvider.getPath("health")).thenReturn("/application/alive");
publishApplicationReadyEvent(factory, 8080, 8081); publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).matches( assertThat(app.getManagementUrl()).matches("http://\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}:8081/application");
"http://\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}\\.\\d{0,3}:8081/application/");
} }
@Test @Test
...@@ -119,11 +124,12 @@ public class DefaultApplicationFactoryTest { ...@@ -119,11 +124,12 @@ public class DefaultApplicationFactoryTest {
instanceProperties.setPreferIp(true); instanceProperties.setPreferIp(true);
server.setAddress(InetAddress.getByName("127.0.0.1")); server.setAddress(InetAddress.getByName("127.0.0.1"));
management.setAddress(InetAddress.getByName("127.0.0.2")); management.setAddress(InetAddress.getByName("127.0.0.2"));
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 8080, 8081); publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://127.0.0.2:8081/application/"); assertThat(app.getManagementUrl()).isEqualTo("http://127.0.0.2:8081/application");
assertThat(app.getHealthUrl()).isEqualTo("http://127.0.0.2:8081/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://127.0.0.2:8081/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://127.0.0.1:8080/"); assertThat(app.getServiceUrl()).isEqualTo("http://127.0.0.1:8080/");
} }
...@@ -144,22 +150,24 @@ public class DefaultApplicationFactoryTest { ...@@ -144,22 +150,24 @@ public class DefaultApplicationFactoryTest {
instanceProperties.setManagementBaseUrl("http://management:8090"); instanceProperties.setManagementBaseUrl("http://management:8090");
instanceProperties.setServiceBaseUrl("http://service:80"); instanceProperties.setServiceBaseUrl("http://service:80");
management.setContextPath("/admin"); management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getServiceUrl()).isEqualTo("http://service:80/"); assertThat(app.getServiceUrl()).isEqualTo("http://service:80/");
assertThat(app.getManagementUrl()).isEqualTo("http://management:8090/admin/"); assertThat(app.getManagementUrl()).isEqualTo("http://management:8090/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://management:8090/admin/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://management:8090/admin/health");
} }
@Test @Test
public void test_service_baseUrl() { public void test_service_baseUrl() {
instanceProperties.setServiceBaseUrl("http://service:80"); instanceProperties.setServiceBaseUrl("http://service:80");
management.setContextPath("/admin"); management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getServiceUrl()).isEqualTo("http://service:80/"); assertThat(app.getServiceUrl()).isEqualTo("http://service:80/");
assertThat(app.getManagementUrl()).isEqualTo("http://service:80/admin/"); assertThat(app.getManagementUrl()).isEqualTo("http://service:80/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://service:80/admin/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://service:80/admin/health");
} }
@Test @Test
......
...@@ -23,7 +23,8 @@ import java.net.UnknownHostException; ...@@ -23,7 +23,8 @@ import java.net.UnknownHostException;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.EndpointPathProvider;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.mock.env.MockEnvironment; import org.springframework.mock.env.MockEnvironment;
...@@ -39,8 +40,9 @@ public class ServletApplicationFactoryTest { ...@@ -39,8 +40,9 @@ public class ServletApplicationFactoryTest {
private ServerProperties server = new ServerProperties(); private ServerProperties server = new ServerProperties();
private ManagementServerProperties management = new ManagementServerProperties(); private ManagementServerProperties management = new ManagementServerProperties();
private MockServletContext servletContext = new MockServletContext(); private MockServletContext servletContext = new MockServletContext();
private EndpointPathProvider endpointPathProvider = mock(EndpointPathProvider.class);
private ServletApplicationFactory factory = new ServletApplicationFactory(instance, management, server, private ServletApplicationFactory factory = new ServletApplicationFactory(instance, management, server,
servletContext, "/health"); servletContext, endpointPathProvider);
@Before @Before
public void setup() { public void setup() {
...@@ -51,47 +53,51 @@ public class ServletApplicationFactoryTest { ...@@ -51,47 +53,51 @@ public class ServletApplicationFactoryTest {
public void test_contextPath_mgmtPath() { public void test_contextPath_mgmtPath() {
servletContext.setContextPath("app"); servletContext.setContextPath("app");
management.setContextPath("/admin"); management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
publishApplicationReadyEvent(factory, 8080, null); publishApplicationReadyEvent(factory, 8080, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8080/app/admin/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
} }
@Test @Test
public void test_contextPath_mgmtPortPath() { public void test_contextPath_mgmtPortPath() {
servletContext.setContextPath("app"); servletContext.setContextPath("app");
management.setContextPath("/admin"); management.setContextPath("/admin");
when(endpointPathProvider.getPath("health")).thenReturn("/admin/health");
publishApplicationReadyEvent(factory, 8080, 8081); publishApplicationReadyEvent(factory, 8080, 8081);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":8081/admin");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":8081/admin/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":8080/app");
} }
@Test @Test
public void test_contextPath() { public void test_contextPath() {
servletContext.setContextPath("app"); servletContext.setContextPath("app");
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 80, null); publishApplicationReadyEvent(factory, 80, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/app/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/app/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/app/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/app");
} }
@Test @Test
public void test_servletPath() { public void test_servletPath() {
server.getServlet().setPath("app"); server.getServlet().setPath("app");
servletContext.setContextPath("srv"); servletContext.setContextPath("srv");
when(endpointPathProvider.getPath("health")).thenReturn("/application/health");
publishApplicationReadyEvent(factory, 80, null); publishApplicationReadyEvent(factory, 80, null);
Application app = factory.createApplication(); Application app = factory.createApplication();
assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/"); assertThat(app.getManagementUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application");
assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/health/"); assertThat(app.getHealthUrl()).isEqualTo("http://" + getHostname() + ":80/srv/app/application/health");
assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/srv/"); assertThat(app.getServiceUrl()).isEqualTo("http://" + getHostname() + ":80/srv");
} }
private String getHostname() { private String getHostname() {
......
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