org.springframework.messaging.handler.invocation

## 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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Log` | `defaultLogger` Public for wrapping with fallback logger.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HandlerMethodReturnValueHandlerComposite()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `HandlerMethodReturnValueHandlerComposite` | `addHandler(HandlerMethodReturnValueHandler returnValueHandler)` Add the given `HandlerMethodReturnValueHandler`.
    `HandlerMethodReturnValueHandlerComposite` | `addHandlers(List<? extends HandlerMethodReturnValueHandler> handlers)` Add the given `HandlerMethodReturnValueHandlers`.
    `void` | `clear()` Clear the list of configured handlers.
    `Log` | `getLogger()` Return the currently configured Logger.
    `List<HandlerMethodReturnValueHandler>` | `getReturnValueHandlers()` Return a read-only list with the configured handlers.
    `void` | `handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message)` Handle the given return value.
    `boolean` | `isAsyncReturnValue(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(Object returnValue, MethodParameter returnType)` Adapt the asynchronous return value to a `ListenableFuture`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### defaultLogger

          public static final Log defaultLogger

      Public for wrapping with fallback logger.

  - ### Constructor Detail

    - #### HandlerMethodReturnValueHandlerComposite

          public HandlerMethodReturnValueHandlerComposite()

  - ### Method Detail

    - #### setLogger

          public void setLogger(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 Log getLogger()

      Return the currently configured Logger.
      Since:
        5.1

    - #### getReturnValueHandlers

          public List<HandlerMethodReturnValueHandler> 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 given `HandlerMethodReturnValueHandler`.

    - #### addHandlers

          public HandlerMethodReturnValueHandlerComposite addHandlers(@Nullable
                                                                      List<? extends HandlerMethodReturnValueHandler> handlers)

      Add the given `HandlerMethodReturnValueHandlers`.

    - #### supportsReturnType

          public boolean supportsReturnType(MethodParameter returnType)

      Description copied from interface: `HandlerMethodReturnValueHandler`
      Whether the given method return type is supported by this handler.
      Specified by:
        `supportsReturnType` in interface `HandlerMethodReturnValueHandler`
      Parameters:
        `returnType` - the method return type to check
      Returns:
        `true` if this handler supports the supplied return type; `false` otherwise

    - #### handleReturnValue

          public void handleReturnValue(@Nullable
                                        Object returnValue,
                                        MethodParameter returnType,
                                        Message<?> message)
                                 throws Exception

      Description copied from interface: `HandlerMethodReturnValueHandler`
      Handle the given return value.
      Specified by:
        `handleReturnValue` in interface `HandlerMethodReturnValueHandler`
      Parameters:
        `returnValue` - the value returned from the handler method
        `returnType` - 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 called
      Throws:
        `Exception` - if the return value handling results in an error

    - #### isAsyncReturnValue

          public boolean isAsyncReturnValue(Object returnValue,
                                            MethodParameter returnType)

      Description copied from interface: `AsyncHandlerMethodReturnValueHandler`
      Whether the return value represents an asynchronous, Future-like type with success and error callbacks. If this method returns `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`.

      Specified by:
        `isAsyncReturnValue` in interface `AsyncHandlerMethodReturnValueHandler`
      Parameters:
        `returnValue` - the value returned from the handler method
        `returnType` - the type of the return value
      Returns:
        `true` if the return value type represents an async value

    - #### toListenableFuture

          @Nullable
          public ListenableFuture<?> toListenableFuture(Object returnValue,
                                                                  MethodParameter returnType)

      Description copied from interface: `AsyncHandlerMethodReturnValueHandler`
      Adapt the asynchronous return value to a `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`.

      Specified by:
        `toListenableFuture` in interface `AsyncHandlerMethodReturnValueHandler`
      Parameters:
        `returnValue` - the value returned from the handler method
        `returnType` - the type of the return value
      Returns:
        the resulting ListenableFuture, or `null` in which case no further handling will be performed