Skip to content

Commit 526e83b

Browse files
committed
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.
1 parent d9e89f4 commit 526e83b

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpNioSslTransport.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ public AmqpNioSslTransport(WireFormat wireFormat, Socket socket,
5454
@Override
5555
protected void initializeStreams() throws IOException {
5656
super.initializeStreams();
57+
if (initBuffer != null) {
58+
initBuffer.buffer.flip();
59+
// If we are processing the initial buffer from the auto transport,
60+
// then process first. This generally should only have 8 bytes from
61+
// the initial read
62+
if (initBuffer.buffer.hasRemaining()) {
63+
receiveCounter.addAndGet(initBuffer.readSize);
64+
try {
65+
// one call is all that is needed to consume all data
66+
processCommand(initBuffer.buffer);
67+
} catch (Exception e) {
68+
throw new IOException(e);
69+
}
70+
initBuffer.buffer.clear();
71+
}
72+
}
5773
if (inputBuffer.position() != 0 && inputBuffer.hasRemaining()) {
5874
serviceRead();
5975
}
@@ -76,23 +92,4 @@ protected void doInit() throws Exception {
7692
super.doInit();
7793
}
7894

79-
@Override
80-
protected int secureRead(ByteBuffer plain) throws Exception {
81-
if (initBuffer != null) {
82-
initBuffer.buffer.flip();
83-
if (initBuffer.buffer.hasRemaining()) {
84-
plain.flip();
85-
for (int i =0; i < 8; i++) {
86-
plain.put(initBuffer.buffer.get());
87-
}
88-
plain.flip();
89-
processCommand(plain);
90-
initBuffer.buffer.clear();
91-
return 8;
92-
}
93-
}
94-
return super.secureRead(plain);
95-
}
96-
97-
98-
}
95+
}

0 commit comments

Comments
 (0)