diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/SendToUser.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/SendToUser.java
index a5c7c2b5ffd..a85bc67b9fb 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/SendToUser.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/SendToUser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,13 +22,16 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.springframework.core.annotation.AliasFor;
+
/**
- * Annotation that indicates the return value of a message-handling method should
- * be sent as a {@link org.springframework.messaging.Message} to the specified
- * destination(s) prepended with {@code "/user/{username}"} where the user
- * name is extracted from the headers of the input message being handled.
+ * Annotation that indicates that the return value of a message-handling method
+ * should be sent as a {@link org.springframework.messaging.Message} to the specified
+ * destination(s) prepended with "/user/{username}" where the user name
+ * is extracted from the headers of the input message being handled.
*
* @author Rossen Stoyanchev
+ * @author Sam Brannen
* @since 4.0
* @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler
* @see org.springframework.messaging.simp.user.UserDestinationMessageHandler
@@ -40,13 +43,23 @@ import java.lang.annotation.Target;
public @interface SendToUser {
/**
- * One or more destinations to send a message to. If left unspecified, a
- * default destination is selected based on the destination of the input
- * message being handled.
- * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler
+ * Alias for {@link #destinations}.
+ * @see #destinations
*/
+ @AliasFor(attribute = "destinations")
String[] value() default {};
+ /**
+ * One or more destinations to send a message to.
+ *
If left unspecified, a default destination is selected based on + * the destination of the input message being handled. + * @since 4.2 + * @see #value + * @see org.springframework.messaging.simp.annotation.support.SendToMethodReturnValueHandler + */ + @AliasFor(attribute = "value") + String[] destinations() default {}; + /** * Whether messages should be sent to all sessions associated with the user * or only to the session of the input message being handled. diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java index d28b851c1de..eec22554053 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java @@ -17,10 +17,6 @@ package org.springframework.messaging.simp.annotation.support; import com.fasterxml.jackson.annotation.JsonView; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; -import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER; -import static org.springframework.messaging.support.MessageHeaderAccessor.*; import java.lang.reflect.Method; import java.nio.charset.Charset; @@ -33,6 +29,7 @@ import javax.security.auth.Subject; import org.junit.Before; import org.junit.Test; + import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -57,6 +54,11 @@ import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.util.MimeType; +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; +import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER; +import static org.springframework.messaging.support.MessageHeaderAccessor.*; + /** * Test fixture for {@link SendToMethodReturnValueHandlerTests}. * @@ -466,55 +468,46 @@ public class SendToMethodReturnValueHandlerTests { } } - @SuppressWarnings("unused") public String handleNoAnnotations() { return PAYLOAD; } - @SuppressWarnings("unused") @SendTo public String handleAndSendToDefaultDestination() { return PAYLOAD; } - @SuppressWarnings("unused") @SendTo({"/dest1", "/dest2"}) public String handleAndSendTo() { return PAYLOAD; } - @SuppressWarnings("unused") @SendTo("/topic/chat.message.filtered.{roomName}") public String handleAndSendToWithPlaceholders() { return PAYLOAD; } - @SuppressWarnings("unused") @SendToUser public String handleAndSendToUserDefaultDestination() { return PAYLOAD; } - @SuppressWarnings("unused") - @SendToUser(broadcast=false) + @SendToUser(broadcast = false) public String handleAndSendToUserDefaultDestinationSingleSession() { return PAYLOAD; } - @SuppressWarnings("unused") @SendToUser({"/dest1", "/dest2"}) public String handleAndSendToUser() { return PAYLOAD; } - @SuppressWarnings("unused") - @SendToUser(value={"/dest1", "/dest2"}, broadcast=false) + @SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false) public String handleAndSendToUserSingleSession() { return PAYLOAD; } - @SuppressWarnings("unused") - @SendTo({"/dest"}) + @SendTo("/dest") @JsonView(MyJacksonView1.class) public JacksonViewBean handleAndSendToJsonView() { JacksonViewBean payload = new JacksonViewBean(); @@ -528,6 +521,7 @@ public class SendToMethodReturnValueHandlerTests { private interface MyJacksonView1 {}; private interface MyJacksonView2 {}; + @SuppressWarnings("unused") private static class JacksonViewBean { @JsonView(MyJacksonView1.class)