Skip to content

Commit 44e4569

Browse files
committed
Polish
1 parent 59f3970 commit 44e4569

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ protected String[] getTargetDestinations(Annotation annotation, Message<?> messa
188188
}
189189
}
190190
String name = DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER;
191-
String destination = (String)message.getHeaders().get(name);
192-
if (StringUtils.hasLength(destination) && !destination.startsWith("/")) {
193-
destination = "/" + destination;
194-
}
195-
return new String[] { defaultPrefix + destination };
191+
String destination = (String) message.getHeaders().get(name);
192+
Assert.hasText(destination, "No lookup destination header in " + message);
193+
194+
return (destination.startsWith("/") ?
195+
new String[] {defaultPrefix + destination} : new String[] {defaultPrefix + "/" + destination});
196196
}
197197

198198
private MessageHeaders createHeaders(String sessionId) {

spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandlerTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,18 @@ public void sendToDefaultDestination() throws Exception {
186186
}
187187

188188
@Test
189-
public void sendToDefaultDestinationWithoutLeadingSlash() throws Exception {
189+
public void sendToDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
190190

191191
when(this.messageChannel.send(any(Message.class))).thenReturn(true);
192192

193-
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "dest", null);
193+
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app/", "dest.foo.bar", null);
194194
this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);
195195

196196
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
197197

198198
Message<?> message = this.messageCaptor.getAllValues().get(0);
199199
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
200-
assertEquals("/topic/dest", headers.getDestination());
200+
assertEquals("/topic/dest.foo.bar", headers.getDestination());
201201
}
202202

203203
@Test
@@ -313,19 +313,19 @@ public void sendToUserDefaultDestination() throws Exception {
313313
}
314314

315315
@Test
316-
public void sendToUserDefaultDestinationWithoutLeadingSlash() throws Exception {
316+
public void sendToUserDefaultDestinationWhenUsingDotPathSeparator() throws Exception {
317317

318318
when(this.messageChannel.send(any(Message.class))).thenReturn(true);
319319

320320
TestUser user = new TestUser();
321-
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "dest", user);
321+
Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app/", "dest.foo.bar", user);
322322
this.handler.handleReturnValue(PAYLOAD, this.sendToUserDefaultDestReturnType, inputMessage);
323323

324324
verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());
325325

326326
Message<?> message = this.messageCaptor.getAllValues().get(0);
327327
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
328-
assertEquals("/user/" + user.getName() + "/queue/dest", headers.getDestination());
328+
assertEquals("/user/" + user.getName() + "/queue/dest.foo.bar", headers.getDestination());
329329
}
330330

331331
@Test

0 commit comments

Comments
 (0)