diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java index f980f1cd3e6..bc097cd5084 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/client/SessionAddMessageHandlerTest.java @@ -41,10 +41,9 @@ import org.eclipse.jetty.websocket.javax.common.UpgradeRequest; import org.eclipse.jetty.websocket.javax.common.UpgradeRequestAdapter; import org.eclipse.jetty.websocket.javax.tests.MessageType; import org.eclipse.jetty.websocket.javax.tests.SessionMatchers; -import org.eclipse.jetty.websocket.javax.tests.handlers.ByteArrayWholeHandler; -import org.eclipse.jetty.websocket.javax.tests.handlers.ByteBufferPartialHandler; +import org.eclipse.jetty.websocket.javax.tests.handlers.BinaryHandlers; import org.eclipse.jetty.websocket.javax.tests.handlers.LongMessageHandler; -import org.eclipse.jetty.websocket.javax.tests.handlers.StringWholeHandler; +import org.eclipse.jetty.websocket.javax.tests.handlers.TextHandlers; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -93,7 +92,7 @@ public class SessionAddMessageHandlerTest @Test public void testMessageHandlerBinary() { - session.addMessageHandler(new ByteBufferPartialHandler()); + session.addMessageHandler(new BinaryHandlers.ByteBufferPartialHandler()); assertThat("session", session, SessionMatchers.isMessageHandlerTypeRegistered(MessageType.BINARY)); assertThat("session", session, Matchers.not(SessionMatchers.isMessageHandlerTypeRegistered(MessageType.TEXT))); assertThat("session", session, Matchers.not(SessionMatchers.isMessageHandlerTypeRegistered(MessageType.PONG))); @@ -102,7 +101,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.BINARY), - instanceOf(ByteBufferPartialHandler.class) + instanceOf(BinaryHandlers.ByteBufferPartialHandler.class) ) ) ); @@ -111,8 +110,8 @@ public class SessionAddMessageHandlerTest @Test public void testMessageHandlerBoth() { - session.addMessageHandler(new StringWholeHandler()); - session.addMessageHandler(new ByteArrayWholeHandler()); + session.addMessageHandler(new TextHandlers.StringWholeHandler()); + session.addMessageHandler(new BinaryHandlers.ByteArrayWholeHandler()); assertThat("session", session, SessionMatchers.isMessageHandlerTypeRegistered(MessageType.BINARY)); assertThat("session", session, SessionMatchers.isMessageHandlerTypeRegistered(MessageType.TEXT)); assertThat("session", session, Matchers.not(SessionMatchers.isMessageHandlerTypeRegistered(MessageType.PONG))); @@ -121,7 +120,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.BINARY), - instanceOf(ByteArrayWholeHandler.class) + instanceOf(BinaryHandlers.ByteArrayWholeHandler.class) ) ) ); @@ -130,7 +129,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.TEXT), - instanceOf(StringWholeHandler.class) + instanceOf(TextHandlers.StringWholeHandler.class) ) ) ); @@ -139,9 +138,9 @@ public class SessionAddMessageHandlerTest @Test public void testMessageHandlerReplaceTextHandler() { - MessageHandler strHandler = new StringWholeHandler(); + MessageHandler strHandler = new TextHandlers.StringWholeHandler(); session.addMessageHandler(strHandler); // add a TEXT handler - session.addMessageHandler(new ByteArrayWholeHandler()); // add BINARY handler + session.addMessageHandler(new BinaryHandlers.ByteArrayWholeHandler()); // add BINARY handler session.removeMessageHandler(strHandler); // remove original TEXT handler session.addMessageHandler(new LongMessageHandler()); // add new TEXT handler @@ -154,7 +153,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.BINARY), - instanceOf(ByteArrayWholeHandler.class) + instanceOf(BinaryHandlers.ByteArrayWholeHandler.class) ) ) ); @@ -177,7 +176,7 @@ public class SessionAddMessageHandlerTest MessageHandler.Whole lamdaHandler = (msg) -> received.add(msg); session.addMessageHandler(String.class, lamdaHandler); // add a TEXT handler lambda - session.addMessageHandler(new ByteArrayWholeHandler()); // add BINARY handler + session.addMessageHandler(new BinaryHandlers.ByteArrayWholeHandler()); // add BINARY handler session.removeMessageHandler(lamdaHandler); // remove original TEXT handler assertThat("session", session, SessionMatchers.isMessageHandlerTypeRegistered(MessageType.BINARY)); @@ -189,7 +188,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.BINARY), - instanceOf(ByteArrayWholeHandler.class) + instanceOf(BinaryHandlers.ByteArrayWholeHandler.class) ) ) ); @@ -198,7 +197,7 @@ public class SessionAddMessageHandlerTest @Test public void testMessageHandlerText() { - session.addMessageHandler(new StringWholeHandler()); + session.addMessageHandler(new TextHandlers.StringWholeHandler()); assertThat("session", session, Matchers.not(SessionMatchers.isMessageHandlerTypeRegistered(MessageType.BINARY))); assertThat("session", session, SessionMatchers.isMessageHandlerTypeRegistered(MessageType.TEXT)); @@ -209,7 +208,7 @@ public class SessionAddMessageHandlerTest Matchers.hasItem( Matchers.allOf( SessionMatchers.isMessageHandlerType(session, MessageType.TEXT), - instanceOf(StringWholeHandler.class) + instanceOf(TextHandlers.StringWholeHandler.class) ) ) ); diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractAnnotatedHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractAnnotatedHandler.java new file mode 100644 index 00000000000..919461ccf22 --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractAnnotatedHandler.java @@ -0,0 +1,69 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests.handlers; + +import java.io.IOException; +import java.nio.ByteBuffer; +import javax.websocket.EndpointConfig; +import javax.websocket.OnError; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/") +public class AbstractAnnotatedHandler +{ + protected Session _session; + + @OnOpen + public void onOpen(Session session, EndpointConfig config) + { + _session = session; + } + + @OnError + public void onError(Session session, Throwable thr) + { + thr.printStackTrace(); + } + + public void sendText(String message, boolean last) + { + try + { + _session.getBasicRemote().sendText(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + public void sendBinary(ByteBuffer message, boolean last) + { + try + { + _session.getBasicRemote().sendBinary(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractHandler.java new file mode 100644 index 00000000000..5b31c930106 --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/AbstractHandler.java @@ -0,0 +1,68 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests.handlers; + +import java.io.IOException; +import java.nio.ByteBuffer; +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.Session; + +public class AbstractHandler extends Endpoint implements MessageHandler +{ + protected Session _session; + + @Override + public void onOpen(Session session, EndpointConfig config) + { + _session = session; + _session.addMessageHandler(this); + } + + @Override + public void onError(Session session, Throwable thr) + { + thr.printStackTrace(); + } + + public void sendText(String message, boolean last) + { + try + { + _session.getBasicRemote().sendText(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + public void sendBinary(ByteBuffer message, boolean last) + { + try + { + _session.getBasicRemote().sendBinary(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BaseMessageHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BaseMessageHandler.java index 1df281c32f4..c4452ff38f0 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BaseMessageHandler.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BaseMessageHandler.java @@ -20,11 +20,11 @@ package org.eclipse.jetty.websocket.javax.tests.handlers; import javax.websocket.MessageHandler; -public class BaseMessageHandler implements MessageHandler.Whole +public class BaseMessageHandler extends AbstractHandler implements MessageHandler.Whole { @Override public void onMessage(String message) { - // TODO Auto-generated method stub + sendText(message, true); } } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BinaryHandlers.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BinaryHandlers.java new file mode 100644 index 00000000000..de3be71ced2 --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/BinaryHandlers.java @@ -0,0 +1,169 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests.handlers; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.stream.Stream; +import javax.websocket.MessageHandler; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.IO; +import org.junit.jupiter.params.provider.Arguments; + +public class BinaryHandlers +{ + public static Stream getBinaryHandlers() + { + return Stream.of( + ByteArrayWholeHandler.class, + ByteArrayPartialHandler.class, + ByteBufferWholeHandler.class, + ByteBufferPartialHandler.class, + InputStreamWholeHandler.class, + AnnotatedByteBufferWholeHandler.class, + AnnotatedByteBufferPartialHandler.class, + AnnotatedByteArrayWholeHandler.class, + AnnotatedByteArrayPartialHandler.class, + AnnotatedInputStreamWholeHandler.class, + AnnotatedReverseArgumentPartialHandler.class + ).map(Arguments::of); + } + + public static class ByteArrayWholeHandler extends AbstractHandler implements MessageHandler.Whole + { + @Override + public void onMessage(byte[] message) + { + sendBinary(BufferUtil.toBuffer(message), true); + } + } + + public static class ByteArrayPartialHandler extends AbstractHandler implements MessageHandler.Partial + { + @Override + public void onMessage(byte[] partialMessage, boolean last) + { + sendBinary(BufferUtil.toBuffer(partialMessage), last); + } + } + + public static class ByteBufferWholeHandler extends AbstractHandler implements MessageHandler.Whole + { + @Override + public void onMessage(ByteBuffer message) + { + sendBinary(message, true); + } + } + + public static class ByteBufferPartialHandler extends AbstractHandler implements MessageHandler.Partial + { + @Override + public void onMessage(ByteBuffer partialMessage, boolean last) + { + sendBinary(partialMessage, last); + } + } + + public static class InputStreamWholeHandler extends AbstractHandler implements MessageHandler.Whole + { + @Override + public void onMessage(InputStream stream) + { + sendBinary(readBytes(stream), true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedByteBufferWholeHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(ByteBuffer message) + { + sendBinary(message, true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedByteBufferPartialHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(ByteBuffer message, boolean last) + { + sendBinary(message, last); + } + } + + @ServerEndpoint("/") + public static class AnnotatedByteArrayWholeHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(byte[] message) + { + sendBinary(BufferUtil.toBuffer(message), true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedByteArrayPartialHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(byte[] message, boolean last) + { + sendBinary(BufferUtil.toBuffer(message), last); + } + } + + @ServerEndpoint("/") + public static class AnnotatedInputStreamWholeHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(InputStream stream) + { + sendBinary(readBytes(stream), true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedReverseArgumentPartialHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(boolean last, Session session, byte[] message) + { + sendBinary(BufferUtil.toBuffer(message), last); + } + } + + private static ByteBuffer readBytes(InputStream stream) + { + try + { + return BufferUtil.toBuffer(IO.readBytes(stream)); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayPartialHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayPartialHandler.java deleted file mode 100644 index 32f9bc222e9..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayPartialHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import javax.websocket.MessageHandler; - -public class ByteArrayPartialHandler implements MessageHandler.Partial -{ - @Override - public void onMessage(byte[] partialMessage, boolean last) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayWholeHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayWholeHandler.java deleted file mode 100644 index 9c93050a373..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteArrayWholeHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import javax.websocket.MessageHandler; - -public class ByteArrayWholeHandler implements MessageHandler.Whole -{ - @Override - public void onMessage(byte[] message) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferPartialHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferPartialHandler.java deleted file mode 100644 index f203e9a0cd9..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferPartialHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import java.nio.ByteBuffer; -import javax.websocket.MessageHandler; - -public class ByteBufferPartialHandler implements MessageHandler.Partial -{ - @Override - public void onMessage(ByteBuffer partialMessage, boolean last) - { - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferWholeHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferWholeHandler.java deleted file mode 100644 index 4e350776b28..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ByteBufferWholeHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import java.nio.ByteBuffer; -import javax.websocket.MessageHandler; - -public class ByteBufferWholeHandler implements MessageHandler.Whole -{ - @Override - public void onMessage(ByteBuffer message) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ComboMessageHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ComboMessageHandler.java index a266e5a5c1d..9067fed437d 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ComboMessageHandler.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ComboMessageHandler.java @@ -24,17 +24,17 @@ import javax.websocket.MessageHandler; /** * A particularly annoying type of MessageHandler. One defining 2 implementations. */ -public class ComboMessageHandler implements MessageHandler.Whole, MessageHandler.Partial +public class ComboMessageHandler extends AbstractHandler implements MessageHandler.Whole, MessageHandler.Partial { @Override public void onMessage(ByteBuffer partialMessage, boolean last) { - // TODO Auto-generated method stub + sendBinary(partialMessage, last); } @Override public void onMessage(String message) { - // TODO Auto-generated method stub + sendText(message, true); } } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ExtendedMessageHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ExtendedMessageHandler.java index 9cb1f749d85..76c10824fc0 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ExtendedMessageHandler.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ExtendedMessageHandler.java @@ -26,6 +26,6 @@ public class ExtendedMessageHandler extends BaseMessageHandler implements Messag @Override public void onMessage(ByteBuffer partialMessage, boolean last) { - // TODO Auto-generated method stub + sendBinary(partialMessage, last); } } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/InputStreamWholeHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/InputStreamWholeHandler.java deleted file mode 100644 index 34c5af063b8..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/InputStreamWholeHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import java.io.InputStream; -import javax.websocket.MessageHandler; - -public class InputStreamWholeHandler implements MessageHandler.Whole -{ - @Override - public void onMessage(InputStream stream) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/LongMessageHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/LongMessageHandler.java index f1155847855..46d1500997c 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/LongMessageHandler.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/LongMessageHandler.java @@ -20,10 +20,11 @@ package org.eclipse.jetty.websocket.javax.tests.handlers; import javax.websocket.MessageHandler; -public class LongMessageHandler implements MessageHandler.Whole +public class LongMessageHandler extends AbstractHandler implements MessageHandler.Whole { @Override public void onMessage(Long message) { + sendText(message.toString(), true); } } diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/MessageHandlerTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/MessageHandlerTest.java new file mode 100644 index 00000000000..92a4db28a11 --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/MessageHandlerTest.java @@ -0,0 +1,167 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests.handlers; + +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.websocket.CloseReason; +import javax.websocket.ContainerProvider; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; +import javax.websocket.server.ServerEndpointConfig; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.component.LifeCycle; +import org.eclipse.jetty.websocket.javax.server.config.JavaxWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.javax.tests.EventSocket; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static javax.websocket.CloseReason.CloseCodes.NORMAL_CLOSURE; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MessageHandlerTest +{ + private Server server; + private URI serverUri; + private WebSocketContainer client; + + private static Stream getBinaryHandlers() + { + return Stream.concat(BinaryHandlers.getBinaryHandlers(), + Stream.of(ComboMessageHandler.class, ExtendedMessageHandler.class).map(Arguments::of)); + } + + private static Stream getTextHandlers() + { + return Stream.concat(TextHandlers.getTextHandlers(), + Stream.of(ComboMessageHandler.class, ExtendedMessageHandler.class).map(Arguments::of)); + } + + @BeforeEach + public void before() throws Exception + { + server = new Server(); + ServerConnector connector = new ServerConnector(server); + server.addConnector(connector); + + ServletContextHandler contextHandler = new ServletContextHandler(); + contextHandler.setContextPath("/"); + JavaxWebSocketServletContainerInitializer.configure(contextHandler, (context, container) -> + { + Stream argumentsStream = Stream.concat(getBinaryHandlers(), getTextHandlers()); + for (Class c : getClassListFromArguments(argumentsStream)) + { + container.addEndpoint(ServerEndpointConfig.Builder.create(c, "/" + c.getSimpleName()).build()); + } + + container.addEndpoint(ServerEndpointConfig.Builder.create(LongMessageHandler.class, + "/" + LongMessageHandler.class.getSimpleName()).build()); + }); + + server.setHandler(contextHandler); + server.start(); + serverUri = URI.create("ws://localhost:" + connector.getLocalPort() + "/"); + client = ContainerProvider.getWebSocketContainer(); + } + + @AfterEach + public void after() throws Exception + { + LifeCycle.stop(client); + server.stop(); + } + + @ParameterizedTest + @MethodSource("getBinaryHandlers") + public void testBinaryHandlers(Class clazz) throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + Session session = client.connectToServer(clientEndpoint, serverUri.resolve(clazz.getSimpleName())); + + // Send and receive echo on client. + ByteBuffer payload = BufferUtil.toBuffer("hello world"); + session.getBasicRemote().sendBinary(payload); + ByteBuffer echoMessage = clientEndpoint.binaryMessages.poll(5, TimeUnit.SECONDS); + assertThat(echoMessage, is(payload)); + + // Close normally. + session.close(new CloseReason(NORMAL_CLOSURE, "standard close")); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(NORMAL_CLOSURE)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("standard close")); + } + + @ParameterizedTest + @MethodSource("getTextHandlers") + public void testTextHandlers(Class clazz) throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + Session session = client.connectToServer(clientEndpoint, serverUri.resolve(clazz.getSimpleName())); + + // Send and receive echo on client. + String payload = "hello world"; + session.getBasicRemote().sendText(payload); + String echoMessage = clientEndpoint.textMessages.poll(5, TimeUnit.SECONDS); + assertThat(echoMessage, is(payload)); + + // Close normally. + session.close(new CloseReason(NORMAL_CLOSURE, "standard close")); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(NORMAL_CLOSURE)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("standard close")); + } + + @Test + public void testLongDecoderHandler() throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + Session session = client.connectToServer(clientEndpoint, serverUri.resolve(LongMessageHandler.class.getSimpleName())); + + // Send and receive echo on client. + String payload = Long.toString(Long.MAX_VALUE); + session.getBasicRemote().sendText(payload); + String echoMessage = clientEndpoint.textMessages.poll(5, TimeUnit.SECONDS); + assertThat(echoMessage, is(payload)); + + // Close normally. + session.close(new CloseReason(NORMAL_CLOSURE, "standard close")); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeReason.getCloseCode(), is(NORMAL_CLOSURE)); + assertThat(clientEndpoint.closeReason.getReasonPhrase(), is("standard close")); + } + + private List> getClassListFromArguments(Stream stream) + { + return stream.map(arguments -> (Class)arguments.get()[0]).collect(Collectors.toList()); + } +} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ReaderWholeHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ReaderWholeHandler.java deleted file mode 100644 index d8637aa7080..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/ReaderWholeHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import java.io.Reader; -import javax.websocket.MessageHandler; - -public class ReaderWholeHandler implements MessageHandler.Whole -{ - @Override - public void onMessage(Reader reader) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringPartialHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringPartialHandler.java deleted file mode 100644 index d614d282a1f..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringPartialHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import javax.websocket.MessageHandler; - -public class StringPartialHandler implements MessageHandler.Partial -{ - @Override - public void onMessage(String partialMessage, boolean last) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringWholeHandler.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringWholeHandler.java deleted file mode 100644 index 2f072ebc9bb..00000000000 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/StringWholeHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under -// the terms of the Eclipse Public License 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0 -// -// This Source Code may also be made available under the following -// Secondary Licenses when the conditions for such availability set -// forth in the Eclipse Public License, v. 2.0 are satisfied: -// the Apache License v2.0 which is available at -// https://www.apache.org/licenses/LICENSE-2.0 -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.websocket.javax.tests.handlers; - -import javax.websocket.MessageHandler; - -public class StringWholeHandler implements MessageHandler.Whole -{ - @Override - public void onMessage(String message) - { - // TODO Auto-generated method stub - } -} diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/TextHandlers.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/TextHandlers.java new file mode 100644 index 00000000000..b5badb5ec0a --- /dev/null +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/handlers/TextHandlers.java @@ -0,0 +1,125 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.javax.tests.handlers; + +import java.io.IOException; +import java.io.Reader; +import java.util.stream.Stream; +import javax.websocket.MessageHandler; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +import org.eclipse.jetty.util.IO; +import org.junit.jupiter.params.provider.Arguments; + +public class TextHandlers +{ + public static Stream getTextHandlers() + { + return Stream.of( + StringWholeHandler.class, + StringPartialHandler.class, + ReaderWholeHandler.class, + AnnotatedStringWholeHandler.class, + AnnotatedStringPartialHandler.class, + AnnotatedReaderHandler.class, + AnnotatedReverseArgumentsPartialHandler.class + ).map(Arguments::of); + } + + public static class StringWholeHandler extends AbstractHandler implements MessageHandler.Whole + { + @Override + public void onMessage(String message) + { + sendText(message, true); + } + } + + public static class StringPartialHandler extends AbstractHandler implements MessageHandler.Partial + { + @Override + public void onMessage(String partialMessage, boolean last) + { + sendText(partialMessage, last); + } + } + + public static class ReaderWholeHandler extends AbstractHandler implements MessageHandler.Whole + { + @Override + public void onMessage(Reader reader) + { + sendText(readString(reader), true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedStringWholeHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(String message) + { + sendText(message, true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedStringPartialHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(String message, boolean last) + { + sendText(message, last); + } + } + + @ServerEndpoint("/") + public static class AnnotatedReaderHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(Reader reader) + { + sendText(readString(reader), true); + } + } + + @ServerEndpoint("/") + public static class AnnotatedReverseArgumentsPartialHandler extends AbstractAnnotatedHandler + { + @OnMessage + public void onMessage(boolean last, String message, Session session) + { + sendText(message, last); + } + } + + private static String readString(Reader reader) + { + try + { + return IO.toString(reader); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnectionListener.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnectionListener.java index 7dac7419859..fd98cae3cfe 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnectionListener.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketConnectionListener.java @@ -31,7 +31,9 @@ public interface WebSocketConnectionListener * @param statusCode the close status code. (See {@link StatusCode}) * @param reason the optional reason for the close. */ - void onWebSocketClose(int statusCode, String reason); + default void onWebSocketClose(int statusCode, String reason) + { + } /** * A WebSocket {@link Session} has connected successfully and is ready to be used. @@ -40,7 +42,9 @@ public interface WebSocketConnectionListener * * @param session the websocket session. */ - void onWebSocketConnect(Session session); + default void onWebSocketConnect(Session session) + { + } /** * A WebSocket exception has occurred. @@ -53,5 +57,7 @@ public interface WebSocketConnectionListener * * @param cause the error that occurred. */ - void onWebSocketError(Throwable cause); + default void onWebSocketError(Throwable cause) + { + } } diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java index 8f11b97c375..ec3b059ceac 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketListener.java @@ -30,12 +30,16 @@ public interface WebSocketListener extends WebSocketConnectionListener * @param offset the offset in the payload array where the data starts * @param len the length of bytes in the payload */ - void onWebSocketBinary(byte[] payload, int offset, int len); + default void onWebSocketBinary(byte[] payload, int offset, int len) + { + } /** * A WebSocket Text frame was received. * * @param message the message */ - void onWebSocketText(String message); + default void onWebSocketText(String message) + { + } } diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPartialListener.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPartialListener.java index 26b4cc0a830..ec676b7387f 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPartialListener.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPartialListener.java @@ -35,7 +35,9 @@ public interface WebSocketPartialListener extends WebSocketConnectionListener * @param payload the binary message frame payload * @param fin true if this is the final frame, false otherwise */ - void onWebSocketPartialBinary(ByteBuffer payload, boolean fin); + default void onWebSocketPartialBinary(ByteBuffer payload, boolean fin) + { + } /** * A WebSocket TEXT (or associated CONTINUATION) frame has been received. @@ -50,5 +52,7 @@ public interface WebSocketPartialListener extends WebSocketConnectionListener * will be held over until the next frame is received. * @param fin true if this is the final frame, false otherwise */ - void onWebSocketPartialText(String payload, boolean fin); + default void onWebSocketPartialText(String payload, boolean fin) + { + } } diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPingPongListener.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPingPongListener.java index dde0f7fb0ea..968ac27d937 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPingPongListener.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/WebSocketPingPongListener.java @@ -30,12 +30,16 @@ public interface WebSocketPingPongListener extends WebSocketConnectionListener * * @param payload the ping payload */ - void onWebSocketPing(ByteBuffer payload); + default void onWebSocketPing(ByteBuffer payload) + { + } /** * A WebSocket PONG has been received. * * @param payload the pong payload */ - void onWebSocketPong(ByteBuffer payload); + default void onWebSocketPong(ByteBuffer payload) + { + } } diff --git a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java index acbee3fbd3b..dc58cf9973e 100644 --- a/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java +++ b/jetty-websocket/websocket-jetty-api/src/main/java/org/eclipse/jetty/websocket/api/annotations/OnWebSocketMessage.java @@ -35,9 +35,9 @@ import org.eclipse.jetty.websocket.api.Session; *

* Text Message Versions *

    - *
  1. {@code public void methodName(String text)}
  2. + *
  3. public void methodName(String text)
  4. *
  5. public void methodName({@link Session} session, String text)
  6. - *
  7. {@code public void methodName(Reader reader)}
  8. + *
  9. public void methodName(Reader reader)
  10. *
  11. public void methodName({@link Session} session, Reader reader)
  12. *
* Note: that the {@link Reader} in this case will always use UTF-8 encoding/charset (this is dictated by the RFC 6455 spec for Text Messages. If you need to @@ -45,11 +45,11 @@ import org.eclipse.jetty.websocket.api.Session; *

* Binary Message Versions *

    - *
  1. {@code public void methodName(ByteBuffer message)}
  2. + *
  3. public void methodName(ByteBuffer message)
  4. *
  5. public void methodName({@link Session} session, ByteBuffer message)
  6. - *
  7. {@code public void methodName(byte buf[], int offset, int length)}
  8. + *
  9. public void methodName(byte buf[], int offset, int length)
  10. *
  11. public void methodName({@link Session} session, byte buf[], int offset, int length)
  12. - *
  13. {@code public void methodName(InputStream stream)}
  14. + *
  15. public void methodName(InputStream stream)
  16. *
  17. public void methodName({@link Session} session, InputStream stream)
  18. *
*/ diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java index 13a22ab6d0f..0d08b373c4f 100644 --- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java +++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerFactory.java @@ -296,15 +296,9 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle final InvokerUtils.Arg STATUS_CODE = new InvokerUtils.Arg(int.class); final InvokerUtils.Arg REASON = new InvokerUtils.Arg(String.class); MethodHandle methodHandle = InvokerUtils.mutatedInvoker(lookup, endpointClass, onmethod, SESSION, STATUS_CODE, REASON); - // TODO: need mutation of args? ... - // Session + CloseInfo -> - // setOnClose((closeInfo) ->{ - // args[0] = getSession(); - // args[1] = closeInfo.getStatusCode(); - // args[2] = closeInfo.getReason(); - // invoker.apply(endpoint, args); metadata.setCloseHandler(methodHandle, onmethod); } + // OnWebSocketError [0..1] onmethod = ReflectUtils.findAnnotatedMethod(endpointClass, OnWebSocketError.class); if (onmethod != null) @@ -360,7 +354,6 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle new InvokerUtils.Arg(Reader.class).required() }; - onmessageloop: for (Method onMsg : onMessages) { assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); @@ -371,7 +364,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle // Normal Text Message assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); metadata.setTextHandler(StringMessageSink.class, methodHandle, onMsg); - continue onmessageloop; + continue; } methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, binaryBufferCallingArgs); @@ -380,7 +373,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle // ByteBuffer Binary Message assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); metadata.setBinaryHandle(ByteBufferMessageSink.class, methodHandle, onMsg); - continue onmessageloop; + continue; } methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, binaryArrayCallingArgs); @@ -389,7 +382,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle // byte[] Binary Message assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); metadata.setBinaryHandle(ByteArrayMessageSink.class, methodHandle, onMsg); - continue onmessageloop; + continue; } methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, inputStreamCallingArgs); @@ -398,7 +391,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle // InputStream Binary Message assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); metadata.setBinaryHandle(InputStreamMessageSink.class, methodHandle, onMsg); - continue onmessageloop; + continue; } methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, readerCallingArgs); @@ -407,7 +400,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle // Reader Text Message assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); metadata.setTextHandler(ReaderMessageSink.class, methodHandle, onMsg); - continue onmessageloop; + continue; } else { diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java index d0cb78f7884..4eddfa4c677 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java @@ -122,15 +122,15 @@ public class ConcurrentConnectTest for (EventSocket l : listeners) { l.session.getRemote().sendString("ping"); - assertThat(l.messageQueue.poll(5, TimeUnit.SECONDS), is("ping")); + assertThat(l.textMessages.poll(5, TimeUnit.SECONDS), is("ping")); l.session.close(StatusCode.NORMAL, "close from client"); } for (EventSocket l : listeners) { assertTrue(l.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(l.statusCode, is(StatusCode.NORMAL)); - assertThat(l.reason, is("close from client")); + assertThat(l.closeCode, is(StatusCode.NORMAL)); + assertThat(l.closeReason, is("close from client")); assertNull(l.error); } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/EventSocket.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/EventSocket.java index 69d3fcb9e71..bffbe3825e5 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/EventSocket.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/EventSocket.java @@ -42,10 +42,10 @@ public class EventSocket public Session session; private String behavior; - public BlockingQueue messageQueue = new BlockingArrayQueue<>(); - public BlockingQueue binaryMessageQueue = new BlockingArrayQueue<>(); - public volatile int statusCode = StatusCode.UNDEFINED; - public volatile String reason; + public BlockingQueue textMessages = new BlockingArrayQueue<>(); + public BlockingQueue binaryMessages = new BlockingArrayQueue<>(); + public volatile int closeCode = StatusCode.UNDEFINED; + public volatile String closeReason; public volatile Throwable error = null; public CountDownLatch openLatch = new CountDownLatch(1); @@ -67,7 +67,7 @@ public class EventSocket { if (LOG.isDebugEnabled()) LOG.debug("{} onMessage(): {}", toString(), message); - messageQueue.offer(message); + textMessages.offer(message); } @OnWebSocketMessage @@ -76,7 +76,7 @@ public class EventSocket ByteBuffer message = ByteBuffer.wrap(buf, offset, len); if (LOG.isDebugEnabled()) LOG.debug("{} onMessage(): {}", toString(), message); - binaryMessageQueue.offer(message); + binaryMessages.offer(message); } @OnWebSocketClose @@ -84,8 +84,8 @@ public class EventSocket { if (LOG.isDebugEnabled()) LOG.debug("{} onClose(): {}:{}", toString(), statusCode, reason); - this.statusCode = statusCode; - this.reason = reason; + this.closeCode = statusCode; + this.closeReason = reason; closeLatch.countDown(); } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java index 77b15837219..fb70a93f8ee 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyOnCloseTest.java @@ -130,8 +130,8 @@ public class JettyOnCloseTest clientEndpoint.session.close(); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.SERVICE_RESTART)); - assertThat(clientEndpoint.reason, is("custom close reason")); + assertThat(clientEndpoint.closeCode, is(StatusCode.SERVICE_RESTART)); + assertThat(clientEndpoint.closeReason, is("custom close reason")); } @Test @@ -146,8 +146,8 @@ public class JettyOnCloseTest serverEndpoint.session.close(StatusCode.NORMAL, "first close"); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.NORMAL)); - assertThat(clientEndpoint.reason, is("first close")); + assertThat(clientEndpoint.closeCode, is(StatusCode.NORMAL)); + assertThat(clientEndpoint.closeReason, is("first close")); } @Test @@ -166,8 +166,8 @@ public class JettyOnCloseTest serverEndpoint.session.close(StatusCode.PROTOCOL, "abnormal close 1"); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.PROTOCOL)); - assertThat(clientEndpoint.reason, is("abnormal close 1")); + assertThat(clientEndpoint.closeCode, is(StatusCode.PROTOCOL)); + assertThat(clientEndpoint.closeReason, is("abnormal close 1")); } @Test @@ -185,8 +185,8 @@ public class JettyOnCloseTest clientEndpoint.session.close(); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.SERVER_ERROR)); - assertThat(clientEndpoint.reason, containsString("trigger onError from onClose")); + assertThat(clientEndpoint.closeCode, is(StatusCode.SERVER_ERROR)); + assertThat(clientEndpoint.closeReason, containsString("trigger onError from onClose")); assertTrue(serverEndpoint.errorLatch.await(5, TimeUnit.SECONDS)); assertThat(serverEndpoint.error, instanceOf(RuntimeException.class)); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketExtensionConfigTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketExtensionConfigTest.java index 620a59ee419..9b2a4cc74a0 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketExtensionConfigTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketExtensionConfigTest.java @@ -130,7 +130,7 @@ public class JettyWebSocketExtensionConfigTest assertTrue(socket.closeLatch.await(5, TimeUnit.SECONDS)); assertTrue(correctResponseExtensions.await(5, TimeUnit.SECONDS)); - String msg = socket.messageQueue.poll(); + String msg = socket.textMessages.poll(); assertThat(msg, is("hello world")); } } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketFilterTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketFilterTest.java index 2543e78f4c4..488eb796a9b 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketFilterTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketFilterTest.java @@ -80,7 +80,7 @@ public class JettyWebSocketFilterTest } assertTrue(socket.closeLatch.await(10, TimeUnit.SECONDS)); - String msg = socket.messageQueue.poll(); + String msg = socket.textMessages.poll(); assertThat(msg, is("hello world")); } } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java index 2bf60c8dd27..926ecd0bdd3 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/JettyWebSocketServletTest.java @@ -92,7 +92,7 @@ public class JettyWebSocketServletTest } assertTrue(socket.closeLatch.await(10, TimeUnit.SECONDS)); - String msg = socket.messageQueue.poll(); + String msg = socket.textMessages.poll(); assertThat(msg, is("hello world")); } } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/SuspendResumeTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/SuspendResumeTest.java index 90556e1823e..e919baada8f 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/SuspendResumeTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/SuspendResumeTest.java @@ -110,16 +110,16 @@ public class SuspendResumeTest clientSocket.session.getRemote().sendString("suspend"); clientSocket.session.getRemote().sendString("hello world"); - assertThat(serverSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("suspend")); - assertNull(serverSocket.messageQueue.poll(1, TimeUnit.SECONDS)); + assertThat(serverSocket.textMessages.poll(5, TimeUnit.SECONDS), is("suspend")); + assertNull(serverSocket.textMessages.poll(1, TimeUnit.SECONDS)); serverSocket.suspendToken.resume(); - assertThat(serverSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("suspend")); - assertNull(serverSocket.messageQueue.poll(1, TimeUnit.SECONDS)); + assertThat(serverSocket.textMessages.poll(5, TimeUnit.SECONDS), is("suspend")); + assertNull(serverSocket.textMessages.poll(1, TimeUnit.SECONDS)); serverSocket.suspendToken.resume(); - assertThat(serverSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("hello world")); - assertNull(serverSocket.messageQueue.poll(1, TimeUnit.SECONDS)); + assertThat(serverSocket.textMessages.poll(5, TimeUnit.SECONDS), is("hello world")); + assertNull(serverSocket.textMessages.poll(1, TimeUnit.SECONDS)); // make sure both sides are closed clientSocket.session.close(); @@ -142,22 +142,22 @@ public class SuspendResumeTest // verify connection by sending a message from server to client assertTrue(serverSocket.openLatch.await(5, TimeUnit.SECONDS)); serverSocket.session.getRemote().sendString("verification"); - assertThat(clientSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("verification")); + assertThat(clientSocket.textMessages.poll(5, TimeUnit.SECONDS), is("verification")); // suspend the client so that no read events occur SuspendToken suspendToken = clientSocket.session.suspend(); // verify client can still send messages clientSocket.session.getRemote().sendString("message-from-client"); - assertThat(serverSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("message-from-client")); + assertThat(serverSocket.textMessages.poll(5, TimeUnit.SECONDS), is("message-from-client")); // the message is not received as it is suspended serverSocket.session.getRemote().sendString("message-from-server"); - assertNull(clientSocket.messageQueue.poll(2, TimeUnit.SECONDS)); + assertNull(clientSocket.textMessages.poll(2, TimeUnit.SECONDS)); // client should receive message after it resumes suspendToken.resume(); - assertThat(clientSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("message-from-server")); + assertThat(clientSocket.textMessages.poll(5, TimeUnit.SECONDS), is("message-from-server")); // make sure both sides are closed clientSocket.session.close(); @@ -180,7 +180,7 @@ public class SuspendResumeTest // verify connection by sending a message from server to client assertTrue(serverSocket.openLatch.await(5, TimeUnit.SECONDS)); serverSocket.session.getRemote().sendString("verification"); - assertThat(clientSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("verification")); + assertThat(clientSocket.textMessages.poll(5, TimeUnit.SECONDS), is("verification")); // make sure both sides are closed clientSocket.session.close(); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java index cd590d1507f..aad53455047 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketOverHTTP2Test.java @@ -167,13 +167,13 @@ public class WebSocketOverHTTP2Test String text = "websocket"; session.getRemote().sendString(text); - String message = wsEndPoint.messageQueue.poll(5, TimeUnit.SECONDS); + String message = wsEndPoint.textMessages.poll(5, TimeUnit.SECONDS); assertNotNull(message); assertEquals(text, message); session.close(StatusCode.NORMAL, null); assertTrue(wsEndPoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertEquals(StatusCode.NORMAL, wsEndPoint.statusCode); + assertEquals(StatusCode.NORMAL, wsEndPoint.closeCode); assertNull(wsEndPoint.error); } @@ -230,7 +230,7 @@ public class WebSocketOverHTTP2Test String text = "websocket"; session.getRemote().sendString(text); - String message = wsEndPoint.messageQueue.poll(5, TimeUnit.SECONDS); + String message = wsEndPoint.textMessages.poll(5, TimeUnit.SECONDS); assertNotNull(message); assertEquals(text, message); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketServletExamplesTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketServletExamplesTest.java index 4f309ab5cf0..547c5c396ae 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketServletExamplesTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketServletExamplesTest.java @@ -123,7 +123,7 @@ public class WebSocketServletExamplesTest String message = "hello world"; session.getRemote().sendString(message); - String response = socket.messageQueue.poll(5, TimeUnit.SECONDS); + String response = socket.textMessages.poll(5, TimeUnit.SECONDS); assertThat(response, is(message)); } @@ -147,7 +147,7 @@ public class WebSocketServletExamplesTest String message = "hello world"; session.getRemote().sendString(message); - String response = socket.messageQueue.poll(5, TimeUnit.SECONDS); + String response = socket.textMessages.poll(5, TimeUnit.SECONDS); assertThat(response, is(message)); } @@ -173,7 +173,7 @@ public class WebSocketServletExamplesTest String message = "hello world"; session.getRemote().sendString(message); - String response = socket.messageQueue.poll(5, TimeUnit.SECONDS); + String response = socket.textMessages.poll(5, TimeUnit.SECONDS); assertThat(response, is(message)); } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java index 43ffc5e687f..914ddd1ae2b 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/WebSocketStopTest.java @@ -102,8 +102,8 @@ public class WebSocketStopTest client.stop(); assertTrue(clientSocket1.closeLatch.await(5, TimeUnit.SECONDS)); assertTrue(clientSocket2.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientSocket1.statusCode, is(StatusCode.SHUTDOWN)); - assertThat(clientSocket2.statusCode, is(StatusCode.SHUTDOWN)); + assertThat(clientSocket1.closeCode, is(StatusCode.SHUTDOWN)); + assertThat(clientSocket2.closeCode, is(StatusCode.SHUTDOWN)); } @Test @@ -116,7 +116,7 @@ public class WebSocketStopTest upgradeRequest.addExtensions("permessage-deflate"); Session session = client.connect(clientSocket, uri, upgradeRequest).get(5, TimeUnit.SECONDS); clientSocket.session.getRemote().sendString("init deflater"); - assertThat(serverSocket.messageQueue.poll(5, TimeUnit.SECONDS), is("init deflater")); + assertThat(serverSocket.textMessages.poll(5, TimeUnit.SECONDS), is("init deflater")); session.close(StatusCode.NORMAL, null); // make sure both sides are closed @@ -125,8 +125,8 @@ public class WebSocketStopTest assertTrue(serverSocket.closeLatch.await(5, TimeUnit.SECONDS)); // check we closed normally - assertThat(clientSocket.statusCode, is(StatusCode.NORMAL)); - assertThat(serverSocket.statusCode, is(StatusCode.NORMAL)); + assertThat(clientSocket.closeCode, is(StatusCode.NORMAL)); + assertThat(serverSocket.closeCode, is(StatusCode.NORMAL)); IOException error = assertThrows(IOException.class, () -> session.getRemote().sendString("this should fail before ExtensionStack")); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java index 662bbaa7bf5..916ab848b81 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/autobahn/JettyAutobahnClient.java @@ -161,7 +161,7 @@ public class JettyAutobahnClient if (waitForUpgrade(wsUri, response)) { - String msg = onCaseCount.messageQueue.poll(10, TimeUnit.SECONDS); + String msg = onCaseCount.textMessages.poll(10, TimeUnit.SECONDS); onCaseCount.session.close(StatusCode.SHUTDOWN, null); assertTrue(onCaseCount.closeLatch.await(2, TimeUnit.SECONDS)); assertNotNull(msg); diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConfigTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConfigTest.java index 96d1e240536..ba3446931d6 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConfigTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientConfigTest.java @@ -159,7 +159,7 @@ public class ClientConfigTest assertNull(clientEndpoint.error); assertTrue(serverSocket.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(serverSocket.statusCode, is(StatusCode.NO_CODE)); + assertThat(serverSocket.closeCode, is(StatusCode.NO_CODE)); } @ParameterizedTest @@ -177,7 +177,7 @@ public class ClientConfigTest assertThat(clientEndpoint.error, instanceOf(MessageTooLargeException.class)); assertTrue(serverSocket.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(serverSocket.statusCode, is(StatusCode.MESSAGE_TOO_LARGE)); + assertThat(serverSocket.closeCode, is(StatusCode.MESSAGE_TOO_LARGE)); } @ParameterizedTest @@ -196,7 +196,7 @@ public class ClientConfigTest assertThat(clientEndpoint.error, instanceOf(WebSocketTimeoutException.class)); assertTrue(serverSocket.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(serverSocket.statusCode, is(StatusCode.SHUTDOWN)); + assertThat(serverSocket.closeCode, is(StatusCode.SHUTDOWN)); } @ParameterizedTest @@ -214,6 +214,6 @@ public class ClientConfigTest assertThat(clientEndpoint.error, instanceOf(MessageTooLargeException.class)); assertTrue(serverSocket.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(serverSocket.statusCode, is(StatusCode.MESSAGE_TOO_LARGE)); + assertThat(serverSocket.closeCode, is(StatusCode.MESSAGE_TOO_LARGE)); } } diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractAnnotatedListener.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractAnnotatedListener.java new file mode 100644 index 00000000000..c28200ac88e --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractAnnotatedListener.java @@ -0,0 +1,69 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.listeners; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; + +@WebSocket +public class AbstractAnnotatedListener +{ + protected Session _session; + + @OnWebSocketConnect + public void onWebSocketConnect(Session session) + { + _session = session; + } + + @OnWebSocketError + public void onWebSocketError(Throwable thr) + { + thr.printStackTrace(); + } + + public void sendText(String message, boolean last) + { + try + { + _session.getRemote().sendPartialString(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + public void sendBinary(ByteBuffer message, boolean last) + { + try + { + _session.getRemote().sendPartialBytes(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractListener.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractListener.java new file mode 100644 index 00000000000..d6b3784e970 --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/AbstractListener.java @@ -0,0 +1,66 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.listeners; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketConnectionListener; + +public class AbstractListener implements WebSocketConnectionListener +{ + protected Session _session; + + @Override + public void onWebSocketConnect(Session session) + { + _session = session; + } + + @Override + public void onWebSocketError(Throwable thr) + { + thr.printStackTrace(); + } + + public void sendText(String message, boolean last) + { + try + { + _session.getRemote().sendPartialString(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } + + public void sendBinary(ByteBuffer message, boolean last) + { + try + { + _session.getRemote().sendPartialBytes(message, last); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/BinaryListeners.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/BinaryListeners.java new file mode 100644 index 00000000000..7cc0a8850a7 --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/BinaryListeners.java @@ -0,0 +1,129 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.listeners; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.stream.Stream; + +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketListener; +import org.eclipse.jetty.websocket.api.WebSocketPartialListener; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.junit.jupiter.params.provider.Arguments; + +public class BinaryListeners +{ + public static Stream getBinaryListeners() + { + return Stream.of( + OffsetByteArrayWholeListener.class, + OffsetByteBufferPartialListener.class, + AnnotatedByteBufferWholeListener.class, + AnnotatedByteArrayWholeListener.class, + AnnotatedOffsetByteArrayWholeListener.class, + AnnotatedInputStreamWholeListener.class, + AnnotatedReverseArgumentPartialListener.class + ).map(Arguments::of); + } + + public static class OffsetByteArrayWholeListener extends AbstractListener implements WebSocketListener + { + @Override + public void onWebSocketBinary(byte[] payload, int offset, int len) + { + sendBinary(BufferUtil.toBuffer(payload, offset, len), true); + } + } + + public static class OffsetByteBufferPartialListener extends AbstractListener implements WebSocketPartialListener + { + @Override + public void onWebSocketPartialBinary(ByteBuffer payload, boolean fin) + { + sendBinary(payload, fin); + } + } + + @WebSocket + public static class AnnotatedByteBufferWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(ByteBuffer message) + { + sendBinary(message, true); + } + } + + @WebSocket + public static class AnnotatedByteArrayWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(byte[] message) + { + sendBinary(BufferUtil.toBuffer(message), true); + } + } + + @WebSocket + public static class AnnotatedOffsetByteArrayWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(byte[] message, int offset, int length) + { + sendBinary(BufferUtil.toBuffer(message, offset, length), true); + } + } + + @WebSocket + public static class AnnotatedInputStreamWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(InputStream stream) + { + sendBinary(readBytes(stream), true); + } + } + + @WebSocket + public static class AnnotatedReverseArgumentPartialListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(Session session, ByteBuffer message) + { + sendBinary(message, true); + } + } + + public static ByteBuffer readBytes(InputStream stream) + { + try + { + return BufferUtil.toBuffer(IO.readBytes(stream)); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/TextListeners.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/TextListeners.java new file mode 100644 index 00000000000..e362c28aea0 --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/TextListeners.java @@ -0,0 +1,105 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.listeners; + +import java.io.IOException; +import java.io.Reader; +import java.util.stream.Stream; + +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketListener; +import org.eclipse.jetty.websocket.api.WebSocketPartialListener; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.junit.jupiter.params.provider.Arguments; + +public class TextListeners +{ + public static Stream getTextListeners() + { + return Stream.of( + StringWholeListener.class, + StringPartialListener.class, + AnnotatedStringWholeListener.class, + AnnotatedReaderWholeListener.class, + AnnotatedReverseArgumentPartialListener.class + ).map(Arguments::of); + } + + public static class StringWholeListener extends AbstractListener implements WebSocketListener + { + @Override + public void onWebSocketText(String message) + { + sendText(message, true); + } + } + + public static class StringPartialListener extends AbstractListener implements WebSocketPartialListener + { + @Override + public void onWebSocketPartialText(String message, boolean fin) + { + sendText(message, fin); + } + } + + @WebSocket + public static class AnnotatedStringWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(String message) + { + sendText(message, true); + } + } + + @WebSocket + public static class AnnotatedReaderWholeListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(Reader reader) + { + sendText(readString(reader), true); + } + } + + @WebSocket + public static class AnnotatedReverseArgumentPartialListener extends AbstractAnnotatedListener + { + @OnWebSocketMessage + public void onMessage(Session session, String message) + { + sendText(message, true); + } + } + + public static String readString(Reader reader) + { + try + { + return IO.toString(reader); + } + catch (IOException e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/WebSocketListenerTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/WebSocketListenerTest.java new file mode 100644 index 00000000000..fe290ccba82 --- /dev/null +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/listeners/WebSocketListenerTest.java @@ -0,0 +1,146 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 +// +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.websocket.tests.listeners; + +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.websocket.api.StatusCode; +import org.eclipse.jetty.websocket.client.WebSocketClient; +import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer; +import org.eclipse.jetty.websocket.tests.EventSocket; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class WebSocketListenerTest +{ + private Server server; + private URI serverUri; + private WebSocketClient client; + + @BeforeEach + public void before() throws Exception + { + server = new Server(); + ServerConnector connector = new ServerConnector(server); + server.addConnector(connector); + + ServletContextHandler contextHandler = new ServletContextHandler(); + contextHandler.setContextPath("/"); + JettyWebSocketServletContainerInitializer.configure(contextHandler, (context, container) -> + { + for (Class c : getClassListFromArguments(TextListeners.getTextListeners())) + { + container.addMapping("/text/" + c.getSimpleName(), (req, res) -> construct(c)); + } + + for (Class c : getClassListFromArguments(BinaryListeners.getBinaryListeners())) + { + container.addMapping("/binary/" + c.getSimpleName(), (req, res) -> construct(c)); + } + }); + + server.setHandler(contextHandler); + server.start(); + serverUri = URI.create("ws://localhost:" + connector.getLocalPort() + "/"); + client = new WebSocketClient(); + client.start(); + } + + @AfterEach + public void after() throws Exception + { + client.stop(); + server.stop(); + } + + @ParameterizedTest + @MethodSource("org.eclipse.jetty.websocket.tests.listeners.TextListeners#getTextListeners") + public void testTextListeners(Class clazz) throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + client.connect(clientEndpoint, serverUri.resolve("/text/" + clazz.getSimpleName())).get(5, TimeUnit.SECONDS); + + // Send and receive echo on client. + String payload = "hello world"; + clientEndpoint.session.getRemote().sendString(payload); + String echoMessage = clientEndpoint.textMessages.poll(5, TimeUnit.SECONDS); + assertThat(echoMessage, is(payload)); + + // Close normally. + clientEndpoint.session.close(StatusCode.NORMAL, "standard close"); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeCode, is(StatusCode.NORMAL)); + assertThat(clientEndpoint.closeReason, is("standard close")); + } + + @ParameterizedTest + @MethodSource("org.eclipse.jetty.websocket.tests.listeners.BinaryListeners#getBinaryListeners") + public void testBinaryListeners(Class clazz) throws Exception + { + EventSocket clientEndpoint = new EventSocket(); + client.connect(clientEndpoint, serverUri.resolve("/binary/" + clazz.getSimpleName())).get(5, TimeUnit.SECONDS); + + // Send and receive echo on client. + ByteBuffer payload = BufferUtil.toBuffer("hello world"); + clientEndpoint.session.getRemote().sendBytes(payload); + ByteBuffer echoMessage = clientEndpoint.binaryMessages.poll(5, TimeUnit.SECONDS); + assertThat(echoMessage, is(payload)); + + // Close normally. + clientEndpoint.session.close(StatusCode.NORMAL, "standard close"); + assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); + assertThat(clientEndpoint.closeCode, is(StatusCode.NORMAL)); + assertThat(clientEndpoint.closeReason, is("standard close")); + } + + private List> getClassListFromArguments(Stream stream) + { + return stream.map(arguments -> (Class)arguments.get()[0]).collect(Collectors.toList()); + } + + private T construct(Class clazz) + { + try + { + @SuppressWarnings("unchecked") + T instance = (T)clazz.getConstructors()[0].newInstance(); + return instance; + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } +} diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerConfigTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerConfigTest.java index 510774ed602..739877c084e 100644 --- a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerConfigTest.java +++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerConfigTest.java @@ -230,7 +230,7 @@ public class ServerConfigTest assertNull(serverEndpoint.error); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.NO_CODE)); + assertThat(clientEndpoint.closeCode, is(StatusCode.NO_CODE)); listener.assertClosed(); } @@ -251,7 +251,7 @@ public class ServerConfigTest assertThat(serverEndpoint.error, instanceOf(MessageTooLargeException.class)); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.MESSAGE_TOO_LARGE)); + assertThat(clientEndpoint.closeCode, is(StatusCode.MESSAGE_TOO_LARGE)); listener.assertClosed(); } @@ -267,7 +267,7 @@ public class ServerConfigTest connect.get(5, TimeUnit.SECONDS); clientEndpoint.session.getRemote().sendString("hello world"); - String msg = serverEndpoint.messageQueue.poll(500, TimeUnit.MILLISECONDS); + String msg = serverEndpoint.textMessages.poll(500, TimeUnit.MILLISECONDS); assertThat(msg, is("hello world")); Thread.sleep(idleTimeout + 500); @@ -275,7 +275,7 @@ public class ServerConfigTest assertThat(serverEndpoint.error, instanceOf(WebSocketTimeoutException.class)); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.SHUTDOWN)); + assertThat(clientEndpoint.closeCode, is(StatusCode.SHUTDOWN)); listener.assertClosed(); } @@ -296,7 +296,7 @@ public class ServerConfigTest assertThat(serverEndpoint.error, instanceOf(MessageTooLargeException.class)); assertTrue(clientEndpoint.closeLatch.await(5, TimeUnit.SECONDS)); - assertThat(clientEndpoint.statusCode, is(StatusCode.MESSAGE_TOO_LARGE)); + assertThat(clientEndpoint.closeCode, is(StatusCode.MESSAGE_TOO_LARGE)); listener.assertClosed(); } diff --git a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/ByteArrayMessageSink.java b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/ByteArrayMessageSink.java index 1921e36b704..4b84a54156d 100644 --- a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/ByteArrayMessageSink.java +++ b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/ByteArrayMessageSink.java @@ -42,7 +42,8 @@ public class ByteArrayMessageSink extends AbstractMessageSink { super(session, methodHandle); - // byte[] buf + // This uses the offset length byte array signature not supported by javax websocket. + // The javax layer instead uses decoders for whole byte array messages instead of this message sink. MethodType onMessageType = MethodType.methodType(Void.TYPE, byte[].class, int.class, int.class); if (methodHandle.type().changeReturnType(void.class) != onMessageType.changeReturnType(void.class)) { diff --git a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteArrayMessageSink.java b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteArrayMessageSink.java index a42c3577837..bf7058cbe0c 100644 --- a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteArrayMessageSink.java +++ b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteArrayMessageSink.java @@ -19,13 +19,11 @@ package org.eclipse.jetty.websocket.util.messages; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.websocket.core.CoreSession; import org.eclipse.jetty.websocket.core.Frame; -import org.eclipse.jetty.websocket.util.InvalidSignatureException; public class PartialByteArrayMessageSink extends AbstractMessageSink { @@ -34,13 +32,6 @@ public class PartialByteArrayMessageSink extends AbstractMessageSink public PartialByteArrayMessageSink(CoreSession session, MethodHandle methodHandle) { super(session, methodHandle); - - // byte[] buf, int offset, int length - MethodType onMessageType = MethodType.methodType(Void.TYPE, byte[].class, int.class, int.class, boolean.class); - if (methodHandle.type() != onMessageType) - { - throw InvalidSignatureException.build(onMessageType, methodHandle.type()); - } } @Override @@ -51,7 +42,7 @@ public class PartialByteArrayMessageSink extends AbstractMessageSink if (frame.hasPayload() || frame.isFin()) { byte[] buffer = frame.hasPayload() ? BufferUtil.toArray(frame.getPayload()) : EMPTY_BUFFER; - methodHandle.invoke(buffer, 0, buffer.length, frame.isFin()); + methodHandle.invoke(buffer, frame.isFin()); } callback.succeeded(); diff --git a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteBufferMessageSink.java b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteBufferMessageSink.java index ce00ee7acef..9336e93aa52 100644 --- a/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteBufferMessageSink.java +++ b/jetty-websocket/websocket-util/src/main/java/org/eclipse/jetty/websocket/util/messages/PartialByteBufferMessageSink.java @@ -29,14 +29,6 @@ public class PartialByteBufferMessageSink extends AbstractMessageSink public PartialByteBufferMessageSink(CoreSession session, MethodHandle methodHandle) { super(session, methodHandle); - - /* TODO: Review - MethodType onMessageType = MethodType.methodType(Void.TYPE, ByteBuffer.class, boolean.class); - if (methodHandle.type() != onMessageType) - { - throw InvalidSignatureException.build(onMessageType, methodHandle.type()); - } - */ } @Override