org.springframework.messaging.simp.annotation.support

## Class SubscriptionMethodReturnValueHandler

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

All Implemented Interfaces:
  HandlerMethodReturnValueHandler

    public class SubscriptionMethodReturnValueHandler
    extends Object
    implements HandlerMethodReturnValueHandler

`HandlerMethodReturnValueHandler` for replying directly to a subscription. It is supported on methods annotated with `SubscribeMapping` such that the return value is treated as a response to be sent directly back on the session. This allows a client to implement a request-response pattern and use it for example to obtain some data upon initialization.

The value returned from the method is converted and turned into a `Message` that is then enriched with the sessionId, subscriptionId, and destination of the input message.

Note: this default behavior for interpreting the return value from an `@SubscribeMapping` method can be overridden through use of the `SendTo` or `SendToUser` annotations in which case a message is prepared and sent to the broker instead.

Since:
  4.0
Author:
  Rossen Stoyanchev, Sebastien Deleuze

### Constructor Summary

Constructors
Constructor and Description
`SubscriptionMethodReturnValueHandler(MessageSendingOperations<String> template)` Construct a new SubscriptionMethodReturnValueHandler.

### Method Summary

All Methods Instance Methods Concrete Methods
`MessageHeaderInitializer` `getHeaderInitializer()` Return the configured header initializer.
`void` `handleReturnValue(Object returnValue, org.springframework.core.MethodParameter returnType, Message<?> message)` Handle the given return value.
`void` `setHeaderInitializer(MessageHeaderInitializer headerInitializer)` Configure a `MessageHeaderInitializer` to apply to the headers of all messages sent to the client outbound channel.
`boolean` `supportsReturnType(org.springframework.core.MethodParameter returnType)` Whether the given method return type is supported by this handler.

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

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

### Constructor Detail

#### SubscriptionMethodReturnValueHandler

    public SubscriptionMethodReturnValueHandler(MessageSendingOperations<String> template)

Construct a new SubscriptionMethodReturnValueHandler.

Parameters:
  `template` - a messaging template to send messages to, most likely the "clientOutboundChannel" (must not be `null`)

### Method Detail

#### setHeaderInitializer

    public void setHeaderInitializer(@Nullable
                                     MessageHeaderInitializer headerInitializer)

Configure a `MessageHeaderInitializer` to apply to the headers of all messages sent to the client outbound channel.

By default this property is not set.

#### getHeaderInitializer

    @Nullable
    public MessageHeaderInitializer getHeaderInitializer()

Return the configured header initializer.

#### supportsReturnType

    public boolean supportsReturnType(org.springframework.core.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,
                                  org.springframework.core.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