Skip to content

Commit e4031f2

Browse files
committed
Efficient log checks in STOMP encoder/decoder
(cherry picked from commit 122ee30)
1 parent 55fa5f2 commit e4031f2

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,9 +150,7 @@ private Message<byte[]> decodeMessage(ByteBuffer buffer, MultiValueMap<String, S
150150
}
151151
}
152152
else {
153-
if (logger.isTraceEnabled()) {
154-
logger.trace("Incomplete frame, resetting input buffer...");
155-
}
153+
logger.trace("Incomplete frame, resetting input buffer...");
156154
if (headers != null && headerAccessor != null) {
157155
String name = NativeMessageHeaderAccessor.NATIVE_HEADERS;
158156
@SuppressWarnings("unchecked")
@@ -288,7 +286,9 @@ private byte[] readPayload(ByteBuffer buffer, StompHeaderAccessor headerAccessor
288286
contentLength = headerAccessor.getContentLength();
289287
}
290288
catch (NumberFormatException ex) {
291-
logger.warn("Ignoring invalid content-length: '" + headerAccessor);
289+
if (logger.isWarnEnabled()) {
290+
logger.warn("Ignoring invalid content-length: '" + headerAccessor);
291+
}
292292
contentLength = null;
293293
}
294294

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,9 +97,7 @@ public byte[] encode(Map<String, Object> headers, byte[] payload) {
9797
DataOutputStream output = new DataOutputStream(baos);
9898

9999
if (SimpMessageType.HEARTBEAT.equals(SimpMessageHeaderAccessor.getMessageType(headers))) {
100-
if (logger.isTraceEnabled()) {
101-
logger.trace("Encoding heartbeat");
102-
}
100+
logger.trace("Encoding heartbeat");
103101
output.write(StompDecoder.HEARTBEAT_PAYLOAD);
104102
}
105103

0 commit comments

Comments
 (0)