This commit is contained in:
Rossen Stoyanchev
2014-07-17 09:24:45 -04:00
parent 59f39706dc
commit 44e4569150
2 changed files with 11 additions and 11 deletions

View File

@@ -188,11 +188,11 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH
}
}
String name = DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER;
String destination = (String)message.getHeaders().get(name);
if (StringUtils.hasLength(destination) && !destination.startsWith("/")) {
destination = "/" + destination;
}
return new String[] { defaultPrefix + destination };
String destination = (String) message.getHeaders().get(name);
Assert.hasText(destination, "No lookup destination header in " + message);
return (destination.startsWith("/") ?
new String[] {defaultPrefix + destination} : new String[] {defaultPrefix + "/" + destination});
}
private MessageHeaders createHeaders(String sessionId) {

View File

@@ -186,18 +186,18 @@ public class SendToMethodReturnValueHandlerTests {
}
@Test
public void sendToDefaultDestinationWithoutLeadingSlash() throws Exception {
public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
when(this.messageChannel.send(any(Message.class))).thenReturn(true);
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "dest", null);
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app/", "dest.foo.bar", null);
this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
Message<?> message = this.messageCaptor.getAllValues().get(0);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
assertEquals("/topic/dest", headers.getDestination());
assertEquals("/topic/dest.foo.bar", headers.getDestination());
}
@Test
@@ -313,19 +313,19 @@ public class SendToMethodReturnValueHandlerTests {
}
@Test
public void sendToUserDefaultDestinationWithoutLeadingSlash() throws Exception {
public void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
when(this.messageChannel.send(any(Message.class))).thenReturn(true);
TestUser user = new TestUser();
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "dest", user);
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app/", "dest.foo.bar", user);
this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
Message<?> message = this.messageCaptor.getAllValues().get(0);
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
assertEquals("/user/" + user.getName() + "/queue/dest", headers.getDestination());
assertEquals("/user/" + user.getName() + "/queue/dest.foo.bar", headers.getDestination());
}
@Test