This closes #646 ARTEMIS-234 fix content-length for Stomp 1.0

This commit is contained in:
Andy Taylor 2016-07-20 13:40:57 +01:00
commit d1cfcdffa0
4 changed files with 12 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import java.util.Map;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.ActiveMQBuffers;
import org.apache.activemq.artemis.core.protocol.stomp.v10.StompFrameV10;
/** /**
* Represents all the data in a STOMP frame. * Represents all the data in a STOMP frame.
@ -107,7 +108,7 @@ public class StompFrame {
head.append(Stomp.NEWLINE); head.append(Stomp.NEWLINE);
// Output the headers. // Output the headers.
encodeHeaders(head); encodeHeaders(head);
if (bytesBody != null && bytesBody.length > 0 && !hasHeader(Stomp.Headers.CONTENT_LENGTH)) { if (bytesBody != null && bytesBody.length > 0 && !hasHeader(Stomp.Headers.CONTENT_LENGTH) && !(this instanceof StompFrameV10)) {
head.append(Stomp.Headers.CONTENT_LENGTH); head.append(Stomp.Headers.CONTENT_LENGTH);
head.append(Stomp.Headers.SEPARATOR); head.append(Stomp.Headers.SEPARATOR);
head.append(bytesBody.length); head.append(bytesBody.length);

View File

@ -384,18 +384,18 @@ destinations, the Stomp destinations must follow the same convention:
Stomp is mainly a text-orientated protocol. To make it simpler to Stomp is mainly a text-orientated protocol. To make it simpler to
interoperate with JMS and Apache ActiveMQ Artemis Core API, our Stomp implementation interoperate with JMS and Apache ActiveMQ Artemis Core API, our Stomp implementation
checks for presence of the `content-length` header to decide how to map checks for presence of the `content-length` header to decide how to map
a Stomp message to a JMS Message or a Core message. a Stomp 1.0 message to a JMS Message or a Core message.
If the Stomp message does *not* have a `content-length` header, it will If the Stomp 1.0 message does *not* have a `content-length` header, it will
be mapped to a JMS *TextMessage* or a Core message with a *single be mapped to a JMS *TextMessage* or a Core message with a *single
nullable SimpleString in the body buffer*. nullable SimpleString in the body buffer*.
Alternatively, if the Stomp message *has* a `content-length` header, it Alternatively, if the Stomp 1.0 message *has* a `content-length` header, it
will be mapped to a JMS *BytesMessage* or a Core message with a *byte[] will be mapped to a JMS *BytesMessage* or a Core message with a *byte[]
in the body buffer*. in the body buffer*.
The same logic applies when mapping a JMS message or a Core message to The same logic applies when mapping a JMS message or a Core message to
Stomp. A Stomp client can check the presence of the `content-length` Stomp. A Stomp 1.0 client can check the presence of the `content-length`
header to determine the type of the message body (String or bytes). header to determine the type of the message body (String or bytes).
#### Message IDs for Stomp messages #### Message IDs for Stomp messages

View File

@ -595,6 +595,10 @@ public class StompTest extends StompTestBase {
Assert.assertTrue(frame.indexOf("destination:") > 0); Assert.assertTrue(frame.indexOf("destination:") > 0);
Assert.assertTrue(frame.indexOf(getName()) > 0); Assert.assertTrue(frame.indexOf(getName()) > 0);
Pattern cl = Pattern.compile("Content-length:\\s*(\\d+)", Pattern.CASE_INSENSITIVE);
Matcher cl_matcher = cl.matcher(frame);
Assert.assertFalse(cl_matcher.find());
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL; frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
sendFrame(frame); sendFrame(frame);

View File

@ -2002,6 +2002,8 @@ public class StompV11Test extends StompV11TestBase {
ClientStompFrame frame = connV11.receiveFrame(); ClientStompFrame frame = connV11.receiveFrame();
assertEquals(getName().length(), Integer.parseInt(frame.getHeader("content-length")));
this.ack(connV11, "sub1", frame); this.ack(connV11, "sub1", frame);
connV11.disconnect(); connV11.disconnect();