You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2012/02/20 15:58:24 UTC
svn commit: r1291299 - in /activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/transport/stomp/
main/java/org/apache/activemq/util/
test/java/org/apache/activemq/transport/stomp/
Author: gtully
Date: Mon Feb 20 14:58:23 2012
New Revision: 1291299
URL: http://svn.apache.org/viewvc?rev=1291299&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3729 - Stomp wireformat and codec block on telnet CRLF CRLF header separator. fix up telnet support, additional test, impacts https://issues.apache.org/jira/browse/AMQ-2583 and https://issues.apache.org/jira/browse/AMQ-3449
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java (with props)
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ByteArrayOutputStream.java
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java?rev=1291299&r1=1291298&r2=1291299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompCodec.java Mon Feb 20 14:58:23 2012
@@ -25,6 +25,7 @@ import java.util.HashMap;
public class StompCodec {
+ final static byte[] crlfcrlf = new byte[]{'\r','\n','\r','\n'};
TcpTransport transport;
ByteArrayOutputStream currentCommand = new ByteArrayOutputStream();
@@ -52,7 +53,7 @@ public class StompCodec {
if (!processedHeaders) {
currentCommand.write(b);
// end of headers section, parse action and header
- if (previousByte == '\n' && b == '\n') {
+ if (b == '\n' && (previousByte == '\n' || currentCommand.endsWith(crlfcrlf))) {
if (transport.getWireFormat() instanceof StompWireFormat) {
DataByteArrayInputStream data = new DataByteArrayInputStream(currentCommand.toByteArray());
action = ((StompWireFormat)transport.getWireFormat()).parseAction(data);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java?rev=1291299&r1=1291298&r2=1291299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompWireFormat.java Mon Feb 20 14:58:23 2012
@@ -178,7 +178,7 @@ public class StompWireFormat implements
HashMap<String, String> headers = new HashMap<String, String>(25);
while (true) {
ByteSequence line = readHeaderLine(in, MAX_HEADER_LENGTH, "The maximum header length was exceeded");
- if (line != null && line.length > 0) {
+ if (line != null && line.length > 1) {
if (headers.size() > MAX_HEADERS) {
throw new ProtocolException("The maximum number of headers was exceeded", true);
Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ByteArrayOutputStream.java?rev=1291299&r1=1291298&r2=1291299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ByteArrayOutputStream.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/ByteArrayOutputStream.java Mon Feb 20 14:58:23 2012
@@ -52,7 +52,7 @@ public class ByteArrayOutputStream exten
/**
* Ensures the the buffer has at least the minimumCapacity specified.
- * @param i
+ * @param minimumCapacity
*/
private void checkCapacity(int minimumCapacity) {
if (minimumCapacity > buffer.length) {
@@ -79,4 +79,18 @@ public class ByteArrayOutputStream exten
public int size() {
return size;
}
+
+ public boolean endsWith(final byte[] array) {
+ int i = 0;
+ int start = size - array.length;
+ if (start < 0) {
+ return false;
+ }
+ while (start < size) {
+ if (buffer[start++] != array[i++]) {
+ return false;
+ }
+ }
+ return true;
+ }
}
Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java?rev=1291299&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java Mon Feb 20 14:58:23 2012
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.activemq.transport.stomp;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.URI;
+import org.apache.activemq.CombinationTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StompTelnetTest extends CombinationTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(StompTelnetTest.class);
+
+ private BrokerService broker;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ broker = new BrokerService();
+ broker.setPersistent(false);
+ broker.addConnector("stomp://localhost:0");
+ broker.addConnector("stomp+nio://localhost:0");
+
+ broker.start();
+ broker.waitUntilStarted();
+ }
+
+ public void testCRLF() throws Exception {
+
+ for (TransportConnector connector : broker.getTransportConnectors()) {
+ LOG.info("try: " + connector.getConnectUri());
+
+ StompConnection stompConnection = new StompConnection();
+ stompConnection.open(createSocket(connector.getConnectUri()));
+ String frame = "CONNECT\r\n\r\n" + Stomp.NULL;
+ stompConnection.sendFrame(frame);
+
+ frame = stompConnection.receiveFrame();
+ LOG.info("response from: " + connector.getConnectUri() + ", " + frame);
+ assertTrue(frame.startsWith("CONNECTED"));
+ stompConnection.close();
+ }
+ }
+
+ protected Socket createSocket(URI connectUri) throws IOException {
+ return new Socket("127.0.0.1", connectUri.getPort());
+ }
+
+ protected String getQueueName() {
+ return getClass().getName() + "." + getName();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ broker.stop();
+ broker.waitUntilStopped();
+ }
+
+}
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTelnetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date