|
76 | 76 | * |
77 | 77 | * @author Rossen Stoyanchev |
78 | 78 | * @author Brian Clozel |
| 79 | + * @author Juergen Hoeller |
79 | 80 | * @since 4.0 |
80 | 81 | */ |
81 | 82 | public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo> |
@@ -289,7 +290,7 @@ public final void stop(Runnable callback) { |
289 | 290 |
|
290 | 291 | protected List<HandlerMethodArgumentResolver> initArgumentResolvers() { |
291 | 292 | ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ? |
292 | | - ((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null); |
| 293 | + ((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null); |
293 | 294 |
|
294 | 295 | List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>(); |
295 | 296 |
|
@@ -342,34 +343,45 @@ protected boolean isHandler(Class<?> beanType) { |
342 | 343 |
|
343 | 344 | @Override |
344 | 345 | 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; |
351 | 357 | } |
352 | | - return result; |
353 | 358 | } |
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; |
359 | 371 | } |
360 | | - return result; |
361 | 372 | } |
| 373 | + |
362 | 374 | return null; |
363 | 375 | } |
364 | 376 |
|
365 | | - private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) { |
| 377 | + private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) { |
366 | 378 | return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE, |
367 | | - new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher)); |
| 379 | + new DestinationPatternsMessageCondition(destinations, this.pathMatcher)); |
368 | 380 | } |
369 | 381 |
|
370 | | - private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) { |
| 382 | + private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) { |
371 | 383 | return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE, |
372 | | - new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher)); |
| 384 | + new DestinationPatternsMessageCondition(destinations, this.pathMatcher)); |
373 | 385 | } |
374 | 386 |
|
375 | 387 | @Override |
|
0 commit comments