Use base implementation for STOMP 1.1+ toActiveMQBuffer
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/615a9881 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/615a9881 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/615a9881 Branch: refs/heads/master Commit: 615a9881b501586ba787666fc831a8e4f988d1cc Parents: 0b3a64c Author: Ville Skyttä <ville.sky...@iki.fi> Authored: Tue Jul 21 19:06:40 2015 +0300 Committer: Ville Skyttä <ville.sky...@iki.fi> Committed: Tue Jul 21 19:06:40 2015 +0300 ---------------------------------------------------------------------- .../artemis/core/protocol/stomp/StompFrame.java | 19 ++++--- .../core/protocol/stomp/v11/StompFrameV11.java | 56 ++------------------ 2 files changed, 17 insertions(+), 58 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/615a9881/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java ---------------------------------------------------------------------- diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java index d77dc6c..1d37194 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompFrame.java @@ -121,13 +121,7 @@ public class StompFrame head.append(command); head.append(Stomp.NEWLINE); // Output the headers. - for (Map.Entry<String, String> header : headers.entrySet()) - { - head.append(header.getKey()); - head.append(Stomp.Headers.SEPARATOR); - head.append(header.getValue()); - head.append(Stomp.NEWLINE); - } + encodeHeaders(head); if (bytesBody != null && bytesBody.length > 0 && !hasHeader(Stomp.Headers.CONTENT_LENGTH)) { head.append(Stomp.Headers.CONTENT_LENGTH); @@ -154,6 +148,17 @@ public class StompFrame return buffer; } + protected void encodeHeaders(StringBuffer head) + { + for (Map.Entry<String, String> header : headers.entrySet()) + { + head.append(header.getKey()); + head.append(Stomp.Headers.SEPARATOR); + head.append(header.getValue()); + head.append(Stomp.NEWLINE); + } + } + public String getHeader(String key) { return headers.get(key); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/615a9881/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameV11.java ---------------------------------------------------------------------- diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameV11.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameV11.java index 3cd49e4..2a38d40 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameV11.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameV11.java @@ -16,13 +16,10 @@ */ package org.apache.activemq.artemis.core.protocol.stomp.v11; -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; @@ -42,58 +39,15 @@ public class StompFrameV11 extends StompFrame } @Override - public ActiveMQBuffer toActiveMQBuffer() throws Exception + protected void encodeHeaders(StringBuffer head) { - if (isPing()) + for (Header h : allHeaders) { - // ping has some special treatment done at the super package only. - // on that case we will defer it to super. - return super.toActiveMQBuffer(); - } - - 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(h.getEncodedKey()); + head.append(Stomp.Headers.SEPARATOR); + head.append(h.getEncodedValue()); 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 && !hasHeader(Stomp.Headers.CONTENT_LENGTH)) - { - 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