Skip to content

Commit

Permalink
Merge branch '3.2.x'
Browse files Browse the repository at this point in the history
Closes gh-39445
  • Loading branch information
scottfrederick committed Feb 7, 2024
2 parents b1bf4bb + 89354f3 commit c05942d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
* @author Madhura Bhave
* @author Phillip Webb
* @author Brian Clozel
* @author Scott Frederick
* @since 2.0.0
*/
@ImportRuntimeHints(AbstractWebFluxEndpointHandlerMappingRuntimeHints.class)
Expand Down Expand Up @@ -260,6 +261,26 @@ public Object invoke(InvocationContext context) {

}

protected static final class ExceptionCapturingInvoker implements OperationInvoker {

private final OperationInvoker invoker;

public ExceptionCapturingInvoker(OperationInvoker invoker) {
this.invoker = invoker;
}

@Override
public Object invoke(InvocationContext context) {
try {
return this.invoker.invoke(context);
}
catch (Exception ex) {
return Mono.error(ex);
}
}

}

/**
* Reactive handler providing actuator links at the root endpoint.
*/
Expand Down Expand Up @@ -303,9 +324,9 @@ private ReactiveWebOperationAdapter(WebOperation operation) {
private OperationInvoker getInvoker(WebOperation operation) {
OperationInvoker invoker = operation::invoke;
if (operation.isBlocking()) {
invoker = new ElasticSchedulerInvoker(invoker);
return new ElasticSchedulerInvoker(invoker);
}
return invoker;
return new ExceptionCapturingInvoker(invoker);
}

private Supplier<Mono<? extends SecurityContext>> getSecurityContextSupplier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ void readOperationWithSingleQueryParameters() {
.isEqualTo("1 2"));
}

@Test
void readOperationWithQueryParametersMissing() {
load(QueryEndpointConfiguration.class,
(client) -> client.get().uri("/query").exchange().expectStatus().isBadRequest());
}

@Test
void reactiveReadOperationWithSingleQueryParameters() {
load(ReactiveQueryEndpointConfiguration.class,
(client) -> client.get()
.uri("/query?param=test")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("query")
.isEqualTo("test"));
}

@Test
void reactiveReadOperationWithQueryParametersMissing() {
load(ReactiveQueryEndpointConfiguration.class,
(client) -> client.get().uri("/query").exchange().expectStatus().isBadRequest());
}

@Test
void readOperationWithSingleQueryParametersAndMultipleValues() {
load(QueryEndpointConfiguration.class,
Expand Down Expand Up @@ -732,6 +757,17 @@ QueryWithListEndpoint queryEndpoint() {

}

@Configuration(proxyBeanMethods = false)
@Import(BaseConfiguration.class)
static class ReactiveQueryEndpointConfiguration {

@Bean
ReactiveQueryEndpoint reactiveQueryEndpoint() {
return new ReactiveQueryEndpoint();
}

}

@Configuration(proxyBeanMethods = false)
@Import(BaseConfiguration.class)
static class VoidWriteResponseEndpointConfiguration {
Expand Down Expand Up @@ -974,6 +1010,16 @@ Map<String, String> queryWithParameterList(String one, List<String> two) {

}

@Endpoint(id = "query")
static class ReactiveQueryEndpoint {

@ReadOperation
Mono<Map<String, String>> query(String param) {
return Mono.just(Collections.singletonMap("query", param));
}

}

@Endpoint(id = "voidwrite")
static class VoidWriteResponseEndpoint {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void sessionsForUsernameWithoutUsernameParam(WebTestClient client) {
.uri((builder) -> builder.path("/actuator/sessions").build())
.exchange()
.expectStatus()
.is5xxServerError(); // https://github.com/spring-projects/spring-boot/issues/39236
.is4xxClientError();
}

@WebEndpointTest(infrastructure = Infrastructure.WEBFLUX)
Expand Down

0 comments on commit c05942d

Please sign in to comment.