Skip to content

Commit f119962

Browse files
committed
SimpAnnotationMethodMessageHandler ignores empty marker annotations
Issue: SPR-13704
1 parent fdc14a1 commit f119962

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
*
8282
* @author Rossen Stoyanchev
8383
* @author Brian Clozel
84+
* @author Juergen Hoeller
8485
* @since 4.0
8586
*/
8687
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
@@ -364,36 +365,47 @@ protected boolean isHandler(Class<?> beanType) {
364365

365366
@Override
366367
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
367-
MessageMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
368-
MessageMapping messageAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class);
369-
if (messageAnnotation != null) {
370-
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnnotation);
371-
if (typeAnnotation != null) {
372-
result = createMessageMappingCondition(typeAnnotation).combine(result);
368+
MessageMapping messageAnn = AnnotationUtils.findAnnotation(method, MessageMapping.class);
369+
if (messageAnn != null) {
370+
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
371+
// Only actually register it if there are destinations specified;
372+
// otherwise @MessageMapping is just being used as a (meta-annotation) marker.
373+
if (messageAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
374+
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnn.value());
375+
if (typeAnn != null) {
376+
result = createMessageMappingCondition(typeAnn.value()).combine(result);
377+
}
378+
return result;
373379
}
374-
return result;
375380
}
376-
SubscribeMapping subscribeAnnotation = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
377-
if (subscribeAnnotation != null) {
378-
SimpMessageMappingInfo result = createSubscribeCondition(subscribeAnnotation);
379-
if (typeAnnotation != null) {
380-
result = createMessageMappingCondition(typeAnnotation).combine(result);
381+
382+
SubscribeMapping subscribeAnn = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
383+
if (subscribeAnn != null) {
384+
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
385+
// Only actually register it if there are destinations specified;
386+
// otherwise @SubscribeMapping is just being used as a (meta-annotation) marker.
387+
if (subscribeAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
388+
SimpMessageMappingInfo result = createSubscribeMappingCondition(subscribeAnn.value());
389+
if (typeAnn != null) {
390+
result = createMessageMappingCondition(typeAnn.value()).combine(result);
391+
}
392+
return result;
381393
}
382-
return result;
383394
}
395+
384396
return null;
385397
}
386398

387-
private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) {
388-
String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value());
399+
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
400+
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
389401
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
390-
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
402+
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
391403
}
392404

393-
private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) {
394-
String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value());
405+
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
406+
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
395407
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
396-
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
408+
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
397409
}
398410

399411
/**

0 commit comments

Comments
 (0)