Polish
This commit is contained in:
@@ -38,9 +38,9 @@ public final class MissingParametersException extends InvalidEndpointRequestExce
|
||||
super("Failed to invoke operation because the following required "
|
||||
+ "parameters were missing: "
|
||||
+ StringUtils.collectionToCommaDelimitedString(missingParameters),
|
||||
"Missing parameters: " + missingParameters.stream()
|
||||
.map(OperationParameter::getName)
|
||||
.collect(Collectors.joining(",")));
|
||||
"Missing parameters: "
|
||||
+ missingParameters.stream().map(OperationParameter::getName)
|
||||
.collect(Collectors.joining(",")));
|
||||
this.missingParameters = missingParameters;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* Identifies a type as being an endpoint that is only exposed over Spring MVC or
|
||||
* Spring WebFlux. Mapped methods must be annotated with {@link GetMapping @GetMapping},
|
||||
* Identifies a type as being an endpoint that is only exposed over Spring MVC or Spring
|
||||
* WebFlux. Mapped methods must be annotated with {@link GetMapping @GetMapping},
|
||||
* {@link PostMapping @PostMapping}, {@link DeleteMapping @DeleteMapping}, etc annotations
|
||||
* rather than {@link ReadOperation @ReadOperation},
|
||||
* {@link WriteOperation @WriteOperation}, {@link DeleteOperation @DeleteOperation}.
|
||||
|
||||
@@ -31,7 +31,8 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link EndpointDiscoverer} for {@link ExposableControllerEndpoint controller endpoints}.
|
||||
* {@link EndpointDiscoverer} for {@link ExposableControllerEndpoint controller
|
||||
* endpoints}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
|
||||
@@ -288,8 +288,8 @@ public abstract class AbstractWebFluxEndpointHandlerMapping
|
||||
private Mono<ResponseEntity<Object>> handleResult(Publisher<?> result,
|
||||
HttpMethod httpMethod) {
|
||||
return Mono.from(result).map(this::toResponseEntity)
|
||||
.onErrorMap(InvalidEndpointRequestException.class, (ex) ->
|
||||
new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
.onErrorMap(InvalidEndpointRequestException.class,
|
||||
(ex) -> new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
ex.getReason()))
|
||||
.defaultIfEmpty(new ResponseEntity<>(httpMethod == HttpMethod.GET
|
||||
? HttpStatus.NOT_FOUND : HttpStatus.NO_CONTENT));
|
||||
|
||||
@@ -72,8 +72,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
|
||||
private Map<Object, ExposableControllerEndpoint> getHandlers(
|
||||
Collection<ExposableControllerEndpoint> endpoints) {
|
||||
Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>();
|
||||
endpoints
|
||||
.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
|
||||
endpoints.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
|
||||
return Collections.unmodifiableMap(handlers);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,7 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
|
||||
private Map<Object, ExposableControllerEndpoint> getHandlers(
|
||||
Collection<ExposableControllerEndpoint> endpoints) {
|
||||
Map<Object, ExposableControllerEndpoint> handlers = new LinkedHashMap<>();
|
||||
endpoints
|
||||
.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
|
||||
endpoints.forEach((endpoint) -> handlers.put(endpoint.getController(), endpoint));
|
||||
return Collections.unmodifiableMap(handlers);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,12 +75,12 @@ public class RouterFunctionMetrics {
|
||||
Iterable<Tag> tags) {
|
||||
return (request, next) -> {
|
||||
final long start = System.nanoTime();
|
||||
return next.handle(request).doOnSuccess(response -> {
|
||||
return next.handle(request).doOnSuccess((response) -> {
|
||||
Iterable<Tag> allTags = Tags.concat(tags,
|
||||
this.defaultTags.apply(request, response));
|
||||
this.registry.timer(name, allTags).record(System.nanoTime() - start,
|
||||
TimeUnit.NANOSECONDS);
|
||||
}).doOnError(error -> {
|
||||
}).doOnError((error) -> {
|
||||
// FIXME how do we get the response under an error condition?
|
||||
Iterable<Tag> allTags = Tags.concat(tags,
|
||||
this.defaultTags.apply(request, null));
|
||||
|
||||
@@ -99,7 +99,7 @@ public class BeansEndpointTests {
|
||||
parentRunner.run((parent) -> {
|
||||
new ApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfiguration.class).withParent(parent)
|
||||
.run(child -> {
|
||||
.run((child) -> {
|
||||
ApplicationBeans result = child.getBean(BeansEndpoint.class).beans();
|
||||
assertThat(result.getContexts().get(parent.getId()).getBeans())
|
||||
.containsKey("bean");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConfigurationPropertiesReportEndpointParentTests {
|
||||
.run((parent) -> {
|
||||
new ApplicationContextRunner()
|
||||
.withUserConfiguration(ClassConfigurationProperties.class)
|
||||
.withParent(parent).run(child -> {
|
||||
.withParent(parent).run((child) -> {
|
||||
ConfigurationPropertiesReportEndpoint endpoint = child
|
||||
.getBean(ConfigurationPropertiesReportEndpoint.class);
|
||||
ApplicationConfigurationProperties applicationProperties = endpoint
|
||||
@@ -65,7 +65,7 @@ public class ConfigurationPropertiesReportEndpointParentTests {
|
||||
new ApplicationContextRunner()
|
||||
.withUserConfiguration(
|
||||
BeanMethodConfigurationProperties.class)
|
||||
.withParent(parent).run(child -> {
|
||||
.withParent(parent).run((child) -> {
|
||||
ConfigurationPropertiesReportEndpoint endpoint = child
|
||||
.getBean(ConfigurationPropertiesReportEndpoint.class);
|
||||
ApplicationConfigurationProperties applicationProperties = endpoint
|
||||
|
||||
@@ -159,9 +159,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
@Test
|
||||
public void readOperationWithMappingFailureProducesBadRequestResponse() {
|
||||
load(QueryEndpointConfiguration.class, (client) -> {
|
||||
WebTestClient.BodyContentSpec body = client.get()
|
||||
.uri("/query?two=two").exchange().expectStatus().isBadRequest()
|
||||
.expectBody();
|
||||
WebTestClient.BodyContentSpec body = client.get().uri("/query?two=two")
|
||||
.exchange().expectStatus().isBadRequest().expectBody();
|
||||
validateErrorBody(body, HttpStatus.BAD_REQUEST, "/endpoints/query",
|
||||
"Missing parameters: one");
|
||||
});
|
||||
@@ -282,9 +281,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
@Test
|
||||
public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() {
|
||||
load(RequiredParameterEndpointConfiguration.class, (client) -> {
|
||||
WebTestClient.BodyContentSpec body = client.get()
|
||||
.uri("/requiredparameters").exchange().expectStatus().isBadRequest()
|
||||
.expectBody();
|
||||
WebTestClient.BodyContentSpec body = client.get().uri("/requiredparameters")
|
||||
.exchange().expectStatus().isBadRequest().expectBody();
|
||||
validateErrorBody(body, HttpStatus.BAD_REQUEST,
|
||||
"/endpoints/requiredparameters", "Missing parameters: foo");
|
||||
});
|
||||
@@ -334,9 +332,8 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
|
||||
protected void validateErrorBody(WebTestClient.BodyContentSpec body,
|
||||
HttpStatus status, String path, String message) {
|
||||
body.jsonPath("status").isEqualTo(status.value())
|
||||
.jsonPath("error").isEqualTo(status.getReasonPhrase())
|
||||
.jsonPath("path").isEqualTo(path)
|
||||
body.jsonPath("status").isEqualTo(status.value()).jsonPath("error")
|
||||
.isEqualTo(status.getReasonPhrase()).jsonPath("path").isEqualTo(path)
|
||||
.jsonPath("message").isEqualTo(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ class BaseConfiguration {
|
||||
ParameterValueMapper parameterMapper = new ConversionServiceParameterValueMapper(
|
||||
DefaultConversionService.getSharedInstance());
|
||||
return new WebEndpointDiscoverer(applicationContext, parameterMapper,
|
||||
endpointMediaTypes(), PathMapper.useEndpointId(),
|
||||
Collections.emptyList(), Collections.emptyList());
|
||||
endpointMediaTypes(), PathMapper.useEndpointId(), Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -298,9 +298,9 @@ public class WebEndpointDiscovererTests {
|
||||
Map<WebOperationRequestPredicate, Long> matchCounts = new HashMap<>();
|
||||
for (WebOperationRequestPredicate predicate : predicates) {
|
||||
matchCounts.put(predicate, Stream.of(matchers)
|
||||
.filter(matcher -> matcher.matches(predicate)).count());
|
||||
.filter((matcher) -> matcher.matches(predicate)).count());
|
||||
}
|
||||
return matchCounts.values().stream().noneMatch(count -> count != 1);
|
||||
return matchCounts.values().stream().noneMatch((count) -> count != 1);
|
||||
}, Arrays.toString(matchers));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,7 @@ public class SpringIntegrationMetricsIntegrationTests {
|
||||
(e) -> e.id("toJson"))
|
||||
.handle(String.class, this::fahrenheitToCelsius,
|
||||
(e) -> e.id("temperatureConverter"))
|
||||
.transform(this::extractResult, e -> e.id("toResponse"));
|
||||
.transform(this::extractResult, (e) -> e.id("toResponse"));
|
||||
}
|
||||
|
||||
private double extractResult(String json) {
|
||||
|
||||
Reference in New Issue
Block a user