|
81 | 81 | *
|
82 | 82 | * @author Rossen Stoyanchev
|
83 | 83 | * @author Brian Clozel
|
| 84 | + * @author Juergen Hoeller |
84 | 85 | * @since 4.0
|
85 | 86 | */
|
86 | 87 | public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
@@ -364,36 +365,47 @@ protected boolean isHandler(Class<?> beanType) {
|
364 | 365 |
|
365 | 366 | @Override
|
366 | 367 | 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; |
373 | 379 | }
|
374 |
| - return result; |
375 | 380 | }
|
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; |
381 | 393 | }
|
382 |
| - return result; |
383 | 394 | }
|
| 395 | + |
384 | 396 | return null;
|
385 | 397 | }
|
386 | 398 |
|
387 |
| - private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) { |
388 |
| - String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value()); |
| 399 | + private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) { |
| 400 | + String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); |
389 | 401 | return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
|
390 |
| - new DestinationPatternsMessageCondition(destinations, this.pathMatcher)); |
| 402 | + new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); |
391 | 403 | }
|
392 | 404 |
|
393 |
| - private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) { |
394 |
| - String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value()); |
| 405 | + private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) { |
| 406 | + String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); |
395 | 407 | return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
|
396 |
| - new DestinationPatternsMessageCondition(destinations, this.pathMatcher)); |
| 408 | + new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); |
397 | 409 | }
|
398 | 410 |
|
399 | 411 | /**
|
|
0 commit comments