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
session id 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, Sebastien Deleuze
-
Constructor Summary
ConstructorsConstructorDescriptionSendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) -
Method Summary
Modifier and TypeMethodDescriptionReturn the configured default destination prefix.Return the configured default user destination prefix.Return the configured header initializer.protected String[]getTargetDestinations(Annotation annotation, Message<?> message, String defaultPrefix) protected StringgetUserName(Message<?> message, MessageHeaders headers) voidhandleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) Handle the given return value.voidsetDefaultDestinationPrefix(String defaultDestinationPrefix) Configure a default prefix to add to message destinations in cases where a method is not annotated with@SendToor does not specify any destinations through the annotation's value attribute.voidConfigure a default prefix to add to message destinations in cases where a method is annotated with@SendToUserbut does not specify any destinations through the annotation's value attribute.voidsetHeaderInitializer(MessageHeaderInitializer headerInitializer) Configure aMessageHeaderInitializerto apply to the headers of all messages sent to the client outbound channel.booleansupportsReturnType(MethodParameter returnType) Whether the given method return type is supported by this handler.toString()
-
Constructor Details
-
SendToMethodReturnValueHandler
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired)
-
-
Method Details
-
setDefaultDestinationPrefix
Configure a default prefix to add to message destinations in cases where a method is not annotated with@SendToor does not specify any destinations through the annotation's value attribute.By default, the prefix is set to "/topic".
-
getDefaultDestinationPrefix
Return the configured default destination prefix.- See Also:
-
setDefaultUserDestinationPrefix
Configure a default prefix to add to message destinations in cases where a method is annotated with@SendToUserbut does not specify any destinations through the annotation's value attribute.By default, the prefix is set to "/queue".
-
getDefaultUserDestinationPrefix
Return the configured default user destination prefix.- See Also:
-
setHeaderInitializer
Configure aMessageHeaderInitializerto apply to the headers of all messages sent to the client outbound channel.By default this property is not set.
-
getHeaderInitializer
Return the configured header initializer. -
supportsReturnType
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, 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
-
getUserName
-
getTargetDestinations
protected String[] getTargetDestinations(@Nullable Annotation annotation, Message<?> message, String defaultPrefix) -
toString
-