Commit 9a80b625 by Johannes Edmeier

Update to Spring Boot 2.0.1

parent db8b2a7d
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<url>https://github.com/codecentric/spring-boot-admin/</url> <url>https://github.com/codecentric/spring-boot-admin/</url>
<properties> <properties>
<revision>2.0.0-SNAPSHOT</revision> <revision>2.0.0-SNAPSHOT</revision>
<spring-boot.version>2.0.0.RELEASE</spring-boot.version> <spring-boot.version>2.0.1.RELEASE</spring-boot.version>
<spring-cloud.version>Finchley.M9</spring-cloud.version> <spring-cloud.version>Finchley.M9</spring-cloud.version>
<hazelcast-tests.version>3.9.2</hazelcast-tests.version> <hazelcast-tests.version>3.9.2</hazelcast-tests.version>
<java.version>1.8</java.version> <java.version>1.8</java.version>
......
...@@ -20,15 +20,11 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties; ...@@ -20,15 +20,11 @@ import de.codecentric.boot.admin.server.config.AdminServerProperties;
import de.codecentric.boot.admin.server.config.EnableAdminServer; import de.codecentric.boot.admin.server.config.EnableAdminServer;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.notify.LoggingNotifier; import de.codecentric.boot.admin.server.notify.LoggingNotifier;
import de.codecentric.boot.admin.server.notify.RemindingNotifier;
import de.codecentric.boot.admin.server.notify.filter.FilteringNotifier;
import java.time.Duration;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain; import org.springframework.security.web.server.SecurityWebFilterChain;
...@@ -72,31 +68,8 @@ public class SpringBootAdminApplication { ...@@ -72,31 +68,8 @@ public class SpringBootAdminApplication {
// @formatter:on // @formatter:on
} }
@Configuration @Bean
public static class NotifierConfig { public LoggingNotifier loggerNotifier(InstanceRepository repository) {
private final InstanceRepository repository; return new LoggingNotifier(repository);
public NotifierConfig(InstanceRepository repository) {
this.repository = repository;
}
@Primary
@Bean(initMethod = "start", destroyMethod = "stop")
public RemindingNotifier remindingNotifier() {
RemindingNotifier notifier = new RemindingNotifier(filteringNotifier(), repository);
notifier.setReminderPeriod(Duration.ofMinutes(10));
notifier.setCheckReminderInverval(Duration.ofSeconds(10));
return notifier;
}
@Bean
public FilteringNotifier filteringNotifier() {
return new FilteringNotifier(loggerNotifier(), repository);
}
@Bean
public LoggingNotifier loggerNotifier() {
return new LoggingNotifier(repository);
}
} }
} }
...@@ -22,6 +22,7 @@ import de.codecentric.boot.admin.server.config.AdminServerWebConfiguration; ...@@ -22,6 +22,7 @@ import de.codecentric.boot.admin.server.config.AdminServerWebConfiguration;
import de.codecentric.boot.admin.server.ui.web.UiController; import de.codecentric.boot.admin.server.ui.web.UiController;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
...@@ -75,14 +76,10 @@ public class AdminServerUiAutoConfiguration { ...@@ -75,14 +76,10 @@ public class AdminServerUiAutoConfiguration {
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@Configuration @Configuration
public static class ReactiveUiConfiguration implements WebFluxConfigurer { public static class ReactiveUiConfiguration implements WebFluxConfigurer {
private final AdminServerUiProperties uiProperties; @Autowired
private final AdminServerProperties adminServerProperties; private AdminServerUiProperties uiProperties;
@Autowired
public ReactiveUiConfiguration(AdminServerUiProperties uiProperties, private AdminServerProperties adminServerProperties;
AdminServerProperties adminServerProperties) {
this.uiProperties = uiProperties;
this.adminServerProperties = adminServerProperties;
}
@Override @Override
public void addResourceHandlers(org.springframework.web.reactive.config.ResourceHandlerRegistry registry) { public void addResourceHandlers(org.springframework.web.reactive.config.ResourceHandlerRegistry registry) {
...@@ -95,14 +92,10 @@ public class AdminServerUiAutoConfiguration { ...@@ -95,14 +92,10 @@ public class AdminServerUiAutoConfiguration {
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@Configuration @Configuration
public static class ServletUiConfiguration implements WebMvcConfigurer { public static class ServletUiConfiguration implements WebMvcConfigurer {
private final AdminServerUiProperties uiProperties; @Autowired
private final AdminServerProperties adminServerProperties; private AdminServerUiProperties uiProperties;
@Autowired
public ServletUiConfiguration(AdminServerUiProperties uiProperties, private AdminServerProperties adminServerProperties;
AdminServerProperties adminServerProperties) {
this.uiProperties = uiProperties;
this.adminServerProperties = adminServerProperties;
}
@Override @Override
public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) { public void addResourceHandlers(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry registry) {
......
...@@ -22,22 +22,11 @@ import reactor.core.publisher.Flux; ...@@ -22,22 +22,11 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalLong;
import java.util.function.Function; import java.util.function.Function;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.http.client.reactive.ClientHttpResponseDecorator;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
...@@ -47,7 +36,6 @@ import org.springframework.web.util.UriComponentsBuilder; ...@@ -47,7 +36,6 @@ import org.springframework.web.util.UriComponentsBuilder;
import static de.codecentric.boot.admin.server.utils.MediaType.ACTUATOR_V1_MEDIATYPE; import static de.codecentric.boot.admin.server.utils.MediaType.ACTUATOR_V1_MEDIATYPE;
import static de.codecentric.boot.admin.server.utils.MediaType.ACTUATOR_V2_MEDIATYPE; import static de.codecentric.boot.admin.server.utils.MediaType.ACTUATOR_V2_MEDIATYPE;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
public final class InstanceExchangeFilterFunctions { public final class InstanceExchangeFilterFunctions {
...@@ -64,9 +52,8 @@ public final class InstanceExchangeFilterFunctions { ...@@ -64,9 +52,8 @@ public final class InstanceExchangeFilterFunctions {
public static ExchangeFilterFunction setInstance(Mono<Instance> instance) { public static ExchangeFilterFunction setInstance(Mono<Instance> instance) {
return (request, next) -> instance.map( return (request, next) -> instance.map(
i -> ClientRequest.from(request).attribute(ATTRIBUTE_INSTANCE, i).build()) i -> ClientRequest.from(request).attribute(ATTRIBUTE_INSTANCE, i).build())
.switchIfEmpty(request.url().isAbsolute() ? .switchIfEmpty(request.url().isAbsolute() ? Mono.just(request) : Mono.error(
Mono.just(request) : new InstanceWebClientException("Instance not found")))
Mono.error(new InstanceWebClientException("Instance not found")))
.flatMap(next::exchange); .flatMap(next::exchange);
} }
...@@ -143,157 +130,13 @@ public final class InstanceExchangeFilterFunctions { ...@@ -143,157 +130,13 @@ public final class InstanceExchangeFilterFunctions {
}; };
} }
private static Function<ClientResponse, Mono<ClientResponse>> convertClientResponse(Function<Flux<DataBuffer>, Flux<DataBuffer>> bodConverter, private static Function<ClientResponse, Mono<ClientResponse>> convertClientResponse(Function<Flux<DataBuffer>, Flux<DataBuffer>> bodConverter, MediaType contentType) {
MediaType contentType) { return response -> {
return response -> Mono.just(new ConvertedBodyResponse(response, bodConverter, contentType)); ClientResponse convertedResponse = ClientResponse.from(response).headers(headers -> {
} headers.replace(HttpHeaders.CONTENT_TYPE, singletonList(contentType.toString()));
headers.remove(HttpHeaders.CONTENT_LENGTH);
private static class ConvertedBodyResponse implements ClientResponse { }).body(response.bodyToFlux(DataBuffer.class).transform(bodConverter)).build();
private final ClientResponse response; return Mono.just(convertedResponse);
private final Function<Flux<DataBuffer>, Flux<DataBuffer>> converter; };
private final Headers headers;
private ConvertedBodyResponse(ClientResponse response,
Function<Flux<DataBuffer>, Flux<DataBuffer>> converter,
MediaType contentType) {
this.response = response;
this.converter = converter;
this.headers = new Headers() {
@Override
public OptionalLong contentLength() {
return OptionalLong.empty();
}
@Override
public Optional<MediaType> contentType() {
return Optional.ofNullable(contentType);
}
@Override
public List<String> header(String headerName) {
if (headerName.equals(HttpHeaders.CONTENT_TYPE)) {
return singletonList(contentType.toString());
}
if (headerName.equals(HttpHeaders.CONTENT_LENGTH)) {
return emptyList();
}
return response.headers().header(headerName);
}
@Override
public HttpHeaders asHttpHeaders() {
HttpHeaders newHeaders = new HttpHeaders();
newHeaders.putAll(response.headers().asHttpHeaders());
newHeaders.replace(HttpHeaders.CONTENT_TYPE, singletonList(contentType.toString()));
newHeaders.remove(HttpHeaders.CONTENT_LENGTH);
return HttpHeaders.readOnlyHttpHeaders(newHeaders);
}
};
}
@Override
public HttpStatus statusCode() {
return response.statusCode();
}
@Override
public Headers headers() {
return headers;
}
@Override
public MultiValueMap<String, ResponseCookie> cookies() {
return response.cookies();
}
@Override
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
return response.body((inputMessage, context) -> {
ClientHttpResponse convertedMessage = new ClientHttpResponseDecorator(inputMessage) {
@Override
public Flux<DataBuffer> getBody() {
return super.getBody().transform(ConvertedBodyResponse.this.converter);
}
};
return extractor.extract(convertedMessage, context);
});
}
@Override
public <T> Mono<T> bodyToMono(Class<? extends T> elementClass) {
if (Void.class.isAssignableFrom(elementClass)) {
return response.bodyToMono(elementClass);
} else {
return body(BodyExtractors.toMono(elementClass));
}
}
@Override
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference) {
if (Void.class.isAssignableFrom(typeReference.getType().getClass())) {
return response.bodyToMono(typeReference);
} else {
return body(BodyExtractors.toMono(typeReference));
}
}
@Override
public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass) {
if (Void.class.isAssignableFrom(elementClass)) {
return response.bodyToFlux(elementClass);
} else {
return body(BodyExtractors.toFlux(elementClass));
}
}
@Override
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
if (Void.class.isAssignableFrom(typeReference.getType().getClass())) {
return response.bodyToFlux(typeReference);
} else {
return body(BodyExtractors.toFlux(typeReference));
}
}
@Override
public <T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyType) {
if (Void.class.isAssignableFrom(bodyType)) {
return response.toEntity(bodyType);
} else {
return toEntityInternal(bodyToMono(bodyType));
}
}
@Override
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> typeReference) {
if (Void.class.isAssignableFrom(typeReference.getType().getClass())) {
return response.toEntity(typeReference);
} else {
return toEntityInternal(bodyToMono(typeReference));
}
}
private <T> Mono<ResponseEntity<T>> toEntityInternal(Mono<T> bodyMono) {
HttpHeaders headers = headers().asHttpHeaders();
HttpStatus statusCode = statusCode();
return bodyMono.map(body -> new ResponseEntity<>(body, headers, statusCode))
.switchIfEmpty(Mono.defer(() -> Mono.just(new ResponseEntity<>(headers, statusCode))));
}
@Override
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> responseType) {
return toEntityListInternal(bodyToFlux(responseType));
}
@Override
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> typeReference) {
return toEntityListInternal(bodyToFlux(typeReference));
}
private <T> Mono<ResponseEntity<List<T>>> toEntityListInternal(Flux<T> bodyFlux) {
HttpHeaders headers = headers().asHttpHeaders();
HttpStatus statusCode = statusCode();
return bodyFlux.collectList().map(body -> new ResponseEntity<>(body, headers, statusCode));
}
} }
} }
...@@ -76,7 +76,7 @@ public abstract class AbstractAdminApplicationTest { ...@@ -76,7 +76,7 @@ public abstract class AbstractAdminApplicationTest {
return webClient.get().uri("/instances/events").accept(MediaType.TEXT_EVENT_STREAM) return webClient.get().uri("/instances/events").accept(MediaType.TEXT_EVENT_STREAM)
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectHeader().contentType(MediaType.TEXT_EVENT_STREAM) .expectHeader().contentTypeCompatibleWith(MediaType.TEXT_EVENT_STREAM)
.returnResult(JSONObject.class).getResponseBody(); .returnResult(JSONObject.class).getResponseBody();
//@formatter:on //@formatter:on
} }
......
...@@ -255,7 +255,7 @@ public class InstancesControllerIntegrationTest { ...@@ -255,7 +255,7 @@ public class InstancesControllerIntegrationTest {
return this.client.get().uri("/instances/events").accept(MediaType.TEXT_EVENT_STREAM) return this.client.get().uri("/instances/events").accept(MediaType.TEXT_EVENT_STREAM)
.exchange() .exchange()
.expectStatus().isOk() .expectStatus().isOk()
.expectHeader().contentType(MediaType.TEXT_EVENT_STREAM) .expectHeader().contentTypeCompatibleWith(MediaType.TEXT_EVENT_STREAM)
.returnResult(RESPONSE_TYPE).getResponseBody(); .returnResult(RESPONSE_TYPE).getResponseBody();
//@formatter:on //@formatter:on
} }
......
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