类 SendToMethodReturnValueHandler
- java.lang.Object
- org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler
- 所有已实现的接口:
HandlerMethodReturnValueHandler
public class SendToMethodReturnValueHandler extends Object implements HandlerMethodReturnValueHandler
AHandlerMethodReturnValueHandler
for sending to destinations specified in aSendTo
orSendToUser
method-level annotations.The value returned from the method is converted, and turned to a
Message
and sent through the providedMessageChannel
. 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.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Sebastien Deleuze
构造器概要
构造器 构造器 说明 SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired)
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 String
getDefaultDestinationPrefix()
Return the configured default destination prefix.String
getDefaultUserDestinationPrefix()
Return the configured default user destination prefix.MessageHeaderInitializer
getHeaderInitializer()
Return the configured header initializer.protected String[]
getTargetDestinations(Annotation annotation, Message<?> message, String defaultPrefix)
protected String
getUserName(Message<?> message, MessageHeaders headers)
void
handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message)
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.void
setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializer
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.String
toString()
构造器详细资料
SendToMethodReturnValueHandler
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired)
方法详细资料
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.
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.
setHeaderInitializer
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializer
to apply to the headers of all messages sent to the client outbound channel.By default this property is not set.
getHeaderInitializer
public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.
supportsReturnType
public boolean supportsReturnType(MethodParameter returnType)
从接口复制的说明:HandlerMethodReturnValueHandler
Whether the given method return type is supported by this handler.- 指定者:
supportsReturnType
在接口中HandlerMethodReturnValueHandler
- 参数:
returnType
- the method return type to check- 返回:
true
if this handler supports the supplied return type;false
otherwise
handleReturnValue
public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception
从接口复制的说明:HandlerMethodReturnValueHandler
Handle the given return value.- 指定者:
handleReturnValue
在接口中HandlerMethodReturnValueHandler
- 参数:
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- 抛出:
Exception
- if the return value handling results in an error
getUserName
protected String getUserName(Message<?> message, MessageHeaders headers)
getTargetDestinations
protected String[] getTargetDestinations(Annotation annotation, Message<?> message, String defaultPrefix)