Allow overriding invokeSuspendingFunction

This commit isolates the invocation of Kotlin coroutines into a separate
template method, so that it can be overridden in subclasses of
RequestMappingHandlerAdapter.

Closes gh-27195
This commit is contained in:
Lukáš Křečan
2021-07-21 13:17:01 +02:00
committed by Arjen Poutsma
parent ac3ebc37dc
commit ff844ed99f

View File

@@ -21,6 +21,9 @@ import java.lang.reflect.Method;
import java.util.Arrays;
import org.springframework.context.MessageSource;
import org.jetbrains.annotations.NotNull;
import org.reactivestreams.Publisher;
import org.springframework.core.CoroutinesUtils;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.KotlinDetector;
@@ -200,7 +203,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
Method method = getBridgedMethod();
try {
if (KotlinDetector.isSuspendingFunction(method)) {
return CoroutinesUtils.invokeSuspendingFunction(method, getBean(), args);
return invokeSuspendingFunction(method, args);
}
return method.invoke(getBean(), args);
}
@@ -228,4 +231,12 @@ public class InvocableHandlerMethod extends HandlerMethod {
}
}
/**
* Invokes Kotlin coroutine suspended function.
*/
@NotNull
protected Publisher<?> invokeSuspendingFunction(Method method, Object[] args) {
return CoroutinesUtils.invokeSuspendingFunction(method, getBean(), args);
}
}