|
|
|
@ -42,7 +42,9 @@ import org.springframework.messaging.MessageChannel; |
|
|
|
import org.springframework.messaging.MessageHeaders; |
|
|
|
import org.springframework.messaging.MessageHeaders; |
|
|
|
import org.springframework.messaging.converter.MappingJackson2MessageConverter; |
|
|
|
import org.springframework.messaging.converter.MappingJackson2MessageConverter; |
|
|
|
import org.springframework.messaging.converter.StringMessageConverter; |
|
|
|
import org.springframework.messaging.converter.StringMessageConverter; |
|
|
|
|
|
|
|
import org.springframework.messaging.handler.DestinationPatternsMessageCondition; |
|
|
|
import org.springframework.messaging.handler.annotation.SendTo; |
|
|
|
import org.springframework.messaging.handler.annotation.SendTo; |
|
|
|
|
|
|
|
import org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver; |
|
|
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; |
|
|
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; |
|
|
|
import org.springframework.messaging.simp.SimpMessageSendingOperations; |
|
|
|
import org.springframework.messaging.simp.SimpMessageSendingOperations; |
|
|
|
import org.springframework.messaging.simp.SimpMessagingTemplate; |
|
|
|
import org.springframework.messaging.simp.SimpMessagingTemplate; |
|
|
|
@ -54,9 +56,6 @@ import org.springframework.util.MimeType; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
import static org.springframework.messaging.handler.DestinationPatternsMessageCondition.*; |
|
|
|
|
|
|
|
import static org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.*; |
|
|
|
|
|
|
|
import static org.springframework.messaging.support.MessageHeaderAccessor.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Test fixture for {@link SendToMethodReturnValueHandlerTests}. |
|
|
|
* Test fixture for {@link SendToMethodReturnValueHandlerTests}. |
|
|
|
@ -357,7 +356,8 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
verify(messagingTemplate).convertAndSend(eq("/topic/dest"), eq(PAYLOAD), captor.capture()); |
|
|
|
verify(messagingTemplate).convertAndSend(eq("/topic/dest"), eq(PAYLOAD), captor.capture()); |
|
|
|
|
|
|
|
|
|
|
|
MessageHeaders headers = captor.getValue(); |
|
|
|
MessageHeaders headers = captor.getValue(); |
|
|
|
SimpMessageHeaderAccessor accessor = getAccessor(headers, SimpMessageHeaderAccessor.class); |
|
|
|
SimpMessageHeaderAccessor accessor = |
|
|
|
|
|
|
|
MessageHeaderAccessor.getAccessor(headers, SimpMessageHeaderAccessor.class); |
|
|
|
assertNotNull(accessor); |
|
|
|
assertNotNull(accessor); |
|
|
|
assertTrue(accessor.isMutable()); |
|
|
|
assertTrue(accessor.isMutable()); |
|
|
|
assertEquals("sess1", accessor.getSessionId()); |
|
|
|
assertEquals("sess1", accessor.getSessionId()); |
|
|
|
@ -399,7 +399,7 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); |
|
|
|
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create(); |
|
|
|
accessor.setSessionId(sessionId); |
|
|
|
accessor.setSessionId(sessionId); |
|
|
|
accessor.setSubscriptionId("sub1"); |
|
|
|
accessor.setSubscriptionId("sub1"); |
|
|
|
accessor.setHeader(DESTINATION_TEMPLATE_VARIABLES_HEADER, vars); |
|
|
|
accessor.setHeader(DestinationVariableMethodArgumentResolver.DESTINATION_TEMPLATE_VARIABLES_HEADER, vars); |
|
|
|
Message<?> message = MessageBuilder.createMessage(PAYLOAD, accessor.getMessageHeaders()); |
|
|
|
Message<?> message = MessageBuilder.createMessage(PAYLOAD, accessor.getMessageHeaders()); |
|
|
|
this.handler.handleReturnValue(PAYLOAD, this.sendToWithPlaceholdersReturnType, message); |
|
|
|
this.handler.handleReturnValue(PAYLOAD, this.sendToWithPlaceholdersReturnType, message); |
|
|
|
|
|
|
|
|
|
|
|
@ -549,7 +549,7 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
headerAccessor.setSubscriptionId(subsId); |
|
|
|
headerAccessor.setSubscriptionId(subsId); |
|
|
|
if (dest != null && destPrefix != null) { |
|
|
|
if (dest != null && destPrefix != null) { |
|
|
|
headerAccessor.setDestination(destPrefix + dest); |
|
|
|
headerAccessor.setDestination(destPrefix + dest); |
|
|
|
headerAccessor.setHeader(LOOKUP_DESTINATION_HEADER, dest); |
|
|
|
headerAccessor.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER, dest); |
|
|
|
} |
|
|
|
} |
|
|
|
if (user != null) { |
|
|
|
if (user != null) { |
|
|
|
headerAccessor.setUser(user); |
|
|
|
headerAccessor.setUser(user); |
|
|
|
@ -563,83 +563,55 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class TestUser implements Principal { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
|
|
|
|
return "joe"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean implies(Subject subject) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class UniqueUser extends TestUser implements DestinationUserNameProvider { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getDestinationUserName() { |
|
|
|
|
|
|
|
return "Me myself and I"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SendTo |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
@interface MySendTo { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = SendTo.class, attribute = "value") |
|
|
|
|
|
|
|
String[] dest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SendToUser |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
@interface MySendToUser { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = SendToUser.class, attribute = "destinations") |
|
|
|
|
|
|
|
String[] dest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleNoAnnotations() { |
|
|
|
String handleNoAnnotations() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendTo @SuppressWarnings("unused") |
|
|
|
@SendTo |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToDefaultDestination() { |
|
|
|
String handleAndSendToDefaultDestination() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendTo({"/dest1", "/dest2"}) @SuppressWarnings("unused") |
|
|
|
@SendTo({"/dest1", "/dest2"}) |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendTo() { |
|
|
|
String handleAndSendTo() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendTo("/topic/chat.message.filtered.{roomName}") @SuppressWarnings("unused") |
|
|
|
@SendTo("/topic/chat.message.filtered.{roomName}") |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToWithPlaceholders() { |
|
|
|
String handleAndSendToWithPlaceholders() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendToUser @SuppressWarnings("unused") |
|
|
|
@SendToUser |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToUserDefaultDestination() { |
|
|
|
String handleAndSendToUserDefaultDestination() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendToUser(broadcast = false) @SuppressWarnings("unused") |
|
|
|
@SendToUser(broadcast = false) |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToUserDefaultDestinationSingleSession() { |
|
|
|
String handleAndSendToUserDefaultDestinationSingleSession() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendToUser({"/dest1", "/dest2"}) @SuppressWarnings("unused") |
|
|
|
@SendToUser({"/dest1", "/dest2"}) |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToUser() { |
|
|
|
String handleAndSendToUser() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false) @SuppressWarnings("unused") |
|
|
|
@SendToUser(destinations = { "/dest1", "/dest2" }, broadcast = false) |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
String handleAndSendToUserSingleSession() { |
|
|
|
String handleAndSendToUserSingleSession() { |
|
|
|
return PAYLOAD; |
|
|
|
return PAYLOAD; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@JsonView(MyJacksonView1.class) @SuppressWarnings("unused") |
|
|
|
@JsonView(MyJacksonView1.class) |
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
JacksonViewBean handleAndSendToJsonView() { |
|
|
|
JacksonViewBean handleAndSendToJsonView() { |
|
|
|
JacksonViewBean payload = new JacksonViewBean(); |
|
|
|
JacksonViewBean payload = new JacksonViewBean(); |
|
|
|
payload.setWithView1("with"); |
|
|
|
payload.setWithView1("with"); |
|
|
|
@ -649,6 +621,45 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class TestUser implements Principal { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getName() { |
|
|
|
|
|
|
|
return "joe"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean implies(Subject subject) { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class UniqueUser extends TestUser implements DestinationUserNameProvider { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String getDestinationUserName() { |
|
|
|
|
|
|
|
return "Me myself and I"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SendTo |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
@interface MySendTo { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = SendTo.class, attribute = "value") |
|
|
|
|
|
|
|
String[] dest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SendToUser |
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
|
|
|
|
@interface MySendToUser { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AliasFor(annotation = SendToUser.class, attribute = "destinations") |
|
|
|
|
|
|
|
String[] dest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MySendTo(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
@MySendTo(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
private static class SendToTestBean { |
|
|
|
private static class SendToTestBean { |
|
|
|
|
|
|
|
|
|
|
|
@ -667,6 +678,7 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
private static class SendToUserTestBean { |
|
|
|
private static class SendToUserTestBean { |
|
|
|
|
|
|
|
|
|
|
|
@ -685,6 +697,7 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
@MySendToUser(dest = "/dest-default") @SuppressWarnings("unused") |
|
|
|
private static class SendToUserWithSendToOverrideTestBean { |
|
|
|
private static class SendToUserWithSendToOverrideTestBean { |
|
|
|
|
|
|
|
|
|
|
|
@ -701,8 +714,10 @@ public class SendToMethodReturnValueHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private interface MyJacksonView1 {} |
|
|
|
private interface MyJacksonView1 {} |
|
|
|
|
|
|
|
|
|
|
|
private interface MyJacksonView2 {} |
|
|
|
private interface MyJacksonView2 {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
private static class JacksonViewBean { |
|
|
|
private static class JacksonViewBean { |
|
|
|
|
|
|
|
|
|
|
|
|