Sync argument resolution and HandlerMethod invocation
HandlerMethodArgumentResolver is a non-blocking contract, however only implementations that read the request body require blocking. This commit introduces SyncMethodArgumentResolver as an extension of the non-blocking contract that allows synchronous implementations to use synchronous argument resolution. There is also a SyncInvocableHandlerMethod extension that uses only sync argument resolvers and allows a synchronous invocation. Issue: SPR-14543
This commit is contained in:
@@ -64,7 +64,7 @@ public class InvocableHandlerMethodTests {
|
||||
@Test
|
||||
public void invokeMethodWithNoArguments() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("noArgs");
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
assertHandlerResultValue(mono, "success");
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class InvocableHandlerMethodTests {
|
||||
public void invokeMethodWithNoValue() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
addResolver(hm, Mono.empty());
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
assertHandlerResultValue(mono, "success:null");
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class InvocableHandlerMethodTests {
|
||||
public void invokeMethodWithValue() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
addResolver(hm, Mono.just("value1"));
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
assertHandlerResultValue(mono, "success:value1");
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class InvocableHandlerMethodTests {
|
||||
@Test
|
||||
public void noMatchingResolver() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
@@ -105,7 +105,7 @@ public class InvocableHandlerMethodTests {
|
||||
public void resolverThrowsException() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
addResolver(hm, Mono.error(new UnsupportedMediaTypeStatusException("boo")));
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
@@ -119,7 +119,7 @@ public class InvocableHandlerMethodTests {
|
||||
public void illegalArgumentExceptionIsWrappedWithInvocationDetails() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("singleArg");
|
||||
addResolver(hm, Mono.just(1));
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
@@ -134,7 +134,7 @@ public class InvocableHandlerMethodTests {
|
||||
@Test
|
||||
public void invocationTargetExceptionIsUnwrapped() throws Exception {
|
||||
InvocableHandlerMethod hm = handlerMethod("exceptionMethod");
|
||||
Mono<HandlerResult> mono = hm.invokeForRequest(this.exchange, new BindingContext());
|
||||
Mono<HandlerResult> mono = hm.invoke(this.exchange, new BindingContext());
|
||||
|
||||
ScriptedSubscriber.create().expectNextCount(0)
|
||||
.consumeErrorWith(error -> {
|
||||
|
||||
@@ -380,7 +380,7 @@ public class RequestMappingInfoHandlerMappingTests {
|
||||
|
||||
BindingContext bindingContext = new BindingContext();
|
||||
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
|
||||
Mono<HandlerResult> mono = invocable.invokeForRequest(exchange, bindingContext);
|
||||
Mono<HandlerResult> mono = invocable.invoke(exchange, bindingContext);
|
||||
|
||||
HandlerResult result = mono.block();
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -69,7 +69,6 @@ public class ServerWebExchangeArgumentResolverTests {
|
||||
assertTrue(this.resolver.supportsParameter(parameter(ServerWebExchange.class)));
|
||||
assertTrue(this.resolver.supportsParameter(parameter(ServerHttpRequest.class)));
|
||||
assertTrue(this.resolver.supportsParameter(parameter(ServerHttpResponse.class)));
|
||||
assertTrue(this.resolver.supportsParameter(parameter(WebSession.class)));
|
||||
assertTrue(this.resolver.supportsParameter(parameter(HttpMethod.class)));
|
||||
assertFalse(this.resolver.supportsParameter(parameter(String.class)));
|
||||
}
|
||||
@@ -79,7 +78,6 @@ public class ServerWebExchangeArgumentResolverTests {
|
||||
testResolveArgument(parameter(ServerWebExchange.class), this.exchange);
|
||||
testResolveArgument(parameter(ServerHttpRequest.class), this.exchange.getRequest());
|
||||
testResolveArgument(parameter(ServerHttpResponse.class), this.exchange.getResponse());
|
||||
testResolveArgument(parameter(WebSession.class), this.exchange.getSession().block());
|
||||
testResolveArgument(parameter(HttpMethod.class), HttpMethod.GET);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user