This is an automated email from the ASF dual-hosted git repository.

cshannon pushed a commit to branch activemq-6.1.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-6.1.x by this push:
     new 88c76c00df AMQ-9658 - Improve auto+nio+ssl transport initialization 
for amqp
88c76c00df is described below

commit 88c76c00df15553edf5266ec18a1ea1be80c23d1
Author: Christopher L. Shannon <[email protected]>
AuthorDate: Wed Feb 5 19:52:22 2025 -0500

    AMQ-9658 - Improve auto+nio+ssl transport initialization for amqp
    
    This makes small fix to ensure that the full initialization
    buffer will always be entirely read and processed when using
    the auto+nio+ssl transport with amqp. Previously the code assumed
    only 8 bytes would ever exist (which should be the case under normal
    circumstances) but now it will handle any extra bytes if a client sent
    more.
    
    (cherry picked from commit 526e83b3cb06ed099ef239b7b7c9d0d252f17a0f)
---
 .../transport/amqp/AmqpNioSslTransport.java        | 37 ++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git 
a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
 
b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
index fb19866450..67446e5695 100644
--- 
a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
+++ 
b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java
@@ -54,6 +54,22 @@ public class AmqpNioSslTransport extends NIOSSLTransport {
     @Override
     protected void initializeStreams() throws IOException {
         super.initializeStreams();
+        if (initBuffer != null) {
+            initBuffer.buffer.flip();
+            // If we are processing the initial buffer from the auto transport,
+            // then process first. This generally should only have 8 bytes from
+            // the initial read
+            if (initBuffer.buffer.hasRemaining()) {
+                receiveCounter.addAndGet(initBuffer.readSize);
+                try {
+                    // one call is all that is needed to consume all data
+                    processCommand(initBuffer.buffer);
+                } catch (Exception e) {
+                    throw new IOException(e);
+                }
+                initBuffer.buffer.clear();
+            }
+        }
         if (inputBuffer.position() != 0 && inputBuffer.hasRemaining()) {
             serviceRead();
         }
@@ -76,23 +92,4 @@ public class AmqpNioSslTransport extends NIOSSLTransport {
         super.doInit();
     }
 
-    @Override
-    protected int secureRead(ByteBuffer plain) throws Exception {
-        if (initBuffer != null) {
-            initBuffer.buffer.flip();
-            if (initBuffer.buffer.hasRemaining()) {
-                plain.flip();
-                for (int i =0; i < 8; i++) {
-                    plain.put(initBuffer.buffer.get());
-                }
-                plain.flip();
-                processCommand(plain);
-                initBuffer.buffer.clear();
-                return 8;
-            }
-        }
-        return super.secureRead(plain);
-    }
-
-
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to