Rename @ReplyTo to @SendTo

This commit is contained in:
Rossen Stoyanchev
2013-09-08 21:22:53 -04:00
parent 41fa15a484
commit 45eab23e15
8 changed files with 65 additions and 65 deletions

View File

@@ -35,7 +35,7 @@ import org.springframework.messaging.Message;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ReplyTo {
public @interface SendTo {
/**
* The destination for a message created from the return value of a method.

View File

@@ -37,13 +37,13 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
* @author Rossen Stoyanchev
* @since 4.0
*
* @see org.springframework.messaging.handler.annotation.ReplyTo
* @see org.springframework.messaging.handler.annotation.SendTo
* @see org.springframework.messaging.simp.handler.UserDestinationMessageHandler
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ReplyToUser {
public @interface SendToUser {
/**
* The destination for a message based on the return value of a method.

View File

@@ -23,19 +23,19 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.MessagePostProcessor;
import org.springframework.messaging.handler.annotation.ReplyTo;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.handler.method.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.annotation.ReplyToUser;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* A {@link HandlerMethodReturnValueHandler} for replying to destinations specified in a
* {@link ReplyTo} or {@link ReplyToUser} method-level annotations.
* A {@link HandlerMethodReturnValueHandler} for sending to destinations specified in a
* {@link SendTo} or {@link SendToUser} method-level annotations.
* <p>
* The value returned from the method is converted, and turned to a {@link Message} and
* sent through the provided {@link MessageChannel}. The
@@ -46,14 +46,14 @@ import org.springframework.util.ObjectUtils;
* @author Rossen Stoyanchev
* @since 4.0
*/
public class ReplyToMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
private final SimpMessageSendingOperations messagingTemplate;
private final boolean annotationRequired;
public ReplyToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
Assert.notNull(messagingTemplate, "messagingTemplate is required");
this.messagingTemplate = messagingTemplate;
this.annotationRequired = annotationRequired;
@@ -62,8 +62,8 @@ public class ReplyToMethodReturnValueHandler implements HandlerMethodReturnValue
@Override
public boolean supportsReturnType(MethodParameter returnType) {
if ((returnType.getMethodAnnotation(ReplyTo.class) != null) ||
(returnType.getMethodAnnotation(ReplyToUser.class) != null)) {
if ((returnType.getMethodAnnotation(SendTo.class) != null) ||
(returnType.getMethodAnnotation(SendToUser.class) != null)) {
return true;
}
return (!this.annotationRequired);
@@ -82,21 +82,21 @@ public class ReplyToMethodReturnValueHandler implements HandlerMethodReturnValue
String sessionId = inputHeaders.getSessionId();
MessagePostProcessor postProcessor = new SessionHeaderPostProcessor(sessionId);
ReplyToUser replyToUser = returnType.getMethodAnnotation(ReplyToUser.class);
if (replyToUser != null) {
SendToUser sendToUser = returnType.getMethodAnnotation(SendToUser.class);
if (sendToUser != null) {
if (inputHeaders.getUser() == null) {
throw new MissingSessionUserException(inputMessage);
}
String user = inputHeaders.getUser().getName();
for (String destination : getDestinations(replyToUser, inputHeaders.getDestination())) {
for (String destination : getDestinations(sendToUser, inputHeaders.getDestination())) {
this.messagingTemplate.convertAndSendToUser(user, destination, returnValue, postProcessor);
}
return;
}
ReplyTo replyTo = returnType.getMethodAnnotation(ReplyTo.class);
if (replyTo != null) {
for (String destination : getDestinations(replyTo, inputHeaders.getDestination())) {
SendTo sendTo = returnType.getMethodAnnotation(SendTo.class);
if (sendTo != null) {
for (String destination : getDestinations(sendTo, inputHeaders.getDestination())) {
this.messagingTemplate.convertAndSend(destination, returnValue, postProcessor);
}
return;
@@ -129,7 +129,7 @@ public class ReplyToMethodReturnValueHandler implements HandlerMethodReturnValue
@Override
public String toString() {
return "ReplyToMethodReturnValueHandler [annotationRequired=" + annotationRequired + "]";
return "SendToMethodReturnValueHandler [annotationRequired=" + annotationRequired + "]";
}
}

View File

@@ -20,10 +20,10 @@ import org.springframework.core.MethodParameter;
import org.springframework.messaging.Message;
import org.springframework.messaging.core.MessagePostProcessor;
import org.springframework.messaging.core.MessageSendingOperations;
import org.springframework.messaging.handler.annotation.ReplyTo;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.handler.method.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.annotation.ReplyToUser;
import org.springframework.messaging.simp.annotation.SendToUser;
import org.springframework.messaging.simp.annotation.SubscribeEvent;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.Assert;
@@ -32,7 +32,7 @@ import org.springframework.util.Assert;
/**
* A {@link HandlerMethodReturnValueHandler} for replying directly to a subscription. It
* supports methods annotated with {@link SubscribeEvent} unless they're also annotated
* with {@link ReplyTo} or {@link ReplyToUser}.
* with {@link SendTo} or {@link SendToUser}.
* <p>
* The value returned from the method is converted, and turned to a {@link Message} and
* then enriched with the sessionId, subscriptionId, and destination of the input message.
@@ -55,8 +55,8 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn
@Override
public boolean supportsReturnType(MethodParameter returnType) {
return ((returnType.getMethodAnnotation(SubscribeEvent.class) != null)
&& (returnType.getMethodAnnotation(ReplyTo.class) == null)
&& (returnType.getMethodAnnotation(ReplyToUser.class) == null));
&& (returnType.getMethodAnnotation(SendTo.class) == null)
&& (returnType.getMethodAnnotation(SendToUser.class) == null));
}
@Override

View File

@@ -58,7 +58,7 @@ import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeEvent;
import org.springframework.messaging.simp.annotation.UnsubscribeEvent;
import org.springframework.messaging.simp.annotation.support.PrincipalMethodArgumentResolver;
import org.springframework.messaging.simp.annotation.support.ReplyToMethodReturnValueHandler;
import org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler;
import org.springframework.messaging.simp.annotation.support.SubscriptionMethodReturnValueHandler;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.converter.MessageConverter;
@@ -201,14 +201,14 @@ public class AnnotationMethodMessageHandler implements MessageHandler, Applicati
this.argumentResolvers.addResolver(new MessageBodyMethodArgumentResolver(this.messageConverter));
// Annotation-based return value types
this.returnValueHandlers.addHandler(new ReplyToMethodReturnValueHandler(this.brokerTemplate, true));
this.returnValueHandlers.addHandler(new SendToMethodReturnValueHandler(this.brokerTemplate, true));
this.returnValueHandlers.addHandler(new SubscriptionMethodReturnValueHandler(this.webSocketResponseTemplate));
// custom return value types
this.returnValueHandlers.addHandlers(this.customReturnValueHandlers);
// catch-all
this.returnValueHandlers.addHandler(new ReplyToMethodReturnValueHandler(this.brokerTemplate, false));
this.returnValueHandlers.addHandler(new SendToMethodReturnValueHandler(this.brokerTemplate, false));
}
protected final void initHandlerMethods() {