Skip to content

Commit a831ed5

Browse files
committed
Polishing
1 parent 05bdc2c commit a831ed5

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public MessageHeaderInitializer getHeaderInitializer() {
7979
* list of {@link Message}s. If the input buffer contains partial STOMP frame
8080
* content, or additional content with a partial STOMP frame, the buffer is
8181
* reset and {@code null} is returned.
82-
* @param buffer The buffer to decode the STOMP frame from
82+
* @param buffer the buffer to decode the STOMP frame from
8383
* @return the decoded messages, or an empty list if none
84+
* @throws StompConversionException raised in case of decoding issues
8485
*/
8586
public List<Message<byte[]>> decode(ByteBuffer buffer) {
8687
return decode(buffer, null);
@@ -98,11 +99,11 @@ public List<Message<byte[]>> decode(ByteBuffer buffer) {
9899
* headers in case of partial content. The caller can then check if a
99100
* "content-length" header was read, which helps to determine how much more
100101
* content is needed before the next attempt to decode.
101-
* @param buffer The buffer to decode the STOMP frame from
102+
* @param buffer the buffer to decode the STOMP frame from
102103
* @param partialMessageHeaders an empty output map that will store the last
103104
* successfully parsed partialMessageHeaders in case of partial message content
104105
* in cases where the partial buffer ended with a partial STOMP frame
105-
* @return decoded messages or an empty list
106+
* @return the decoded messages, or an empty list if none
106107
* @throws StompConversionException raised in case of decoding issues
107108
*/
108109
public List<Message<byte[]>> decode(ByteBuffer buffer, MultiValueMap<String, String> partialMessageHeaders) {
@@ -152,7 +153,7 @@ private Message<byte[]> decodeMessage(ByteBuffer buffer, MultiValueMap<String, S
152153
}
153154
else {
154155
if (logger.isTraceEnabled()) {
155-
logger.trace("Incomplete frame, resetting input buffer.");
156+
logger.trace("Incomplete frame, resetting input buffer...");
156157
}
157158
if (headers != null && headerAccessor != null) {
158159
String name = NativeMessageHeaderAccessor.NATIVE_HEADERS;
@@ -214,7 +215,7 @@ private void readHeaders(ByteBuffer buffer, StompHeaderAccessor headerAccessor)
214215
if (headerStream.size() > 0) {
215216
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
216217
int colonIndex = header.indexOf(':');
217-
if ((colonIndex <= 0) || (colonIndex == header.length() - 1)) {
218+
if (colonIndex <= 0 || colonIndex == header.length() - 1) {
218219
if (buffer.remaining() > 0) {
219220
throw new StompConversionException("Illegal header: '" + header +
220221
"'. A header must be of the form <name>:<value>.");

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/BufferingStompDecoderTests.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727

2828
import static org.junit.Assert.*;
2929

30-
3130
/**
32-
* Unit tests for {@link BufferingStompDecoder}..
31+
* Unit tests for {@link BufferingStompDecoder}.
3332
*
3433
* @author Rossen Stoyanchev
3534
* @since 4.0.3
@@ -38,9 +37,9 @@ public class BufferingStompDecoderTests {
3837

3938
private final StompDecoder STOMP_DECODER = new StompDecoder();
4039

40+
4141
@Test
4242
public void basic() throws InterruptedException {
43-
4443
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
4544
String chunk = "SEND\na:alpha\n\nMessage body\0";
4645

@@ -54,7 +53,6 @@ public void basic() throws InterruptedException {
5453

5554
@Test
5655
public void oneMessageInTwoChunks() throws InterruptedException {
57-
5856
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
5957
String chunk1 = "SEND\na:alpha\n\nMessage";
6058
String chunk2 = " body\0";
@@ -72,7 +70,6 @@ public void oneMessageInTwoChunks() throws InterruptedException {
7270

7371
@Test
7472
public void twoMessagesInOneChunk() throws InterruptedException {
75-
7673
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
7774
String chunk = "SEND\na:alpha\n\nPayload1\0" + "SEND\na:alpha\n\nPayload2\0";
7875
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk));
@@ -87,10 +84,8 @@ public void twoMessagesInOneChunk() throws InterruptedException {
8784

8885
@Test
8986
public void oneFullAndOneSplitMessageContentLength() throws InterruptedException {
90-
91-
int contentLength = "Payload2a-Payload2b".getBytes().length;
92-
9387
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
88+
int contentLength = "Payload2a-Payload2b".getBytes().length;
9489
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:" + contentLength + "\n";
9590
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
9691

@@ -118,7 +113,6 @@ public void oneFullAndOneSplitMessageContentLength() throws InterruptedException
118113

119114
@Test
120115
public void oneFullAndOneSplitMessageNoContentLength() throws InterruptedException {
121-
122116
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
123117
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\na:alpha\n";
124118
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@@ -147,7 +141,6 @@ public void oneFullAndOneSplitMessageNoContentLength() throws InterruptedExcepti
147141

148142
@Test
149143
public void oneFullAndOneSplitWithContentLengthExceedingBufferSize() throws InterruptedException {
150-
151144
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
152145
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:129\n";
153146
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@@ -169,24 +162,23 @@ public void oneFullAndOneSplitWithContentLengthExceedingBufferSize() throws Inte
169162
}
170163

171164
@Test(expected = StompConversionException.class)
172-
public void bufferSizeLimit() throws InterruptedException {
165+
public void bufferSizeLimit() {
173166
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 10);
174167
String payload = "SEND\na:alpha\n\nMessage body";
175168
stompDecoder.decode(toByteBuffer(payload));
176169
}
177170

178171
@Test
179-
public void incompleteCommand() throws InterruptedException {
180-
172+
public void incompleteCommand() {
181173
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
182174
String chunk = "MESSAG";
183175

184176
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk));
185177
assertEquals(0, messages.size());
186178
}
187179

188-
@Test(expected = StompConversionException.class) // SPR-12418
189-
public void endingBackslashHeaderValueCheck() throws InterruptedException {
180+
@Test(expected = StompConversionException.class) // SPR-12418
181+
public void endingBackslashHeaderValueCheck() {
190182
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
191183
String payload = "SEND\na:alpha\\\n\nMessage body\0";
192184
stompDecoder.decode(toByteBuffer(payload));

0 commit comments

Comments
 (0)