SimpAnnotationMethodMessageHandler ignores empty marker annotations

Issue: SPR-13704
(cherry picked from commit f119962)
This commit is contained in:
Juergen Hoeller
2015-12-10 00:30:50 +01:00
parent 3403e8d843
commit 4b27a6ddee

View File

@@ -76,6 +76,7 @@ import org.springframework.validation.Validator;
*
* @author Rossen Stoyanchev
* @author Brian Clozel
* @author Juergen Hoeller
* @since 4.0
*/
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
@@ -289,7 +290,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
ConfigurableBeanFactory beanFactory = (getApplicationContext() instanceof ConfigurableApplicationContext ?
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory() : null);
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
@@ -342,34 +343,45 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
@Override
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
MessageMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
MessageMapping messageAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class);
if (messageAnnotation != null) {
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnnotation);
if (typeAnnotation != null) {
result = createMessageMappingCondition(typeAnnotation).combine(result);
MessageMapping messageAnn = AnnotationUtils.findAnnotation(method, MessageMapping.class);
if (messageAnn != null) {
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
// Only actually register it if there are destinations specified;
// otherwise @MessageMapping is just being used as a (meta-annotation) marker.
if (messageAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnn.value());
if (typeAnn != null) {
result = createMessageMappingCondition(typeAnn.value()).combine(result);
}
return result;
}
return result;
}
SubscribeMapping subscribeAnnotation = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
if (subscribeAnnotation != null) {
SimpMessageMappingInfo result = createSubscribeCondition(subscribeAnnotation);
if (typeAnnotation != null) {
result = createMessageMappingCondition(typeAnnotation).combine(result);
SubscribeMapping subscribeAnn = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
if (subscribeAnn != null) {
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
// Only actually register it if there are destinations specified;
// otherwise @SubscribeMapping is just being used as a (meta-annotation) marker.
if (subscribeAnn.value().length > 0 || (typeAnn != null && typeAnn.value().length > 0)) {
SimpMessageMappingInfo result = createSubscribeMappingCondition(subscribeAnn.value());
if (typeAnn != null) {
result = createMessageMappingCondition(typeAnn.value()).combine(result);
}
return result;
}
return result;
}
return null;
}
private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) {
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher));
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
}
private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) {
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
new DestinationPatternsMessageCondition(annotation.value(), this.pathMatcher));
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
}
@Override