Merge pull request from jking-roar/SPR-13111
This commit is contained in:
commit
7b365583e3
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -215,10 +215,10 @@ public class StompDecoder {
|
||||||
if (headerStream.size() > 0) {
|
if (headerStream.size() > 0) {
|
||||||
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
|
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
|
||||||
int colonIndex = header.indexOf(':');
|
int colonIndex = header.indexOf(':');
|
||||||
if (colonIndex <= 0 || colonIndex == header.length() - 1) {
|
if (colonIndex <= 0) {
|
||||||
if (buffer.remaining() > 0) {
|
if(buffer.remaining() > 0) {
|
||||||
throw new StompConversionException("Illegal header: '" + header +
|
throw new StompConversionException("Illegal header: '" + header +
|
||||||
"'. A header must be of the form <name>:<value>.");
|
"'. A header must be of the form <name>:[<value>].");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -176,18 +176,32 @@ public class StompCodecTests {
|
||||||
Buffer buffer = Buffer.wrap(frame1 + frame2);
|
Buffer buffer = Buffer.wrap(frame1 + frame2);
|
||||||
|
|
||||||
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
|
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
|
||||||
new Reactor2StompCodec().decoder(new Consumer<Message<byte[]>>() {
|
new Reactor2StompCodec().decoder(messages::add).apply(buffer);
|
||||||
@Override
|
|
||||||
public void accept(Message<byte[]> message) {
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
}).apply(buffer);
|
|
||||||
|
|
||||||
assertEquals(2, messages.size());
|
assertEquals(2, messages.size());
|
||||||
assertEquals(StompCommand.SEND, StompHeaderAccessor.wrap(messages.get(0)).getCommand());
|
assertEquals(StompCommand.SEND, StompHeaderAccessor.wrap(messages.get(0)).getCommand());
|
||||||
assertEquals(StompCommand.DISCONNECT, StompHeaderAccessor.wrap(messages.get(1)).getCommand());
|
assertEquals(StompCommand.DISCONNECT, StompHeaderAccessor.wrap(messages.get(1)).getCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPR-13111
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void decodeFrameWithHeaderWithEmptyValue() {
|
||||||
|
String accept = "accept-version:1.1\n";
|
||||||
|
String valuelessKey = "key:\n";
|
||||||
|
|
||||||
|
Message<byte[]> frame = decode("CONNECT\n" + accept + valuelessKey + "\n\0");
|
||||||
|
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
|
||||||
|
|
||||||
|
assertEquals(StompCommand.CONNECT, headers.getCommand());
|
||||||
|
|
||||||
|
assertEquals(2, headers.toNativeHeaderMap().size());
|
||||||
|
assertEquals("1.1", headers.getFirstNativeHeader("accept-version"));
|
||||||
|
assertEquals("", headers.getFirstNativeHeader("key"));
|
||||||
|
|
||||||
|
assertEquals(0, frame.getPayload().length);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decodeFrameWithIncompleteCommand() {
|
public void decodeFrameWithIncompleteCommand() {
|
||||||
assertIncompleteDecode("MESSAG");
|
assertIncompleteDecode("MESSAG");
|
||||||
|
|
@ -234,12 +248,7 @@ public class StompCodecTests {
|
||||||
Buffer buffer = Buffer.wrap(frame);
|
Buffer buffer = Buffer.wrap(frame);
|
||||||
|
|
||||||
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
|
final List<Message<byte[]>> messages = new ArrayList<Message<byte[]>>();
|
||||||
new Reactor2StompCodec().decoder(new Consumer<Message<byte[]>>() {
|
new Reactor2StompCodec().decoder(messages::add).apply(buffer);
|
||||||
@Override
|
|
||||||
public void accept(Message<byte[]> message) {
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
}).apply(buffer);
|
|
||||||
|
|
||||||
assertEquals(1, messages.size());
|
assertEquals(1, messages.size());
|
||||||
assertEquals(SimpMessageType.HEARTBEAT, StompHeaderAccessor.wrap(messages.get(0)).getMessageType());
|
assertEquals(SimpMessageType.HEARTBEAT, StompHeaderAccessor.wrap(messages.get(0)).getMessageType());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue