Author: gaohoward
Date: 2011-08-31 00:46:11 -0400 (Wed, 31 Aug 2011)
New Revision: 11257
Added:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/HornetQStompException.java
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompVersions.java
Modified:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/Stomp.java
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompProtocolManager.java
Log:
stomp 1.1 impl changes
Added:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/HornetQStompException.java
===================================================================
---
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/HornetQStompException.java
(rev 0)
+++
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/HornetQStompException.java 2011-08-31
04:46:11 UTC (rev 11257)
@@ -0,0 +1,49 @@
+package org.hornetq.core.protocol.stomp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class HornetQStompException extends Exception {
+
+ private static final long serialVersionUID = -274452327574950068L;
+
+ private List<Header> headers = new ArrayList<Header>(10);
+ private String body;
+
+ public HornetQStompException(String msg)
+ {
+ super(msg);
+ }
+
+ public HornetQStompException(String msg, Throwable t)
+ {
+ super(msg, t);
+ }
+
+ public HornetQStompException(Throwable t)
+ {
+ super(t);
+ }
+
+ public void addHeader(String header, String value)
+ {
+ headers.add(new Header(header, value));
+ }
+
+ public void setBody(String body)
+ {
+ this.body = body;
+ }
+
+ private class Header
+ {
+ public String key;
+ public String val;
+
+ public Header(String key, String val)
+ {
+ this.key = key;
+ this.val = val;
+ }
+ }
+}
Modified:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/Stomp.java
===================================================================
---
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/Stomp.java 2011-08-31
04:43:40 UTC (rev 11256)
+++
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/Stomp.java 2011-08-31
04:46:11 UTC (rev 11257)
@@ -159,6 +159,10 @@
String CLIENT_ID = "client-id";
String REQUEST_ID = "request-id";
+
+ //1.1
+ String ACCEPT_VERSION = "accept-version";
+ String HOST = "host";
}
public interface Error
Modified:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java
===================================================================
---
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java 2011-08-31
04:43:40 UTC (rev 11256)
+++
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompConnection.java 2011-08-31
04:46:11 UTC (rev 11257)
@@ -15,7 +15,10 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
import java.util.concurrent.CopyOnWriteArrayList;
import org.hornetq.api.core.HornetQBuffer;
@@ -64,6 +67,8 @@
private final Object failLock = new Object();
private volatile boolean dataReceived;
+
+ private StompVersions version = StompVersions.V1_0;
public StompDecoder getDecoder()
{
@@ -349,4 +354,61 @@
}
}
+ /*
+ * accept-version value takes form of "v1,v2,v3..."
+ * we need to return the highest supported version
+ */
+ public void negotiateVersion(String acceptVersion) throws HornetQStompException
+ {
+ if (acceptVersion == null)
+ {
+ this.version = StompVersions.V1_0;
+ }
+ else
+ {
+ Set<String> requestVersions = new HashSet<String>();
+ StringTokenizer tokenizer = new StringTokenizer(acceptVersion, ",");
+ while (tokenizer.hasMoreTokens())
+ {
+ requestVersions.add(tokenizer.nextToken());
+ }
+
+ if (requestVersions.contains("1.1"))
+ {
+ this.version = StompVersions.V1_1;
+ }
+ else if (requestVersions.contains("1.0"))
+ {
+ this.version = StompVersions.V1_0;
+ }
+ else
+ {
+ //not a supported version!
+ HornetQStompException error = new HornetQStompException("Stomp versions
not supported: " + acceptVersion);
+ error.addHeader("version", acceptVersion);
+ error.addHeader("content-type", "text/plain");
+ error.setBody("Supported protocol version are " +
manager.getSupportedVersionsAsString());
+ throw error;
+ }
+ }
+ }
+
+ //reject if the host doesn't match
+ public void setHost(String host) throws HornetQStompException
+ {
+ if (host == null)
+ {
+ HornetQStompException error = new HornetQStompException("Header host is
null");
+ error.setBody("Cannot accept null as host");
+ throw error;
+ }
+
+ String localHost = manager.getVirtualHostName();
+ if (!host.equals(localHost))
+ {
+ HornetQStompException error = new HornetQStompException("Header host
doesn't match server host");
+ error.setBody("host " + host + " doesn't match server host
name");
+ throw error;
+ }
+ }
}
Modified:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompProtocolManager.java
===================================================================
---
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-08-31
04:43:40 UTC (rev 11256)
+++
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompProtocolManager.java 2011-08-31
04:46:11 UTC (rev 11257)
@@ -577,6 +577,9 @@
String passcode = (String)headers.get(Stomp.Headers.Connect.PASSCODE);
String clientID = (String)headers.get(Stomp.Headers.Connect.CLIENT_ID);
String requestID = (String)headers.get(Stomp.Headers.Connect.REQUEST_ID);
+ //since 1.1
+ String acceptVersion = (String)headers.get(Stomp.Headers.Connect.ACCEPT_VERSION);
+ String host = (String)headers.get(Stomp.Headers.Connect.HOST);
HornetQSecurityManager sm = server.getSecurityManager();
@@ -586,6 +589,8 @@
sm.validateUser(login, passcode);
}
+ connection.negotiateVersion(acceptVersion);
+ connection.setHost(host);
connection.setLogin(login);
connection.setPasscode(passcode);
connection.setClientID(clientID);
@@ -665,5 +670,16 @@
}
});
}
+
+ public String getSupportedVersionsAsString()
+ {
+ return "v1.0 v1.1";
+ }
+
+ public String getVirtualHostName()
+ {
+ return "hornetq";
+ }
+
// Inner classes -------------------------------------------------
}
Added:
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompVersions.java
===================================================================
---
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompVersions.java
(rev 0)
+++
branches/STOMP11/hornetq-core/src/main/java/org/hornetq/core/protocol/stomp/StompVersions.java 2011-08-31
04:46:11 UTC (rev 11257)
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.protocol.stomp;
+
+/**
+ * Stomp Spec Versions
+ *
+ * @author <a href="mailto:hgao@redhat.com">Howard Gao</a>
+ *
+ */
+public enum StompVersions
+{
+ V1_0,
+ V1_1
+}