Skip to content

Commit a6b0b6e

Browse files
committed
Efficient STOMP content-length header check
Issue: SPR-14747
1 parent c64f399 commit a6b0b6e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@
3030
import org.springframework.messaging.simp.SimpMessageType;
3131
import org.springframework.messaging.support.MessageHeaderAccessor;
3232
import org.springframework.util.ClassUtils;
33+
import org.springframework.util.CollectionUtils;
3334
import org.springframework.util.MimeType;
3435
import org.springframework.util.MimeTypeUtils;
3536
import org.springframework.util.StringUtils;
3637

3738
/**
38-
* A {@code MessageHeaderAccessor} to use when creating a {@code Message} from a
39-
* decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame.
39+
* A {@code MessageHeaderAccessor} to use when creating a {@code Message} from
40+
* a decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame.
4041
*
41-
* <p>When created from STOMP frame content, the actual STOMP headers are stored
42-
* in the native header sub-map managed by the parent class
42+
* <p>When created from STOMP frame content, the actual STOMP headers are
43+
* stored in the native header sub-map managed by the parent class
4344
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor}
44-
* while the parent class
45-
* {@link org.springframework.messaging.simp.SimpMessageHeaderAccessor} manages
46-
* common processing headers some of which are based on STOMP headers (e.g.
47-
* destination, content-type, etc).
45+
* while the parent class {@link SimpMessageHeaderAccessor} manages common
46+
* processing headers some of which are based on STOMP headers
47+
* (e.g. destination, content-type, etc).
4848
*
4949
* <p>An instance of this class can also be created by wrapping an existing
5050
* {@code Message}. That message may have been created with the more generic
@@ -503,12 +503,8 @@ public static String getPasscode(Map<String, Object> headers) {
503503
}
504504

505505
public static Integer getContentLength(Map<String, List<String>> nativeHeaders) {
506-
if (nativeHeaders.containsKey(STOMP_CONTENT_LENGTH_HEADER)) {
507-
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER);
508-
String value = (values != null ? values.get(0) : null);
509-
return Integer.valueOf(value);
510-
}
511-
return null;
506+
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER);
507+
return (!CollectionUtils.isEmpty(values) ? Integer.valueOf(values.get(0)) : null);
512508
}
513509

514510

0 commit comments

Comments
 (0)