Class HandlerMethodReturnValueHandlerComposite
- java.lang.Object
- org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite
- All Implemented Interfaces:
AsyncHandlerMethodReturnValueHandler
,HandlerMethodReturnValueHandler
public class HandlerMethodReturnValueHandlerComposite extends Object implements AsyncHandlerMethodReturnValueHandler
Handles method return values by delegating to a list of registeredHandlerMethodReturnValueHandler
s. Previously resolved return types are cached for faster lookups.- Since:
- 3.1
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description HandlerMethodReturnValueHandlerComposite()
Method Summary
Constructor Detail
HandlerMethodReturnValueHandlerComposite
public HandlerMethodReturnValueHandlerComposite()
Method Detail
getHandlers
public List<HandlerMethodReturnValueHandler> getHandlers()
Return a read-only list with the registered handlers, or an empty list.
supportsReturnType
public boolean supportsReturnType(MethodParameter returnType)
Whether the given method return type is supported by any registeredHandlerMethodReturnValueHandler
.- Specified by:
supportsReturnType
in interfaceHandlerMethodReturnValueHandler
- Parameters:
returnType
- the method return type to check- Returns:
true
if this handler supports the supplied return type;false
otherwise
handleReturnValue
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception
Iterate over registeredHandlerMethodReturnValueHandler
s and invoke the one that supports it.- Specified by:
handleReturnValue
in 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)
which must have returnedtrue
.mavContainer
- the ModelAndViewContainer for the current requestwebRequest
- the current request- Throws:
IllegalStateException
- if no suitableHandlerMethodReturnValueHandler
is found.Exception
- if the return value handling results in an error
isAsyncReturnValue
public boolean isAsyncReturnValue(Object value, MethodParameter returnType)
Description copied from interface:AsyncHandlerMethodReturnValueHandler
Whether the given return value represents asynchronous computation.- Specified by:
isAsyncReturnValue
in interfaceAsyncHandlerMethodReturnValueHandler
- Parameters:
value
- the value returned from the handler methodreturnType
- the return type- Returns:
true
if the return value type represents an async value
addHandler
public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler handler)
Add the givenHandlerMethodReturnValueHandler
.
addHandlers
public HandlerMethodReturnValueHandlerComposite addHandlers(List<? extends HandlerMethodReturnValueHandler> handlers)
Add the givenHandlerMethodReturnValueHandler
s.