diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java index b5982b28d2d..bc9ab1bab05 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageOutputStream.java @@ -153,6 +153,9 @@ public class MessageOutputStream extends OutputStream // Any flush after the first will be a CONTINUATION frame. frame.setIsContinuation(); + // Buffer has been sent, buffer should have been consumed + assert buffer.remaining() == 0; + BufferUtil.flipToFill(buffer); } } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java index 43dfe4145b6..ae9d6515431 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/message/MessageOutputStreamTest.java @@ -18,11 +18,6 @@ package org.eclipse.jetty.websocket.common.message; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; - -import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; @@ -33,7 +28,6 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames; import org.eclipse.jetty.websocket.common.WebSocketSession; import org.eclipse.jetty.websocket.common.io.FramePipes; -import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection; import org.eclipse.jetty.websocket.common.io.LocalWebSocketSession; import org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope; import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; @@ -45,6 +39,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + public class MessageOutputStreamTest { private static final Logger LOG = Log.getLogger(MessageOutputStreamTest.class); @@ -83,6 +81,7 @@ public class MessageOutputStreamTest remoteSocket = new TrackingSocket("remote"); WebSocketSession remoteSession = new LocalWebSocketSession(containerScope,testname,remoteSocket); OutgoingFrames socketPipe = FramePipes.to(remoteSession); + remoteSession.open(); // Local Session TrackingSocket localSocket = new TrackingSocket("local"); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/OutgoingFramesCapture.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/OutgoingFramesCapture.java index ba406f89da7..03d14906ad3 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/OutgoingFramesCapture.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/OutgoingFramesCapture.java @@ -18,9 +18,7 @@ package org.eclipse.jetty.websocket.common.test; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.is; - +import java.nio.ByteBuffer; import java.util.LinkedList; import org.eclipse.jetty.util.BufferUtil; @@ -32,6 +30,9 @@ import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.junit.Assert; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; + public class OutgoingFramesCapture implements OutgoingFrames { private LinkedList frames = new LinkedList<>(); @@ -89,6 +90,10 @@ public class OutgoingFramesCapture implements OutgoingFrames public void outgoingFrame(Frame frame, WriteCallback callback, BatchMode batchMode) { frames.add(WebSocketFrame.copy(frame)); + // Consume bytes + ByteBuffer payload = frame.getPayload(); + payload.position(payload.limit()); + // notify callback if (callback != null) { callback.writeSuccess();