Polishing

This commit is contained in:
Juergen Hoeller 2014-11-11 03:09:29 +01:00
parent 05bdc2cf77
commit a831ed524f
2 changed files with 13 additions and 20 deletions

View File

@ -79,8 +79,9 @@ public class StompDecoder {
* list of {@link Message}s. If the input buffer contains partial STOMP frame
* content, or additional content with a partial STOMP frame, the buffer is
* reset and {@code null} is returned.
* @param buffer The buffer to decode the STOMP frame from
* @param buffer the buffer to decode the STOMP frame from
* @return the decoded messages, or an empty list if none
* @throws StompConversionException raised in case of decoding issues
*/
public List<Message<byte[]>> decode(ByteBuffer buffer) {
return decode(buffer, null);
@ -98,11 +99,11 @@ public class StompDecoder {
* headers in case of partial content. The caller can then check if a
* "content-length" header was read, which helps to determine how much more
* content is needed before the next attempt to decode.
* @param buffer The buffer to decode the STOMP frame from
* @param buffer the buffer to decode the STOMP frame from
* @param partialMessageHeaders an empty output map that will store the last
* successfully parsed partialMessageHeaders in case of partial message content
* in cases where the partial buffer ended with a partial STOMP frame
* @return decoded messages or an empty list
* @return the decoded messages, or an empty list if none
* @throws StompConversionException raised in case of decoding issues
*/
public List<Message<byte[]>> decode(ByteBuffer buffer, MultiValueMap<String, String> partialMessageHeaders) {
@ -152,7 +153,7 @@ public class StompDecoder {
}
else {
if (logger.isTraceEnabled()) {
logger.trace("Incomplete frame, resetting input buffer.");
logger.trace("Incomplete frame, resetting input buffer...");
}
if (headers != null && headerAccessor != null) {
String name = NativeMessageHeaderAccessor.NATIVE_HEADERS;
@ -214,7 +215,7 @@ public class StompDecoder {
if (headerStream.size() > 0) {
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
int colonIndex = header.indexOf(':');
if ((colonIndex <= 0) || (colonIndex == header.length() - 1)) {
if (colonIndex <= 0 || colonIndex == header.length() - 1) {
if (buffer.remaining() > 0) {
throw new StompConversionException("Illegal header: '" + header +
"'. A header must be of the form <name>:<value>.");

View File

@ -27,9 +27,8 @@ import org.springframework.messaging.Message;
import static org.junit.Assert.*;
/**
* Unit tests for {@link BufferingStompDecoder}..
* Unit tests for {@link BufferingStompDecoder}.
*
* @author Rossen Stoyanchev
* @since 4.0.3
@ -38,9 +37,9 @@ public class BufferingStompDecoderTests {
private final StompDecoder STOMP_DECODER = new StompDecoder();
@Test
public void basic() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "SEND\na:alpha\n\nMessage body\0";
@ -54,7 +53,6 @@ public class BufferingStompDecoderTests {
@Test
public void oneMessageInTwoChunks() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nMessage";
String chunk2 = " body\0";
@ -72,7 +70,6 @@ public class BufferingStompDecoderTests {
@Test
public void twoMessagesInOneChunk() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "SEND\na:alpha\n\nPayload1\0" + "SEND\na:alpha\n\nPayload2\0";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk));
@ -87,10 +84,8 @@ public class BufferingStompDecoderTests {
@Test
public void oneFullAndOneSplitMessageContentLength() throws InterruptedException {
int contentLength = "Payload2a-Payload2b".getBytes().length;
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
int contentLength = "Payload2a-Payload2b".getBytes().length;
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:" + contentLength + "\n";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@ -118,7 +113,6 @@ public class BufferingStompDecoderTests {
@Test
public void oneFullAndOneSplitMessageNoContentLength() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\na:alpha\n";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@ -147,7 +141,6 @@ public class BufferingStompDecoderTests {
@Test
public void oneFullAndOneSplitWithContentLengthExceedingBufferSize() throws InterruptedException {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk1 = "SEND\na:alpha\n\nPayload1\0SEND\ncontent-length:129\n";
List<Message<byte[]>> messages = stompDecoder.decode(toByteBuffer(chunk1));
@ -169,15 +162,14 @@ public class BufferingStompDecoderTests {
}
@Test(expected = StompConversionException.class)
public void bufferSizeLimit() throws InterruptedException {
public void bufferSizeLimit() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 10);
String payload = "SEND\na:alpha\n\nMessage body";
stompDecoder.decode(toByteBuffer(payload));
}
@Test
public void incompleteCommand() throws InterruptedException {
public void incompleteCommand() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String chunk = "MESSAG";
@ -185,8 +177,8 @@ public class BufferingStompDecoderTests {
assertEquals(0, messages.size());
}
@Test(expected = StompConversionException.class) // SPR-12418
public void endingBackslashHeaderValueCheck() throws InterruptedException {
@Test(expected = StompConversionException.class) // SPR-12418
public void endingBackslashHeaderValueCheck() {
BufferingStompDecoder stompDecoder = new BufferingStompDecoder(STOMP_DECODER, 128);
String payload = "SEND\na:alpha\\\n\nMessage body\0";
stompDecoder.decode(toByteBuffer(payload));