From a6b0b6e27945dcf3c84f2c8ae49969470a1c8c76 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 26 Sep 2016 17:25:21 +0200 Subject: [PATCH] Efficient STOMP content-length header check Issue: SPR-14747 --- .../simp/stomp/StompHeaderAccessor.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java index 07949f4d95c..74a5ce65382 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java @@ -30,21 +30,21 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.util.StringUtils; /** - * A {@code MessageHeaderAccessor} to use when creating a {@code Message} from a - * decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame. + * A {@code MessageHeaderAccessor} to use when creating a {@code Message} from + * a decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame. * - *

When created from STOMP frame content, the actual STOMP headers are stored - * in the native header sub-map managed by the parent class + *

When created from STOMP frame content, the actual STOMP headers are + * stored in the native header sub-map managed by the parent class * {@link org.springframework.messaging.support.NativeMessageHeaderAccessor} - * while the parent class - * {@link org.springframework.messaging.simp.SimpMessageHeaderAccessor} manages - * common processing headers some of which are based on STOMP headers (e.g. - * destination, content-type, etc). + * while the parent class {@link SimpMessageHeaderAccessor} manages common + * processing headers some of which are based on STOMP headers + * (e.g. destination, content-type, etc). * *

An instance of this class can also be created by wrapping an existing * {@code Message}. That message may have been created with the more generic @@ -503,12 +503,8 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { } public static Integer getContentLength(Map> nativeHeaders) { - if (nativeHeaders.containsKey(STOMP_CONTENT_LENGTH_HEADER)) { - List values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); - String value = (values != null ? values.get(0) : null); - return Integer.valueOf(value); - } - return null; + List values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); + return (!CollectionUtils.isEmpty(values) ? Integer.valueOf(values.get(0)) : null); }