diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java index 3a9a04ece1..cbaa802131 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractSubscriptionRegistry.java @@ -23,6 +23,8 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; +import org.springframework.util.CollectionUtils; +import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; /** @@ -35,6 +37,10 @@ import org.springframework.util.MultiValueMap; */ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegistry { + private static MultiValueMap EMPTY_MAP = + CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap(0)); + + protected final Log logger = LogFactory.getLog(getClass()); @@ -104,7 +110,7 @@ public abstract class AbstractSubscriptionRegistry implements SubscriptionRegist String destination = SimpMessageHeaderAccessor.getDestination(headers); if (destination == null) { logger.error("No destination in " + message); - return null; + return EMPTY_MAP; } return findSubscriptionsInternal(destination, message); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index 248361ccd9..97afc43f90 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -72,7 +72,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { private String selectorHeaderName = "selector"; - private ExpressionParser expressionParser = new SpelExpressionParser(); + private volatile boolean selectorHeaderInUse = false; + + private final ExpressionParser expressionParser = new SpelExpressionParser(); private final DestinationCache destinationCache = new DestinationCache(); @@ -143,6 +145,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { if (selector != null) { try { expression = this.expressionParser.parseExpression(selector); + this.selectorHeaderInUse = true; if (logger.isTraceEnabled()) { logger.trace("Subscription selector: [" + selector + "]"); } @@ -185,6 +188,9 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { private MultiValueMap filterSubscriptions( MultiValueMap allMatches, Message message) { + if (!this.selectorHeaderInUse) { + return allMatches; + } EvaluationContext context = null; MultiValueMap result = new LinkedMultiValueMap(allMatches.size()); for (String sessionId : allMatches.keySet()) {