public class DeferredResultMethodReturnValueHandler extends java.lang.Object implements AsyncHandlerMethodReturnValueHandler
DeferredResult
, ListenableFuture
,
CompletionStage
and any other async type with a registered adapter
.Modifier and Type | Class and Description |
---|---|
private static class |
DeferredResultMethodReturnValueHandler.CompletionStageAdapter
Adapter for
CompletionStage return values. |
private static class |
DeferredResultMethodReturnValueHandler.ListenableFutureAdapter
Adapter for
ListenableFuture return values. |
private static class |
DeferredResultMethodReturnValueHandler.SimpleDeferredResultAdapter
Adapter for
DeferredResult return values. |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class<?>,DeferredResultAdapter> |
adapterMap |
Constructor and Description |
---|
DeferredResultMethodReturnValueHandler() |
Modifier and Type | Method and Description |
---|---|
private DeferredResultAdapter |
getAdapterFor(java.lang.Class<?> type) |
java.util.Map<java.lang.Class<?>,DeferredResultAdapter> |
getAdapterMap()
Return the map with
DeferredResult adapters. |
void |
handleReturnValue(java.lang.Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
Handle the given return value by adding attributes to the model and
setting a view or setting the
ModelAndViewContainer.setRequestHandled(boolean) flag to true
to indicate the response has been handled directly. |
boolean |
isAsyncReturnValue(java.lang.Object returnValue,
MethodParameter returnType)
Whether the given return value represents asynchronous computation.
|
boolean |
supportsReturnType(MethodParameter returnType)
Whether the given method return type is
supported by this handler.
|
private final java.util.Map<java.lang.Class<?>,DeferredResultAdapter> adapterMap
public DeferredResultMethodReturnValueHandler()
public java.util.Map<java.lang.Class<?>,DeferredResultAdapter> getAdapterMap()
DeferredResult
adapters.
By default the map contains adapters for DeferredResult
, which
simply downcasts, ListenableFuture
, and CompletionStage
.
private DeferredResultAdapter getAdapterFor(java.lang.Class<?> type)
public boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandler
supportsReturnType
in interface HandlerMethodReturnValueHandler
returnType
- the method return type to checktrue
if this handler supports the supplied return type;
false
otherwisepublic boolean isAsyncReturnValue(java.lang.Object returnValue, MethodParameter returnType)
AsyncHandlerMethodReturnValueHandler
isAsyncReturnValue
in interface AsyncHandlerMethodReturnValueHandler
returnValue
- the return valuereturnType
- the return typetrue
if the return value is asynchronous.public void handleReturnValue(java.lang.Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws java.lang.Exception
HandlerMethodReturnValueHandler
ModelAndViewContainer.setRequestHandled(boolean)
flag to true
to indicate the response has been handled directly.handleReturnValue
in interface HandlerMethodReturnValueHandler
returnValue
- the value returned from the handler methodreturnType
- the type of the return value. This type must have
previously been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
which must
have returned true
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current requestjava.lang.Exception
- if the return value handling results in an error