Skip to content

Commit 4b27a6d

Browse files
committed
SimpAnnotationMethodMessageHandler ignores empty marker annotations
Issue: SPR-13704 (cherry picked from commit f119962)
1 parent 3403e8d commit 4b27a6d

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
*
7777
* @author Rossen Stoyanchev
7878
* @author Brian Clozel
79+
* @author Juergen Hoeller
7980
* @since 4.0
8081
*/
8182
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
@@ -289,7 +290,7 @@ public final void stop(Runnable callback) {
289290

290291
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
291292
ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ?
292-
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);
293+
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);
293294

294295
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
295296

@@ -342,34 +343,45 @@ protected boolean isHandler(Class<?> beanType) {
342343

343344
@Override
344345
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
345-
MessageMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
346-
MessageMapping messageAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class);
347-
if (messageAnnotation != null) {
348-
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnnotation);
349-
if (typeAnnotation != null) {
350-
result = createMessageMappingCondition(typeAnnotation).combine(result);
346+
MessageMapping messageAnn = AnnotationUtils.findAnnotation(method, MessageMapping.class);
347+
if (messageAnn != null) {
348+
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
349+
// Only actually register it if there are destinations specified;
350+
// otherwise @MessageMapping is just being used as a (meta-annotation) marker.
351+
if (messageAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
352+
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnn.value());
353+
if (typeAnn != null) {
354+
result = createMessageMappingCondition(typeAnn.value()).combine(result);
355+
}
356+
return result;
351357
}
352-
return result;
353358
}
354-
SubscribeMapping subscribeAnnotation = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
355-
if (subscribeAnnotation != null) {
356-
SimpMessageMappingInfo result = createSubscribeCondition(subscribeAnnotation);
357-
if (typeAnnotation != null) {
358-
result = createMessageMappingCondition(typeAnnotation).combine(result);
359+
360+
SubscribeMapping subscribeAnn = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
361+
if (subscribeAnn != null) {
362+
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
363+
// Only actually register it if there are destinations specified;
364+
// otherwise @SubscribeMapping is just being used as a (meta-annotation) marker.
365+
if (subscribeAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
366+
SimpMessageMappingInfo result = createSubscribeMappingCondition(subscribeAnn.value());
367+
if (typeAnn != null) {
368+
result = createMessageMappingCondition(typeAnn.value()).combine(result);
369+
}
370+
return result;
359371
}
360-
return result;
361372
}
373+
362374
return null;
363375
}
364376

365-
private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) {
377+
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
366378
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
367-
new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher));
379+
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
368380
}
369381

370-
private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) {
382+
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
371383
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
372-
new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher));
384+
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
373385
}
374386

375387
@Override

0 commit comments

Comments
 (0)