ARTEMIS-234 fix content-length for Stomp 1.0
This commit is contained in:
parent
413e7aee54
commit
b466cce593
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
|
||||
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
|
||||
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.
|
||||
|
@ -107,7 +108,7 @@ public class StompFrame {
|
|||
head.append(Stomp.NEWLINE);
|
||||
// Output the headers.
|
||||
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.SEPARATOR);
|
||||
head.append(bytesBody.length);
|
||||
|
|
|
@ -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
|
||||
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
|
||||
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
|
||||
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[]
|
||||
in the body buffer*.
|
||||
|
||||
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).
|
||||
|
||||
#### Message IDs for Stomp messages
|
||||
|
|
|
@ -595,6 +595,10 @@ public class StompTest extends StompTestBase {
|
|||
Assert.assertTrue(frame.indexOf("destination:") > 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;
|
||||
sendFrame(frame);
|
||||
|
||||
|
|
|
@ -2002,6 +2002,8 @@ public class StompV11Test extends StompV11TestBase {
|
|||
|
||||
ClientStompFrame frame = connV11.receiveFrame();
|
||||
|
||||
assertEquals(getName().length(), Integer.parseInt(frame.getHeader("content-length")));
|
||||
|
||||
this.ack(connV11, "sub1", frame);
|
||||
|
||||
connV11.disconnect();
|
||||
|
|
Loading…
Reference in New Issue