Spring MVC supports reactive return values
This commit adds support for reactive library types to be returned directly from controller methods adapting them either to a ResponseBodyEmitter (streaming) or DeferredResult (non-streaming). The reactive libraries supported are the ones that can adapted to a Reactive Streams Publisher through the ReactiveAdapterRegistry. Issue: SPR-15365
This commit is contained in:
@@ -78,6 +78,16 @@ public class ReactiveAdapterRegistry {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the registry has any adapters which would be the case if any of
|
||||
* Reactor, RxJava 2, or RxJava 1 (+ RxJava Reactive Streams bridge) are
|
||||
* present on the classpath.
|
||||
*/
|
||||
public boolean hasAdapters() {
|
||||
return !this.adapters.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a reactive type along with functions to adapt to and from a
|
||||
* Reactive Streams {@link Publisher}. The functions can assume their
|
||||
@@ -113,6 +123,10 @@ public class ReactiveAdapterRegistry {
|
||||
Object sourceToUse = (source instanceof Optional ? ((Optional<?>) source).orElse(null) : source);
|
||||
Class<?> clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType);
|
||||
|
||||
if (reactiveType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.adapters.stream()
|
||||
.filter(adapter -> adapter.getReactiveType() == clazz)
|
||||
.findFirst()
|
||||
|
||||
Reference in New Issue
Block a user