diff --git a/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeEncoder.java b/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeEncoder.java index fd99f7b1cb..7b8dc4dcdf 100644 --- a/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeEncoder.java +++ b/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeEncoder.java @@ -34,9 +34,14 @@ public class StompSubframeEncoder extends MessageToMessageEncoder if (msg instanceof StompFrame) { StompFrame frame = (StompFrame) msg; ByteBuf frameBuf = encodeFrame(frame, ctx); - out.add(frameBuf); - ByteBuf contentBuf = encodeContent(frame, ctx); - out.add(contentBuf); + if (frame.content().isReadable()) { + out.add(frameBuf); + ByteBuf contentBuf = encodeContent(frame, ctx); + out.add(contentBuf); + } else { + frameBuf.writeByte(StompConstants.NUL); + out.add(frameBuf); + } } else if (msg instanceof StompHeadersSubframe) { StompHeadersSubframe frame = (StompHeadersSubframe) msg; ByteBuf buf = encodeFrame(frame, ctx); diff --git a/codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeEncoderTest.java b/codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeEncoderTest.java index 17d4ee684a..c792f73b34 100644 --- a/codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeEncoderTest.java +++ b/codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeEncoderTest.java @@ -83,4 +83,18 @@ public class StompSubframeEncoderTest { assertTrue(fullFrame.release()); } + @Test + public void testOneBufferForStompFrameWithEmptyContent() { + StompFrame connectedFrame = new DefaultStompFrame(StompCommand.CONNECTED); + connectedFrame.headers().set(StompHeaders.VERSION, "1.2"); + + assertTrue(channel.writeOutbound(connectedFrame)); + + ByteBuf stompBuffer = channel.readOutbound(); + + assertNotNull(stompBuffer); + assertNull(channel.readOutbound()); + assertEquals("CONNECTED\nversion:1.2\n\n\0", stompBuffer.toString(CharsetUtil.UTF_8)); + assertTrue(stompBuffer.release()); + } }