public class SendToMethodReturnValueHandler extends java.lang.Object implements HandlerMethodReturnValueHandler
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.
Modifier and Type | Class and Description |
---|---|
private static class |
SendToMethodReturnValueHandler.DestinationVariablePlaceholderResolver |
Modifier and Type | Field and Description |
---|---|
private boolean |
annotationRequired |
private java.lang.String |
defaultDestinationPrefix |
private java.lang.String |
defaultUserDestinationPrefix |
private MessageHeaderInitializer |
headerInitializer |
private SimpMessageSendingOperations |
messagingTemplate |
private PropertyPlaceholderHelper |
placeholderHelper |
Constructor and Description |
---|
SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate,
boolean annotationRequired) |
Modifier and Type | Method and Description |
---|---|
private MessageHeaders |
createHeaders(java.lang.String sessionId,
MethodParameter returnType) |
private java.lang.Object |
findAnnotation(MethodParameter returnType) |
java.lang.String |
getDefaultDestinationPrefix()
Return the configured default destination prefix.
|
java.lang.String |
getDefaultUserDestinationPrefix()
Return the configured default user destination prefix.
|
MessageHeaderInitializer |
getHeaderInitializer()
Return the configured header initializer.
|
protected java.lang.String[] |
getTargetDestinations(java.lang.annotation.Annotation annotation,
Message<?> message,
java.lang.String defaultPrefix) |
protected java.lang.String |
getUserName(Message<?> message,
MessageHeaders headers) |
void |
handleReturnValue(java.lang.Object returnValue,
MethodParameter returnType,
Message<?> message)
Handle the given return value.
|
private PropertyPlaceholderHelper.PlaceholderResolver |
initVarResolver(MessageHeaders headers) |
void |
setDefaultDestinationPrefix(java.lang.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(java.lang.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. |
void |
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure a
MessageHeaderInitializer to apply to the headers of all
messages sent to the client outbound channel. |
boolean |
supportsReturnType(MethodParameter returnType)
Whether the given method return type is
supported by this handler.
|
java.lang.String |
toString() |
private final SimpMessageSendingOperations messagingTemplate
private final boolean annotationRequired
private java.lang.String defaultDestinationPrefix
private java.lang.String defaultUserDestinationPrefix
private PropertyPlaceholderHelper placeholderHelper
@Nullable private MessageHeaderInitializer headerInitializer
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired)
public void setDefaultDestinationPrefix(java.lang.String defaultDestinationPrefix)
@SendTo
or does not specify any destinations
through the annotation's value attribute.
By default, the prefix is set to "/topic".
public java.lang.String getDefaultDestinationPrefix()
setDefaultDestinationPrefix(String)
public void setDefaultUserDestinationPrefix(java.lang.String prefix)
@SendToUser
but does not specify
any destinations through the annotation's value attribute.
By default, the prefix is set to "/queue".
public java.lang.String getDefaultUserDestinationPrefix()
setDefaultUserDestinationPrefix(String)
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
MessageHeaderInitializer
to apply to the headers of all
messages sent to the client outbound channel.
By default this property is not set.
@Nullable public MessageHeaderInitializer getHeaderInitializer()
public boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandler
supportsReturnType
in interface HandlerMethodReturnValueHandler
returnType
- the method return type to checktrue
if this handler supports the supplied return type;
false
otherwisepublic void handleReturnValue(@Nullable java.lang.Object returnValue, MethodParameter returnType, Message<?> message) throws java.lang.Exception
HandlerMethodReturnValueHandler
handleReturnValue
in interface HandlerMethodReturnValueHandler
returnValue
- the value returned from the handler methodreturnType
- 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 calledjava.lang.Exception
- if the return value handling results in an error@Nullable private java.lang.Object findAnnotation(MethodParameter returnType)
private PropertyPlaceholderHelper.PlaceholderResolver initVarResolver(MessageHeaders headers)
@Nullable protected java.lang.String getUserName(Message<?> message, MessageHeaders headers)
protected java.lang.String[] getTargetDestinations(@Nullable java.lang.annotation.Annotation annotation, Message<?> message, java.lang.String defaultPrefix)
private MessageHeaders createHeaders(@Nullable java.lang.String sessionId, MethodParameter returnType)
public java.lang.String toString()
toString
in class java.lang.Object