org.springframework.messaging.simp.annotation.support

## Class SendToMethodReturnValueHandler

- java.lang.Object
- - org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler

- All Implemented Interfaces:
    HandlerMethodReturnValueHandler

      public class SendToMethodReturnValueHandler
      extends Object
      implements HandlerMethodReturnValueHandler

  A `HandlerMethodReturnValueHandler` for sending to destinations specified in a `SendTo` or `SendToUser` method-level annotations.

  The value returned from the method is converted, and turned to a `Message` and sent through the provided `MessageChannel`. The message is then enriched with the sessionId of the input message as well as the destination from the annotation(s). If multiple destinations are specified, a copy of the message is sent to each destination.

  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getDefaultDestinationPrefix()` Return the configured default destination prefix.
    `String` | `getDefaultUserDestinationPrefix()` Return the configured default user destination prefix.
    `protected String[]` | `getTargetDestinations(Annotation annot, SimpMessageHeaderAccessor inputHeaders, String defaultPrefix)`
    `void` | `handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> inputMessage)` Handle the given return value.
    `void` | `setDefaultDestinationPrefix(String defaultDestinationPrefix)` Configure a default prefix to add to message destinations in cases where a method is not annotated with `@SendTo` or does not specify any destinations through the annotation's value attribute.
    `void` | `setDefaultUserDestinationPrefix(String prefix)` Configure a default prefix to add to message destinations in cases where a method is annotated with `@SendToUser` but does not specify any destinations through the annotation's value attribute.
    `boolean` | `supportsReturnType(MethodParameter returnType)` Whether the given method return type is supported by this handler.
    `String` | `toString()`

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

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

- - ### Constructor Detail

    - #### SendToMethodReturnValueHandler

          public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate,
                                                boolean annotationRequired)

  - ### Method Detail

    - #### setDefaultDestinationPrefix

          public void setDefaultDestinationPrefix(String defaultDestinationPrefix)

      Configure a default prefix to add to message destinations in cases where a method is not annotated with `@SendTo` or does not specify any destinations through the annotation's value attribute.

      By default, the prefix is set to "/topic".

    - #### getDefaultDestinationPrefix

          public String getDefaultDestinationPrefix()

      Return the configured default destination prefix.
      See Also:
        `setDefaultDestinationPrefix(String)`

    - #### setDefaultUserDestinationPrefix

          public void setDefaultUserDestinationPrefix(String prefix)

      Configure a default prefix to add to message destinations in cases where a method is annotated with `@SendToUser` but does not specify any destinations through the annotation's value attribute.

      By default, the prefix is set to "/queue".

    - #### getDefaultUserDestinationPrefix

          public String getDefaultUserDestinationPrefix()

      Return the configured default user destination prefix.
      See Also:
        `setDefaultUserDestinationPrefix(String)`

    - #### 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(Object returnValue,
                                        MethodParameter returnType,
                                        Message<?> inputMessage)
                                 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`
        `inputMessage` - the message that caused this method to be called
      Throws:
        `Exception` - if the return value handling results in an error

    - #### getTargetDestinations

          protected String[] getTargetDestinations(Annotation annot,
                                                   SimpMessageHeaderAccessor inputHeaders,
                                                   String defaultPrefix)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`