SimpAnnotationMethodMessageHandler ignores empty marker annotations
Issue: SPR-13704
This commit is contained in:
parent
fdc14a16ee
commit
f119962378
|
|
@ -81,6 +81,7 @@ import org.springframework.validation.Validator;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo>
|
||||||
|
|
@ -364,36 +365,47 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
||||||
MessageMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
|
MessageMapping messageAnn = AnnotationUtils.findAnnotation(method, MessageMapping.class);
|
||||||
MessageMapping messageAnnotation = AnnotationUtils.findAnnotation(method, MessageMapping.class);
|
if (messageAnn != null) {
|
||||||
if (messageAnnotation != null) {
|
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
|
||||||
SimpMessageMappingInfo result = createMessageMappingCondition(messageAnnotation);
|
// Only actually register it if there are destinations specified;
|
||||||
if (typeAnnotation != null) {
|
// otherwise @MessageMapping is just being used as a (meta-annotation) marker.
|
||||||
result = createMessageMappingCondition(typeAnnotation).combine(result);
|
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) {
|
SubscribeMapping subscribeAnn = AnnotationUtils.findAnnotation(method, SubscribeMapping.class);
|
||||||
SimpMessageMappingInfo result = createSubscribeCondition(subscribeAnnotation);
|
if (subscribeAnn != null) {
|
||||||
if (typeAnnotation != null) {
|
MessageMapping typeAnn = AnnotationUtils.findAnnotation(handlerType, MessageMapping.class);
|
||||||
result = createMessageMappingCondition(typeAnnotation).combine(result);
|
// 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimpMessageMappingInfo createMessageMappingCondition(MessageMapping annotation) {
|
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
|
||||||
String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value());
|
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
|
||||||
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
|
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
|
||||||
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
|
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SimpMessageMappingInfo createSubscribeCondition(SubscribeMapping annotation) {
|
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
|
||||||
String[] destinations = resolveEmbeddedValuesInDestinations(annotation.value());
|
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
|
||||||
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
|
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
|
||||||
new DestinationPatternsMessageCondition(destinations, this.pathMatcher));
|
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue