Class HandlerMethodReturnValueHandlerComposite
java.lang.Object
org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandlerComposite
- All Implemented Interfaces:
AsyncHandlerMethodReturnValueHandler,HandlerMethodReturnValueHandler
public class HandlerMethodReturnValueHandlerComposite
extends Object
implements AsyncHandlerMethodReturnValueHandler
A HandlerMethodReturnValueHandler that wraps and delegates to others.
- Since:
- 4.0
- Author:
- Rossen Stoyanchev
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.commons.logging.LogPublic for wrapping with fallback logger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddHandler(HandlerMethodReturnValueHandler returnValueHandler) Add the givenHandlerMethodReturnValueHandler.addHandlers(@Nullable List<? extends HandlerMethodReturnValueHandler> handlers) Add the givenHandlerMethodReturnValueHandlers.voidclear()Clear the list of configured handlers.org.apache.commons.logging.LogReturn the currently configured Logger.Return a read-only list with the configured handlers.voidhandleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, Message<?> message) Handle the given return value.booleanisAsyncReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType) Whether the return value represents an asynchronous, Future-like type with success and error callbacks.voidsetLogger(org.apache.commons.logging.Log logger) Set an alternative logger to use than the one based on the class name.booleansupportsReturnType(org.springframework.core.MethodParameter returnType) Whether the given method return type is supported by this handler.toCompletableFuture(Object returnValue, org.springframework.core.MethodParameter returnType) Adapt the asynchronous return value to aCompletableFuture.
-
Field Details
-
defaultLogger
public static final org.apache.commons.logging.Log defaultLoggerPublic for wrapping with fallback logger.
-
-
Constructor Details
-
HandlerMethodReturnValueHandlerComposite
public HandlerMethodReturnValueHandlerComposite()
-
-
Method Details
-
setLogger
public void setLogger(org.apache.commons.logging.Log logger) Set an alternative logger to use than the one based on the class name.- Parameters:
logger- the logger to use- Since:
- 5.1
-
getLogger
public org.apache.commons.logging.Log getLogger()Return the currently configured Logger.- Since:
- 5.1
-
getReturnValueHandlers
Return a read-only list with the configured handlers. -
clear
public void clear()Clear the list of configured handlers. -
addHandler
public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler returnValueHandler) Add the givenHandlerMethodReturnValueHandler. -
addHandlers
public HandlerMethodReturnValueHandlerComposite addHandlers(@Nullable List<? extends HandlerMethodReturnValueHandler> handlers) Add the givenHandlerMethodReturnValueHandlers. -
supportsReturnType
public boolean supportsReturnType(org.springframework.core.MethodParameter returnType) Description copied from interface:HandlerMethodReturnValueHandlerWhether the given method return type is supported by this handler.- Specified by:
supportsReturnTypein interfaceHandlerMethodReturnValueHandler- Parameters:
returnType- the method return type to check- Returns:
trueif this handler supports the supplied return type;falseotherwise
-
handleReturnValue
public void handleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, Message<?> message) throws Exception Description copied from interface:HandlerMethodReturnValueHandlerHandle the given return value.- Specified by:
handleReturnValuein interfaceHandlerMethodReturnValueHandler- Parameters:
returnValue- the value returned from the handler methodreturnType- the type of the return value. This type must have previously been passed toHandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter)and it must have returnedtrue.message- the message that caused this method to be called- Throws:
Exception- if the return value handling results in an error
-
isAsyncReturnValue
public boolean isAsyncReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType) Description copied from interface:AsyncHandlerMethodReturnValueHandlerWhether the return value represents an asynchronous, Future-like type with success and error callbacks. If this method returnstrue, thenAsyncHandlerMethodReturnValueHandler.toCompletableFuture(java.lang.Object, org.springframework.core.MethodParameter)is invoked next. If it returnsfalse, thenHandlerMethodReturnValueHandler.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 returnstrue.- Specified by:
isAsyncReturnValuein interfaceAsyncHandlerMethodReturnValueHandler- Parameters:
returnValue- the value returned from the handler methodreturnType- the type of the return value- Returns:
trueif the return value type represents an async value
-
toCompletableFuture
public @Nullable CompletableFuture<?> toCompletableFuture(Object returnValue, org.springframework.core.MethodParameter returnType) Description copied from interface:AsyncHandlerMethodReturnValueHandlerAdapt the asynchronous return value to aCompletableFuture.Return value handling will then continue when the CompletableFuture 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 returnstrue.- Specified by:
toCompletableFuturein interfaceAsyncHandlerMethodReturnValueHandler- Parameters:
returnValue- the value returned from the handler methodreturnType- the type of the return value- Returns:
- the resulting CompletableFuture, or
nullin which case no further handling will be performed
-