diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java index 0088adb7d8..7417ae7a55 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java @@ -258,9 +258,9 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate headerEntry : headers.entrySet()) { + Object value = headerEntry.getValue(); + headerAccessor.setNativeHeader(headerEntry.getKey(), (value != null ? value.toString() : null)); } return headerAccessor.getMessageHeaders(); } 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 254384c2cd..92694f8d9a 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 @@ -425,8 +425,8 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { } public Subscription getSubscription(String subscriptionId) { - for (String destination : this.destinationLookup.keySet()) { - Set subs = this.destinationLookup.get(destination); + for (Map.Entry> destinationEntry : this.destinationLookup.entrySet()) { + Set subs = destinationEntry.getValue(); if (subs != null) { for (Subscription sub : subs) { if (sub.getId().equalsIgnoreCase(subscriptionId)) { @@ -453,17 +453,17 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { } public String removeSubscription(String subscriptionId) { - for (String destination : this.destinationLookup.keySet()) { - Set subs = this.destinationLookup.get(destination); + for (Map.Entry> destinationEntry : this.destinationLookup.entrySet()) { + Set subs = destinationEntry.getValue(); if (subs != null) { for (Subscription sub : subs) { if (sub.getId().equals(subscriptionId) && subs.remove(sub)) { synchronized (this.destinationLookup) { if (subs.isEmpty()) { - this.destinationLookup.remove(destination); + this.destinationLookup.remove(destinationEntry.getKey()); } } - return destination; + return destinationEntry.getKey(); } } } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java index 290ee6dffe..eae41dfe99 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java @@ -19,6 +19,7 @@ package org.springframework.messaging.simp.broker; import java.security.Principal; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; @@ -333,11 +334,11 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { logger.debug("Broadcasting to " + subscriptions.size() + " sessions."); } long now = System.currentTimeMillis(); - for (String sessionId : subscriptions.keySet()) { - for (String subscriptionId : subscriptions.get(sessionId)) { + for (Map.Entry> subscriptionEntry : subscriptions.entrySet()) { + for (String subscriptionId : subscriptionEntry.getValue()) { SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); initHeaders(headerAccessor); - headerAccessor.setSessionId(sessionId); + headerAccessor.setSessionId(subscriptionEntry.getKey()); headerAccessor.setSubscriptionId(subscriptionId); headerAccessor.copyHeadersIfAbsent(message.getHeaders()); Object payload = message.getPayload(); @@ -349,7 +350,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { logger.error("Failed to send " + message, ex); } finally { - SessionInfo info = this.sessions.get(sessionId); + SessionInfo info = this.sessions.get(subscriptionEntry.getKey()); if (info != null) { info.setLastWriteTime(now); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java index 7ff5c88c24..3d706005d3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java @@ -191,9 +191,9 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { if (headers == null) { return; } - for (String header : headers.keySet()) { - for (String value : headers.get(header)) { - addNativeHeader(header, value); + for (Map.Entry> headerEntry : headers.entrySet()) { + for (String value : headerEntry.getValue()) { + addNativeHeader(headerEntry.getKey(), value); } } }