|
|
|
@ -16,6 +16,9 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.web.servlet;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
@ -24,6 +27,7 @@ import java.util.function.Function;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
import jakarta.validation.constraints.NotEmpty;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
|
|
|
|
@ -36,13 +40,18 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
|
|
|
|
|
import org.springframework.boot.convert.ApplicationConversionService;
|
|
|
|
|
import org.springframework.boot.env.ConfigTreePropertySource;
|
|
|
|
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
|
|
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
|
import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer;
|
|
|
|
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
|
|
import org.springframework.core.convert.support.ConfigurableConversionService;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
@ -74,6 +83,9 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests {
|
|
|
|
|
"management.endpoints.web.exposure.include=*", "server.error.include-exception=true",
|
|
|
|
|
"server.error.include-message=always", "server.error.include-binding-errors=always");
|
|
|
|
|
|
|
|
|
|
@TempDir
|
|
|
|
|
Path temp;
|
|
|
|
|
|
|
|
|
|
@Test // gh-17938
|
|
|
|
|
void errorEndpointIsUsedWithEndpoint() {
|
|
|
|
|
this.runner.run(withWebTestClient((client) -> {
|
|
|
|
@ -134,6 +146,28 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests {
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test // gh-32941
|
|
|
|
|
void whenManagementServerPortLoadedFromConfigTree() {
|
|
|
|
|
this.runner.withInitializer(this::addConfigTreePropertySource)
|
|
|
|
|
.run((context) -> assertThat(context).hasNotFailed());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addConfigTreePropertySource(ConfigurableApplicationContext applicationContext) {
|
|
|
|
|
try {
|
|
|
|
|
applicationContext.getEnvironment().setConversionService(
|
|
|
|
|
(ConfigurableConversionService) ApplicationConversionService.getSharedInstance());
|
|
|
|
|
Path configtree = this.temp.resolve("configtree");
|
|
|
|
|
Path file = configtree.resolve("management/server/port");
|
|
|
|
|
file.toFile().getParentFile().mkdirs();
|
|
|
|
|
FileCopyUtils.copy("0".getBytes(StandardCharsets.UTF_8), file.toFile());
|
|
|
|
|
ConfigTreePropertySource source = new ConfigTreePropertySource("configtree", configtree);
|
|
|
|
|
applicationContext.getEnvironment().getPropertySources().addFirst(source);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex) {
|
|
|
|
|
throw new IllegalStateException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContextConsumer<AssertableWebApplicationContext> withWebTestClient(Consumer<WebClient> webClient) {
|
|
|
|
|
return (context) -> {
|
|
|
|
|
String port = context.getEnvironment().getProperty("local.management.port");
|
|
|
|
|