diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/CloseTrackingEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/CloseTrackingEndpoint.java index 43829920e37..b8a126d4c26 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/CloseTrackingEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/CloseTrackingEndpoint.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.tests; import java.lang.reflect.Field; +import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -51,6 +52,7 @@ public class CloseTrackingEndpoint extends WebSocketAdapter public CountDownLatch errorLatch = new CountDownLatch(1); public LinkedBlockingQueue messageQueue = new LinkedBlockingQueue<>(); + public LinkedBlockingQueue binaryMessageQueue = new LinkedBlockingQueue<>(); public AtomicReference error = new AtomicReference<>(); public void assertReceivedCloseEvent(int clientTimeoutMs, Matcher statusCodeMatcher) @@ -110,6 +112,13 @@ public class CloseTrackingEndpoint extends WebSocketAdapter messageQueue.offer(message); } + @Override + public void onWebSocketBinary(byte[] payload, int offset, int len) + { + LOG.debug("onWebSocketBinary({},offset,len)", payload, offset, len); + binaryMessageQueue.offer(ByteBuffer.wrap(payload, offset, len)); + } + public EndPoint getEndPoint() throws Exception { Session session = getSession(); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java index ce2d9f651af..a0b8ee62c02 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/EchoSocket.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.tests; import java.io.IOException; +import java.nio.ByteBuffer; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; @@ -33,4 +34,10 @@ public class EchoSocket { session.getRemote().sendString(msg); } + + @OnWebSocketMessage + public void onBinaryMessage(Session session, byte[] data, int offset, int len) throws IOException + { + session.getRemote().sendBytes(ByteBuffer.wrap(data, offset, len)); + } } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java index 611a06e6c55..7863c93744a 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/WebSocketClientTest.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.tests.client; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; +import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; @@ -232,13 +233,23 @@ public class WebSocketClientTest remote.sendPartialString(" ", false); remote.sendPartialString("World", true); - remote.sendPartialBytes(BufferUtil.toBuffer("It's a big enough umbrella, "), false); - remote.sendPartialBytes(BufferUtil.toBuffer("but it's always me that "), false); - remote.sendPartialBytes(BufferUtil.toBuffer("ends up getting wet."), true); + String[] parts = { + "The difference between the right word ", + "and the almost right word is the difference ", + "between lightning and a lightning bug." + }; + + remote.sendPartialBytes(BufferUtil.toBuffer(parts[0]), false); + remote.sendPartialBytes(BufferUtil.toBuffer(parts[1]), false); + remote.sendPartialBytes(BufferUtil.toBuffer(parts[2]), true); // wait for response from server String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS); assertThat("Message", received, containsString("Hello World")); + + ByteBuffer bufReceived = cliSock.binaryMessageQueue.poll(5, TimeUnit.SECONDS); + received = BufferUtil.toUTF8String(bufReceived.slice()); + assertThat("Message", received, containsString(parts[0] + parts[1] + parts[2])); } } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java index b6587f7f3b0..1aa131d54b9 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FrameListenerTest.java @@ -40,9 +40,6 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.common.OpCode; import org.eclipse.jetty.websocket.common.WebSocketSession; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; -import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; -import org.eclipse.jetty.websocket.servlet.WebSocketCreator; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.eclipse.jetty.websocket.tests.CloseTrackingEndpoint; @@ -57,7 +54,7 @@ import static org.hamcrest.Matchers.is; public class FrameListenerTest { private Server server; - private FrameCreator frameCreator; + private FrameEndpoint serverEndpoint; private WebSocketClient client; @BeforeEach @@ -77,8 +74,8 @@ public class FrameListenerTest public void configure(WebSocketServletFactory factory) { factory.getPolicy().setIdleTimeout(SECONDS.toMillis(2)); - frameCreator = new FrameCreator(); - factory.setCreator(frameCreator); + serverEndpoint = new FrameEndpoint(); + factory.setCreator((req, resp) -> serverEndpoint); } }); context.addServlet(closeEndpoint, "/ws"); @@ -138,8 +135,6 @@ public class FrameListenerTest clientRemote.sendPartialString(" ", false); clientRemote.sendPartialString("world", true); - FrameEndpoint serverEndpoint = frameCreator.frameEndpoint; - String event = serverEndpoint.frameEvents.poll(5, SECONDS); assertThat("Event", event, is("FRAME[TEXT,fin=false,payload=hello,len=5]")); event = serverEndpoint.frameEvents.poll(5, SECONDS); @@ -153,18 +148,6 @@ public class FrameListenerTest } } - public static class FrameCreator implements WebSocketCreator - { - public FrameEndpoint frameEndpoint; - - @Override - public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) - { - frameEndpoint = new FrameEndpoint(); - return frameEndpoint; - } - } - public static class FrameEndpoint implements WebSocketFrameListener { public Session session; diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyListenerEventDriver.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyListenerEventDriver.java index 1d86a5a2ad5..1f4fa3b2e62 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyListenerEventDriver.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/events/JettyListenerEventDriver.java @@ -250,12 +250,6 @@ public class JettyListenerEventDriver extends AbstractEventDriver return; } - super.onContinuationFrame(buffer, fin); - } - - @Override - public void onContinuationFrame(ByteBuffer buffer, boolean fin) throws IOException - { if (listener instanceof WebSocketListener) { super.onContinuationFrame(buffer, fin);