Auto-add content-length to STOMP 1.1 frames too, inherit 1.2 from 1.1

This commit is contained in:
Ville Skyttä 2015-07-10 14:43:00 +03:00
parent 2f6d3dc064
commit 851ac30f32
2 changed files with 10 additions and 77 deletions

View File

@ -29,7 +29,7 @@ import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
public class StompFrameV11 extends StompFrame
{
//stomp 1.1 talks about repetitive headers.
private final List<Header> allHeaders = new ArrayList<Header>();
protected final List<Header> allHeaders = new ArrayList<Header>();
public StompFrameV11(String command, Map<String, String> headers, byte[] content)
{
@ -66,6 +66,13 @@ public class StompFrameV11 extends StompFrame
head.append(h.getEncodedValue());
head.append(Stomp.NEWLINE);
}
if (bytesBody != null && bytesBody.length > 0)
{
head.append(Stomp.Headers.CONTENT_LENGTH);
head.append(Stomp.Headers.SEPARATOR);
head.append(bytesBody.length);
head.append(Stomp.NEWLINE);
}
// Add a newline to separate the headers from the content.
head.append(Stomp.NEWLINE);
@ -95,6 +102,4 @@ public class StompFrameV11 extends StompFrame
allHeaders.add(new Header(key, val));
}
}
}

View File

@ -16,21 +16,12 @@
*/
package org.apache.activemq.artemis.core.protocol.stomp.v12;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
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.Stomp;
import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
import org.apache.activemq.artemis.core.protocol.stomp.v11.StompFrameV11;
public class StompFrameV12 extends StompFrame
public class StompFrameV12 extends StompFrameV11
{
//stomp 1.1 talks about repetitive headers.
private final List<Header> allHeaders = new ArrayList<Header>();
public StompFrameV12(String command, Map<String, String> headers, byte[] content)
{
super(command, headers, content);
@ -40,67 +31,4 @@ public class StompFrameV12 extends StompFrame
{
super(command);
}
@Override
public ActiveMQBuffer toActiveMQBuffer() throws Exception
{
if (buffer == null)
{
if (bytesBody != null)
{
buffer = ActiveMQBuffers.dynamicBuffer(bytesBody.length + 512);
}
else
{
buffer = ActiveMQBuffers.dynamicBuffer(512);
}
StringBuffer head = new StringBuffer();
head.append(command);
head.append(Stomp.NEWLINE);
// Output the headers.
for (Header h : allHeaders)
{
head.append(h.getEncodedKey());
head.append(Stomp.Headers.SEPARATOR);
head.append(h.getEncodedValue());
head.append(Stomp.NEWLINE);
}
if ((bytesBody != null) && (bytesBody.length > 0))
{
head.append(Stomp.Headers.CONTENT_LENGTH);
head.append(Stomp.Headers.SEPARATOR);
head.append(bytesBody.length);
head.append(Stomp.NEWLINE);
}
// Add a newline to separate the headers from the content.
head.append(Stomp.NEWLINE);
buffer.writeBytes(head.toString().getBytes(StandardCharsets.UTF_8));
if (bytesBody != null)
{
buffer.writeBytes(bytesBody);
}
buffer.writeBytes(END_OF_FRAME);
size = buffer.writerIndex();
}
return buffer;
}
@Override
public void addHeader(String key, String val)
{
if (!headers.containsKey(key))
{
headers.put(key, val);
allHeaders.add(new Header(key, val));
}
else if (!key.equals(Stomp.Headers.CONTENT_LENGTH))
{
allHeaders.add(new Header(key, val));
}
}
}