Refine Coroutines annotated controller support
This commit refines Coroutines annotated controller support by considering Kotlin Unit as Java void and using the right ReactiveAdapter to support all use cases, including suspending functions that return Flow (usual when using APIs like WebClient). It also fixes RSocket fire and forget handling and adds related tests for that use case. Closes gh-24057 Closes gh-23866
This commit is contained in:
@@ -127,10 +127,13 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
public Mono<Object> invoke(Message<?> message, Object... providedArgs) {
|
||||
return getMethodArgumentValues(message, providedArgs).flatMap(args -> {
|
||||
Object value;
|
||||
boolean isSuspendingFunction = false;
|
||||
try {
|
||||
Method method = getBridgedMethod();
|
||||
ReflectionUtils.makeAccessible(method);
|
||||
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(method.getDeclaringClass())) {
|
||||
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(method.getDeclaringClass())
|
||||
&& CoroutinesUtils.isSuspendingFunction(method)) {
|
||||
isSuspendingFunction = true;
|
||||
value = CoroutinesUtils.invokeSuspendingFunction(method, getBean(), args);
|
||||
}
|
||||
else {
|
||||
@@ -151,7 +154,8 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
}
|
||||
|
||||
MethodParameter returnType = getReturnType();
|
||||
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(returnType.getParameterType());
|
||||
Class<?> reactiveType = (isSuspendingFunction ? value.getClass() : returnType.getParameterType());
|
||||
ReactiveAdapter adapter = this.reactiveAdapterRegistry.getAdapter(reactiveType);
|
||||
return (isAsyncVoidReturnType(returnType, adapter) ?
|
||||
Mono.from(adapter.toPublisher(value)) : Mono.justOrEmpty(value));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user