activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: Use Stomp constants more rather than magic strings
Date Thu, 09 Jul 2015 14:33:50 GMT
Use Stomp constants more rather than magic strings


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7c41bac6
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7c41bac6
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7c41bac6

Branch: refs/heads/master
Commit: 7c41bac6b6b0e70aa09c7ee6cf19817b1a519745
Parents: 0e3b68d
Author: Ville Skyttä <ville.skytta@iki.fi>
Authored: Thu Jul 9 11:11:06 2015 +0300
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Thu Jul 9 10:33:43 2015 -0400

----------------------------------------------------------------------
 .../protocol/stomp/ActiveMQStompException.java  |  6 ++--
 .../core/protocol/stomp/StompConnection.java    | 10 +++---
 .../core/protocol/stomp/StompDecoder.java       | 36 +++++++++-----------
 .../protocol/stomp/StompProtocolManager.java    |  2 +-
 .../stomp/v10/StompFrameHandlerV10.java         |  3 +-
 .../stomp/v11/StompFrameHandlerV11.java         |  4 +--
 .../stomp/v12/StompFrameHandlerV12.java         |  4 +--
 7 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/ActiveMQStompException.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/ActiveMQStompException.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/ActiveMQStompException.java
index 471bc8b..a42e9d4 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/ActiveMQStompException.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/ActiveMQStompException.java
@@ -77,13 +77,13 @@ public class ActiveMQStompException extends Exception
       StompFrame frame = null;
       if (handler == null)
       {
-         frame = new StompFrame("ERROR");
+         frame = new StompFrame(Stomp.Responses.ERROR);
       }
       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)
       {
          frame.addHeader(header.key, header.val);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
index 9795574..b8e26ee 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
@@ -475,15 +475,15 @@ public final class StompConnection implements RemotingConnection
             requestVersions.add(tokenizer.nextToken());
          }
 
-         if (requestVersions.contains("1.2"))
+         if (requestVersions.contains(StompVersions.V1_2.toString()))
          {
             this.version = StompVersions.V1_2;
          }
-         else if (requestVersions.contains("1.1"))
+         else if (requestVersions.contains(StompVersions.V1_1.toString()))
          {
             this.version = StompVersions.V1_1;
          }
-         else if (requestVersions.contains("1.0"))
+         else if (requestVersions.contains(StompVersions.V1_0.toString()))
          {
             this.version = StompVersions.V1_0;
          }
@@ -491,8 +491,8 @@ public final class StompConnection implements RemotingConnection
          {
             //not a supported version!
             ActiveMQStompException error = BUNDLE.versionNotSupported(acceptVersion);
-            error.addHeader("version", acceptVersion);
-            error.addHeader("content-type", "text/plain");
+            error.addHeader(Stomp.Headers.Error.VERSION, acceptVersion);
+            error.addHeader(Stomp.Headers.CONTENT_TYPE, "text/plain");
             error.setBody("Supported protocol version are " + manager.getSupportedVersionsAsString());
             error.setDisconnect(true);
             throw error;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java
index 453e466..cd2bc3b 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompDecoder.java
@@ -27,66 +27,66 @@ public class StompDecoder
 {
    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 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 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 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 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 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 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 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 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 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 String COMMAND_UNSUBSCRIBE = "UNSUBSCRIBE";
+   public static final String COMMAND_UNSUBSCRIBE = Stomp.Commands.UNSUBSCRIBE;
 
    public static final int COMMAND_UNSUBSCRIBE_LENGTH = COMMAND_UNSUBSCRIBE.length();
 
    /**
     * * 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 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 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 String COMMAND_RECEIPT = "RECEIPT";
+   public static final String COMMAND_RECEIPT = Stomp.Responses.RECEIPT;
 
    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 String CONTENT_TYPE_HEADER_NAME = "content-type";
-
-   public static final String CONTENT_LENGTH_HEADER_NAME = "content-length";
-
    public byte[] workingBuffer = new byte[1024];
 
    public int pos;
@@ -346,7 +342,7 @@ public class StompDecoder
 
                headers.put(headerName, headerValue);
 
-               if (headerName.equals(CONTENT_LENGTH_HEADER_NAME))
+               if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
                {
                   contentLength = Integer.parseInt(headerValue.toString());
                }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompProtocolManager.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompProtocolManager.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompProtocolManager.java
index fd06f92..7728a3f 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompProtocolManager.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompProtocolManager.java
@@ -379,7 +379,7 @@ class StompProtocolManager implements ProtocolManager<StompFrameInterceptor>,
No
 
    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()

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v10/StompFrameHandlerV10.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v10/StompFrameHandlerV10.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v10/StompFrameHandlerV10.java
index ee65243..7cbf771 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v10/StompFrameHandlerV10.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v10/StompFrameHandlerV10.java
@@ -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.StompDecoder;
 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.server.ActiveMQServerLogger;
 
@@ -58,7 +59,7 @@ public class StompFrameHandlerV10 extends VersionedStompFrameHandler implements
 
          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());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v11/StompFrameHandlerV11.java
----------------------------------------------------------------------
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 86b40b0..5384277 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
@@ -787,12 +787,12 @@ public class StompFrameHandlerV11 extends VersionedStompFrameHandler
implements
 
                   headers.put(headerName, headerValue);
 
-                  if (headerName.equals(CONTENT_LENGTH_HEADER_NAME))
+                  if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
                   {
                      contentLength = Integer.parseInt(headerValue);
                   }
 
-                  if (headerName.equals(CONTENT_TYPE_HEADER_NAME))
+                  if (headerName.equals(Stomp.Headers.CONTENT_TYPE))
                   {
                      contentType = headerValue;
                   }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7c41bac6/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameHandlerV12.java
----------------------------------------------------------------------
diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameHandlerV12.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameHandlerV12.java
index 08f57d2..ca9b6fe 100644
--- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameHandlerV12.java
+++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/v12/StompFrameHandlerV12.java
@@ -248,12 +248,12 @@ public class StompFrameHandlerV12 extends StompFrameHandlerV11 implements
FrameE
                      headers.put(headerName, headerValue);
                   }
 
-                  if (headerName.equals(CONTENT_LENGTH_HEADER_NAME))
+                  if (headerName.equals(Stomp.Headers.CONTENT_LENGTH))
                   {
                      contentLength = Integer.parseInt(headerValue);
                   }
 
-                  if (headerName.equals(CONTENT_TYPE_HEADER_NAME))
+                  if (headerName.equals(Stomp.Headers.CONTENT_TYPE))
                   {
                      contentType = headerValue;
                   }


Mime
View raw message