public class HandlerMethodReturnValueHandlerComposite extends java.lang.Object implements AsyncHandlerMethodReturnValueHandler
Modifier and Type | Field and Description |
---|---|
static Log |
defaultLogger
Public for wrapping with fallback logger.
|
private Log |
logger |
private java.util.List<HandlerMethodReturnValueHandler> |
returnValueHandlers |
Constructor and Description |
---|
HandlerMethodReturnValueHandlerComposite() |
Modifier and Type | Method and Description |
---|---|
HandlerMethodReturnValueHandlerComposite |
addHandler(HandlerMethodReturnValueHandler returnValueHandler)
Add the given
HandlerMethodReturnValueHandler . |
HandlerMethodReturnValueHandlerComposite |
addHandlers(java.util.List<? extends HandlerMethodReturnValueHandler> handlers)
Add the given
HandlerMethodReturnValueHandlers . |
void |
clear()
Clear the list of configured handlers.
|
Log |
getLogger()
Return the currently configured Logger.
|
private HandlerMethodReturnValueHandler |
getReturnValueHandler(MethodParameter returnType) |
java.util.List<HandlerMethodReturnValueHandler> |
getReturnValueHandlers()
Return a read-only list with the configured handlers.
|
void |
handleReturnValue(java.lang.Object returnValue,
MethodParameter returnType,
Message<?> message)
Handle the given return value.
|
boolean |
isAsyncReturnValue(java.lang.Object returnValue,
MethodParameter returnType)
Whether the return value represents an asynchronous, Future-like type
with success and error callbacks.
|
void |
setLogger(Log logger)
Set an alternative logger to use than the one based on the class name.
|
boolean |
supportsReturnType(MethodParameter returnType)
Whether the given method return type is
supported by this handler.
|
ListenableFuture<?> |
toListenableFuture(java.lang.Object returnValue,
MethodParameter returnType)
Adapt the asynchronous return value to a
ListenableFuture . |
public static final Log defaultLogger
private Log logger
private final java.util.List<HandlerMethodReturnValueHandler> returnValueHandlers
public HandlerMethodReturnValueHandlerComposite()
public void setLogger(Log logger)
logger
- the logger to usepublic Log getLogger()
public java.util.List<HandlerMethodReturnValueHandler> getReturnValueHandlers()
public void clear()
public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler returnValueHandler)
HandlerMethodReturnValueHandler
.public HandlerMethodReturnValueHandlerComposite addHandlers(@Nullable java.util.List<? extends HandlerMethodReturnValueHandler> handlers)
HandlerMethodReturnValueHandlers
.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
otherwise@Nullable private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType)
public void handleReturnValue(@Nullable java.lang.Object returnValue, MethodParameter returnType, Message<?> message) throws java.lang.Exception
HandlerMethodReturnValueHandler
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)
and it must have returned true
.message
- the message that caused this method to be calledjava.lang.Exception
- if the return value handling results in an errorpublic boolean isAsyncReturnValue(java.lang.Object returnValue, MethodParameter returnType)
AsyncHandlerMethodReturnValueHandler
true
,
then AsyncHandlerMethodReturnValueHandler.toListenableFuture(java.lang.Object, org.springframework.core.MethodParameter)
is invoked next. If it returns
false
, then HandlerMethodReturnValueHandler.handleReturnValue(java.lang.Object, org.springframework.core.MethodParameter, org.springframework.messaging.Message<?>)
is called.
Note: this method will only be invoked after
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
is called and it returns true
.
isAsyncReturnValue
in interface AsyncHandlerMethodReturnValueHandler
returnValue
- the value returned from the handler methodreturnType
- the type of the return value.@Nullable public ListenableFuture<?> toListenableFuture(java.lang.Object returnValue, MethodParameter returnType)
AsyncHandlerMethodReturnValueHandler
ListenableFuture
.
Implementations should consider returning an instance of
SettableListenableFuture
. Return value handling will then continue when
the ListenableFuture is completed with either success or error.
Note: this method will only be invoked after
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)
is called and it returns true
.
toListenableFuture
in interface AsyncHandlerMethodReturnValueHandler
returnValue
- the value returned from the handler methodreturnType
- the type of the return value.null
in which case no
further handling will be performed.