Use Stomp constants more rather than magic strings

This commit is contained in:
Ville Skyttä 2015-07-09 11:11:06 +03:00 committed by Clebert Suconic
parent 0e3b68db4b
commit 7c41bac6b6
7 changed files with 31 additions and 34 deletions

View File

@ -77,13 +77,13 @@ public class ActiveMQStompException extends Exception
StompFrame frame = null; StompFrame frame = null;
if (handler == null) if (handler == null)
{ {
frame = new StompFrame("ERROR"); frame = new StompFrame(Stomp.Responses.ERROR);
} }
else else
{ {
frame = handler.createStompFrame("ERROR"); frame = handler.createStompFrame(Stomp.Responses.ERROR);
} }
frame.addHeader("message", this.getMessage()); frame.addHeader(Stomp.Headers.Error.MESSAGE, this.getMessage());
for (Header header : headers) for (Header header : headers)
{ {
frame.addHeader(header.key, header.val); frame.addHeader(header.key, header.val);

View File

@ -475,15 +475,15 @@ public final class StompConnection implements RemotingConnection
requestVersions.add(tokenizer.nextToken()); requestVersions.add(tokenizer.nextToken());
} }
if (requestVersions.contains("1.2")) if (requestVersions.contains(StompVersions.V1_2.toString()))
{ {
this.version = StompVersions.V1_2; this.version = StompVersions.V1_2;
} }
else if (requestVersions.contains("1.1")) else if (requestVersions.contains(StompVersions.V1_1.toString()))
{ {
this.version = StompVersions.V1_1; this.version = StompVersions.V1_1;
} }
else if (requestVersions.contains("1.0")) else if (requestVersions.contains(StompVersions.V1_0.toString()))
{ {
this.version = StompVersions.V1_0; this.version = StompVersions.V1_0;
} }
@ -491,8 +491,8 @@ public final class StompConnection implements RemotingConnection
{ {
//not a supported version! //not a supported version!
ActiveMQStompException error = BUNDLE.versionNotSupported(acceptVersion); ActiveMQStompException error = BUNDLE.versionNotSupported(acceptVersion);
error.addHeader("version", acceptVersion); error.addHeader(Stomp.Headers.Error.VERSION, acceptVersion);
error.addHeader("content-type", "text/plain"); error.addHeader(Stomp.Headers.CONTENT_TYPE, "text/plain");
error.setBody("Supported protocol version are " + manager.getSupportedVersionsAsString()); error.setBody("Supported protocol version are " + manager.getSupportedVersionsAsString());
error.setDisconnect(true); error.setDisconnect(true);
throw error; throw error;

View File

@ -27,66 +27,66 @@ public class StompDecoder
{ {
public static final boolean TRIM_LEADING_HEADER_VALUE_WHITESPACE = true; public static final boolean TRIM_LEADING_HEADER_VALUE_WHITESPACE = true;
public static final String COMMAND_ABORT = "ABORT"; public static final String COMMAND_ABORT = Stomp.Commands.ABORT;
public static final int COMMAND_ABORT_LENGTH = COMMAND_ABORT.length(); public static final int COMMAND_ABORT_LENGTH = COMMAND_ABORT.length();
public static final String COMMAND_ACK = "ACK"; public static final String COMMAND_ACK = Stomp.Commands.ACK;
public static final int COMMAND_ACK_LENGTH = COMMAND_ACK.length(); public static final int COMMAND_ACK_LENGTH = COMMAND_ACK.length();
public static final String COMMAND_NACK = "NACK"; public static final String COMMAND_NACK = Stomp.Commands.NACK;
public static final int COMMAND_NACK_LENGTH = COMMAND_NACK.length(); public static final int COMMAND_NACK_LENGTH = COMMAND_NACK.length();
public static final String COMMAND_BEGIN = "BEGIN"; public static final String COMMAND_BEGIN = Stomp.Commands.BEGIN;
public static final int COMMAND_BEGIN_LENGTH = COMMAND_BEGIN.length(); public static final int COMMAND_BEGIN_LENGTH = COMMAND_BEGIN.length();
public static final String COMMAND_COMMIT = "COMMIT"; public static final String COMMAND_COMMIT = Stomp.Commands.COMMIT;
public static final int COMMAND_COMMIT_LENGTH = COMMAND_COMMIT.length(); public static final int COMMAND_COMMIT_LENGTH = COMMAND_COMMIT.length();
public static final String COMMAND_CONNECT = "CONNECT"; public static final String COMMAND_CONNECT = Stomp.Commands.CONNECT;
public static final int COMMAND_CONNECT_LENGTH = COMMAND_CONNECT.length(); public static final int COMMAND_CONNECT_LENGTH = COMMAND_CONNECT.length();
public static final String COMMAND_DISCONNECT = "DISCONNECT"; public static final String COMMAND_DISCONNECT = Stomp.Commands.DISCONNECT;
public static final int COMMAND_DISCONNECT_LENGTH = COMMAND_DISCONNECT.length(); public static final int COMMAND_DISCONNECT_LENGTH = COMMAND_DISCONNECT.length();
public static final String COMMAND_SEND = "SEND"; public static final String COMMAND_SEND = Stomp.Commands.SEND;
public static final int COMMAND_SEND_LENGTH = COMMAND_SEND.length(); public static final int COMMAND_SEND_LENGTH = COMMAND_SEND.length();
public static final String COMMAND_STOMP = "STOMP"; public static final String COMMAND_STOMP = Stomp.Commands.STOMP;
public static final int COMMAND_STOMP_LENGTH = COMMAND_STOMP.length(); public static final int COMMAND_STOMP_LENGTH = COMMAND_STOMP.length();
public static final String COMMAND_SUBSCRIBE = "SUBSCRIBE"; public static final String COMMAND_SUBSCRIBE = Stomp.Commands.SUBSCRIBE;
public static final int COMMAND_SUBSCRIBE_LENGTH = COMMAND_SUBSCRIBE.length(); public static final int COMMAND_SUBSCRIBE_LENGTH = COMMAND_SUBSCRIBE.length();
public static final String COMMAND_UNSUBSCRIBE = "UNSUBSCRIBE"; public static final String COMMAND_UNSUBSCRIBE = Stomp.Commands.UNSUBSCRIBE;
public static final int COMMAND_UNSUBSCRIBE_LENGTH = COMMAND_UNSUBSCRIBE.length(); public static final int COMMAND_UNSUBSCRIBE_LENGTH = COMMAND_UNSUBSCRIBE.length();
/** /**
* * added by meddy, 27 april 2011, handle header parser for reply to websocket protocol *** * * added by meddy, 27 april 2011, handle header parser for reply to websocket protocol ***
*/ */
public static final String COMMAND_CONNECTED = "CONNECTED"; public static final String COMMAND_CONNECTED = Stomp.Responses.CONNECTED;
public static final int COMMAND_CONNECTED_LENGTH = COMMAND_CONNECTED.length(); public static final int COMMAND_CONNECTED_LENGTH = COMMAND_CONNECTED.length();
public static final String COMMAND_MESSAGE = "MESSAGE"; public static final String COMMAND_MESSAGE = Stomp.Responses.MESSAGE;
public static final int COMMAND_MESSAGE_LENGTH = COMMAND_MESSAGE.length(); public static final int COMMAND_MESSAGE_LENGTH = COMMAND_MESSAGE.length();
public static final String COMMAND_ERROR = "ERROR"; public static final String COMMAND_ERROR = Stomp.Responses.ERROR;
public static final int COMMAND_ERROR_LENGTH = COMMAND_ERROR.length(); public static final int COMMAND_ERROR_LENGTH = COMMAND_ERROR.length();
public static final String COMMAND_RECEIPT = "RECEIPT"; public static final String COMMAND_RECEIPT = Stomp.Responses.RECEIPT;
public static final int COMMAND_RECEIPT_LENGTH = COMMAND_RECEIPT.length(); public static final int COMMAND_RECEIPT_LENGTH = COMMAND_RECEIPT.length();
/** /**
@ -131,10 +131,6 @@ public class StompDecoder
public static final byte TAB = (byte) '\t'; public static final byte TAB = (byte) '\t';
public static final String CONTENT_TYPE_HEADER_NAME = "content-type";
public static final String CONTENT_LENGTH_HEADER_NAME = "content-length";
public byte[] workingBuffer = new byte[1024]; public byte[] workingBuffer = new byte[1024];
public int pos; public int pos;
@ -346,7 +342,7 @@ public class StompDecoder
headers.put(headerName, headerValue); headers.put(headerName, headerValue);
if (headerName.equals(CONTENT_LENGTH_HEADER_NAME)) if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
{ {
contentLength = Integer.parseInt(headerValue.toString()); contentLength = Integer.parseInt(headerValue.toString());
} }

View File

@ -379,7 +379,7 @@ class StompProtocolManager implements ProtocolManager<StompFrameInterceptor>, No
public String getSupportedVersionsAsString() public String getSupportedVersionsAsString()
{ {
return "v1.0 v1.1 v1.2"; return "v" + StompVersions.V1_0 + " v" + StompVersions.V1_1 + " v" + StompVersions.V1_2;
} }
public String getVirtualHostName() public String getVirtualHostName()

View File

@ -24,6 +24,7 @@ import org.apache.activemq.artemis.core.protocol.stomp.Stomp;
import org.apache.activemq.artemis.core.protocol.stomp.StompConnection; import org.apache.activemq.artemis.core.protocol.stomp.StompConnection;
import org.apache.activemq.artemis.core.protocol.stomp.StompDecoder; import org.apache.activemq.artemis.core.protocol.stomp.StompDecoder;
import org.apache.activemq.artemis.core.protocol.stomp.StompFrame; import org.apache.activemq.artemis.core.protocol.stomp.StompFrame;
import org.apache.activemq.artemis.core.protocol.stomp.StompVersions;
import org.apache.activemq.artemis.core.protocol.stomp.VersionedStompFrameHandler; import org.apache.activemq.artemis.core.protocol.stomp.VersionedStompFrameHandler;
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
@ -58,7 +59,7 @@ public class StompFrameHandlerV10 extends VersionedStompFrameHandler implements
if (frame.hasHeader(Stomp.Headers.ACCEPT_VERSION)) if (frame.hasHeader(Stomp.Headers.ACCEPT_VERSION))
{ {
response.addHeader(Stomp.Headers.Connected.VERSION, "1.0"); response.addHeader(Stomp.Headers.Connected.VERSION, StompVersions.V1_0.toString());
} }
response.addHeader(Stomp.Headers.Connected.SESSION, connection.getID().toString()); response.addHeader(Stomp.Headers.Connected.SESSION, connection.getID().toString());

View File

@ -787,12 +787,12 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler implements
headers.put(headerName, headerValue); headers.put(headerName, headerValue);
if (headerName.equals(CONTENT_LENGTH_HEADER_NAME)) if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
{ {
contentLength = Integer.parseInt(headerValue); contentLength = Integer.parseInt(headerValue);
} }
if (headerName.equals(CONTENT_TYPE_HEADER_NAME)) if (headerName.equals(Stomp.Headers.CONTENT_TYPE))
{ {
contentType = headerValue; contentType = headerValue;
} }

View File

@ -248,12 +248,12 @@ public class StompFrameHandlerV12 extends StompFrameHandlerV11 implements FrameE
headers.put(headerName, headerValue); headers.put(headerName, headerValue);
} }
if (headerName.equals(CONTENT_LENGTH_HEADER_NAME)) if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
{ {
contentLength = Integer.parseInt(headerValue); contentLength = Integer.parseInt(headerValue);
} }
if (headerName.equals(CONTENT_TYPE_HEADER_NAME)) if (headerName.equals(Stomp.Headers.CONTENT_TYPE))
{ {
contentType = headerValue; contentType = headerValue;
} }