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 84c485b6a8..491c6a97f7 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 @@ -29,7 +29,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffers; */ public class StompFrame { - private static final byte[] END_OF_FRAME = new byte[]{0, '\n'}; + protected static final byte[] END_OF_FRAME = new byte[]{0, '\n'}; protected final String command; diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/VersionedStompFrameHandler.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/VersionedStompFrameHandler.java index c6891043b6..2bed68c7ef 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/VersionedStompFrameHandler.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/VersionedStompFrameHandler.java @@ -165,7 +165,7 @@ public abstract class VersionedStompFrameHandler public StompFrame handleReceipt(String receiptID) { - StompFrame receipt = new StompFrame(Stomp.Responses.RECEIPT); + StompFrame receipt = createStompFrame(Stomp.Responses.RECEIPT); receipt.addHeader(Stomp.Headers.Response.RECEIPT_ID, receiptID); return receipt; diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java index 538427741c..656ed8de46 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java @@ -103,7 +103,8 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler implements else { // not valid - response = new StompFrame(Stomp.Responses.ERROR, true); + response = createStompFrame(Stomp.Responses.ERROR); + response.setNeedsDisconnect(true); response.addHeader(Stomp.Headers.Error.MESSAGE, "Failed to connect"); response.setBody("The login account is not valid."); } @@ -268,7 +269,7 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler implements public StompFrame createPingFrame() { - StompFrame frame = new StompFrame(Stomp.Commands.STOMP); + StompFrame frame = createStompFrame(Stomp.Commands.STOMP); frame.setPing(true); return frame; } 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 b0e31376c8..e0572c7906 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 @@ -28,10 +28,8 @@ import org.apache.activemq.artemis.core.protocol.stomp.StompFrame; public class StompFrameV11 extends StompFrame { - private static final byte[] END_OF_FRAME = new byte[]{0, '\n'}; - //stomp 1.1 talks about repetitive headers. - private final List
allHeaders = new ArrayList
(); + protected final List
allHeaders = new ArrayList
(); public StompFrameV11(String command, Map headers, byte[] content) { @@ -68,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); @@ -97,6 +102,4 @@ public class StompFrameV11 extends StompFrame allHeaders.add(new Header(key, val)); } } - - } diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameV12.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameV12.java index c9dd728c13..fdf8a7037b 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameV12.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameV12.java @@ -16,23 +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 { - private static final byte[] END_OF_FRAME = new byte[]{0, '\n'}; - - //stomp 1.1 talks about repetitive headers. - private final List
allHeaders = new ArrayList
(); - public StompFrameV12(String command, Map headers, byte[] content) { super(command, headers, content); @@ -42,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)); - } - } }