Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EB79B9083 for ; Mon, 20 Feb 2012 14:58:45 +0000 (UTC) Received: (qmail 85815 invoked by uid 500); 20 Feb 2012 14:58:45 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 85790 invoked by uid 500); 20 Feb 2012 14:58:45 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 85783 invoked by uid 99); 20 Feb 2012 14:58:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2012 14:58:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2012 14:58:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 81D4623888E7 for ; Mon, 20 Feb 2012 14:58:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Mon, 20 Feb 2012 14:58:24 -0000 To: commits@activemq.apache.org From: gtully@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120220145824.81D4623888E7@eris.apache.org> 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 headers = new HashMap(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