diff --git a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java index f32209acf9c..d8d046c1000 100644 --- a/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java +++ b/jetty-websocket/websocket-javax-common/src/main/java/org/eclipse/jetty/websocket/javax/common/JavaxWebSocketFrameHandlerFactory.java @@ -706,16 +706,7 @@ public abstract class JavaxWebSocketFrameHandlerFactory private MethodHandles.Lookup getMethodHandleLookup(Class endpointClass) throws InvalidWebSocketException { - MethodHandles.Lookup lookup; - try - { - lookup = MethodHandles.privateLookupIn(endpointClass, MethodHandles.lookup()); - } - catch (IllegalAccessException e) - { - throw new InvalidWebSocketException("Unable to obtain MethodHandle lookup for " + endpointClass, e); - } - return lookup; + return MethodHandles.publicLookup().in(endpointClass); } private static class DecodedArgs diff --git a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JsrBatchModeTest.java b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JsrBatchModeTest.java index 1f7ad6ee2f3..f3689739fb5 100644 --- a/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JsrBatchModeTest.java +++ b/jetty-websocket/websocket-javax-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/JsrBatchModeTest.java @@ -89,15 +89,8 @@ public class JsrBatchModeTest URI uri = server.getWsUri(); - final CountDownLatch latch = new CountDownLatch(1); - EndpointAdapter endpoint = new EndpointAdapter() - { - @Override - public void onMessage(String message) - { - latch.countDown(); - } - }; + CountDownLatch latch = new CountDownLatch(1); + EndpointAdapter endpoint = new EndpointAdapter(latch); try (Session session = client.connectToServer(endpoint, config, uri)) { @@ -126,15 +119,8 @@ public class JsrBatchModeTest URI uri = server.getWsUri(); - final CountDownLatch latch = new CountDownLatch(1); - EndpointAdapter endpoint = new EndpointAdapter() - { - @Override - public void onMessage(String message) - { - latch.countDown(); - } - }; + CountDownLatch latch = new CountDownLatch(1); + EndpointAdapter endpoint = new EndpointAdapter(latch); try (Session session = client.connectToServer(endpoint, config, uri)) { @@ -157,15 +143,8 @@ public class JsrBatchModeTest URI uri = server.getWsUri(); - final CountDownLatch latch = new CountDownLatch(1); - EndpointAdapter endpoint = new EndpointAdapter() - { - @Override - public void onMessage(String message) - { - latch.countDown(); - } - }; + CountDownLatch latch = new CountDownLatch(1); + EndpointAdapter endpoint = new EndpointAdapter(latch); try (Session session = client.connectToServer(endpoint, config, uri)) { @@ -180,12 +159,25 @@ public class JsrBatchModeTest } } - public abstract static class EndpointAdapter extends Endpoint implements MessageHandler.Whole + public static class EndpointAdapter extends Endpoint implements MessageHandler.Whole { + private final CountDownLatch latch; + + public EndpointAdapter(CountDownLatch latch) + { + this.latch = latch; + } + @Override public void onOpen(Session session, EndpointConfig config) { session.addMessageHandler(this); } + + @Override + public void onMessage(String message) + { + latch.countDown(); + } } } 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 5482da3b4b0..6f0fe0a111b 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 @@ -458,16 +458,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle private MethodHandles.Lookup getMethodHandleLookup(Class endpointClass) throws InvalidWebSocketException { - MethodHandles.Lookup lookup; - try - { - lookup = MethodHandles.privateLookupIn(endpointClass, MethodHandles.lookup()); - } - catch (IllegalAccessException e) - { - throw new InvalidWebSocketException("Unable to obtain MethodHandle lookup for " + endpointClass, e); - } - return lookup; + return MethodHandles.publicLookup().in(endpointClass); } @Override diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/EndPoints.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/EndPoints.java new file mode 100644 index 00000000000..373e0dd7ccc --- /dev/null +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/EndPoints.java @@ -0,0 +1,512 @@ +// +// ======================================================================== +// 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.common; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.websocket.api.Frame; +import org.eclipse.jetty.websocket.api.RemoteEndpoint; +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketFrameListener; +import org.eclipse.jetty.websocket.api.WebSocketListener; +import org.eclipse.jetty.websocket.api.WebSocketPartialListener; +import org.eclipse.jetty.websocket.api.WebSocketPingPongListener; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame; +import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; +import org.eclipse.jetty.websocket.api.annotations.WebSocket; +import org.eclipse.jetty.websocket.core.CloseStatus; +import org.eclipse.jetty.websocket.util.TextUtil; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; + +public class EndPoints +{ + private EndPoints() + { + } + + public static class ListenerBasicSocket implements WebSocketListener + { + public EventQueue events = new EventQueue(); + + @Override + public void onWebSocketBinary(byte[] payload, int offset, int len) + { + events.add("onWebSocketBinary([%d], %d, %d)", payload.length, offset, len); + } + + @Override + public void onWebSocketClose(int statusCode, String reason) + { + events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); + } + + @Override + public void onWebSocketConnect(Session session) + { + events.add("onWebSocketConnect(%s)", session); + } + + @Override + public void onWebSocketError(Throwable cause) + { + events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); + } + + @Override + public void onWebSocketText(String message) + { + events.add("onWebSocketText(%s)", TextUtil.quote(message)); + } + } + + public static class ListenerFrameSocket implements WebSocketFrameListener + { + public EventQueue events = new EventQueue(); + + @Override + public void onWebSocketClose(int statusCode, String reason) + { + events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); + } + + @Override + public void onWebSocketConnect(Session session) + { + events.add("onWebSocketConnect(%s)", session); + } + + @Override + public void onWebSocketError(Throwable cause) + { + events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); + } + + @Override + public void onWebSocketFrame(Frame frame) + { + events.add("onWebSocketFrame(%s)", frame.toString()); + } + } + + public static class ListenerPartialSocket implements WebSocketPartialListener + { + public EventQueue events = new EventQueue(); + + @Override + public void onWebSocketClose(int statusCode, String reason) + { + events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); + } + + @Override + public void onWebSocketConnect(Session session) + { + events.add("onWebSocketConnect(%s)", session); + } + + @Override + public void onWebSocketError(Throwable cause) + { + events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); + } + + @Override + public void onWebSocketPartialText(String payload, boolean fin) + { + events.add("onWebSocketPartialText(%s, %b)", TextUtil.quote(payload), fin); + } + + @Override + public void onWebSocketPartialBinary(ByteBuffer payload, boolean fin) + { + events.add("onWebSocketPartialBinary(%s, %b)", BufferUtil.toDetailString(payload), fin); + } + } + + public static class ListenerPingPongSocket implements WebSocketPingPongListener + { + public EventQueue events = new EventQueue(); + + @Override + public void onWebSocketClose(int statusCode, String reason) + { + events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); + } + + @Override + public void onWebSocketConnect(Session session) + { + events.add("onWebSocketConnect(%s)", session); + } + + @Override + public void onWebSocketError(Throwable cause) + { + events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); + } + + @Override + public void onWebSocketPing(ByteBuffer payload) + { + events.add("onWebSocketPing(%s)", BufferUtil.toDetailString(payload)); + } + + @Override + public void onWebSocketPong(ByteBuffer payload) + { + events.add("onWebSocketPong(%s)", BufferUtil.toDetailString(payload)); + } + } + + /** + * Invalid Socket: Annotate 2 methods with interest in Binary Messages. + */ + @WebSocket + public static class BadDuplicateBinarySocket + { + /** + * First method + * + * @param payload the payload + * @param offset the offset + * @param len the len + */ + @OnWebSocketMessage + public void binMe(byte[] payload, int offset, int len) + { + /* ignore */ + } + + /** + * Second method (also binary) + * + * @param stream the input stream + */ + @OnWebSocketMessage + public void streamMe(InputStream stream) + { + /* ignore */ + } + } + + @WebSocket + public static class AnnotatedBinaryArraySocket + { + public EventQueue events = new EventQueue(); + + @OnWebSocketMessage + public void onBinary(byte[] payload, int offset, int length) + { + events.add("onBinary([%d],%d,%d)", payload.length, offset, length); + } + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); + } + + @OnWebSocketConnect + public void onConnect(Session sess) + { + events.add("onConnect(%s)", sess); + } + } + + @WebSocket + public static class AnnotatedBinaryStreamSocket + { + public EventQueue events = new EventQueue(); + + @OnWebSocketMessage + public void onBinary(InputStream stream) + { + assertThat("InputStream", stream, notNullValue()); + events.add("onBinary(%s)", stream); + } + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); + } + + @OnWebSocketConnect + public void onConnect(Session sess) + { + events.add("onConnect(%s)", sess); + } + } + + @WebSocket + public static class AnnotatedTextSocket + { + public EventQueue events = new EventQueue(); + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); + } + + @OnWebSocketConnect + public void onConnect(Session sess) + { + events.add("onConnect(%s)", sess); + } + + @OnWebSocketError + public void onError(Throwable cause) + { + events.add("onError(%s: %s)", cause.getClass().getSimpleName(), cause.getMessage()); + } + + @OnWebSocketMessage + public void onText(String message) + { + events.add("onText(%s)", TextUtil.quote(message)); + } + } + + @WebSocket + public static class AnnotatedTextStreamSocket + { + public EventQueue events = new EventQueue(); + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); + } + + @OnWebSocketConnect + public void onConnect(Session sess) + { + events.add("onConnect(%s)", sess); + } + + @OnWebSocketMessage + public void onText(Reader reader) + { + events.add("onText(%s)", reader); + } + } + + /** + * Invalid Socket: Annotate a message interest on a method with a return type. + */ + @WebSocket + public static class BadBinarySignatureSocket + { + /** + * Declaring a non-void return type + * + * @param session the session + * @param buf the buffer + * @param offset the offset + * @param len the length + * @return the response boolean + */ + @OnWebSocketMessage + public boolean onBinary(Session session, byte[] buf, int offset, int len) + { + return false; + } + } + + @WebSocket + public static class BadDuplicateFrameSocket + { + /** + * The get a frame + * + * @param frame the frame + */ + @OnWebSocketFrame + public void frameMe(org.eclipse.jetty.websocket.core.Frame frame) + { + /* ignore */ + } + + /** + * This is a duplicate frame type (should throw an exception attempting to use) + * + * @param frame the frame + */ + @OnWebSocketFrame + public void watchMe(org.eclipse.jetty.websocket.core.Frame frame) + { + /* ignore */ + } + } + + /** + * Invalid Socket: Annotate a message interest on a static method + */ + @WebSocket + public static class BadTextSignatureSocket + { + /** + * Declaring a static method + * + * @param session the session + * @param text the text message + */ + @OnWebSocketMessage + public static void onText(Session session, String text) + { + /* do nothing */ + } + } + + @WebSocket + public static class FrameSocket + { + /** + * A frame + * + * @param frame the frame + */ + @OnWebSocketFrame + public void frameMe(Frame frame) + { + /* ignore */ + } + } + + /** + * Test of constructing a new WebSocket based on a base class + */ + @WebSocket + public static class MyEchoBinarySocket extends MyEchoSocket + { + @OnWebSocketMessage + public void echoBin(byte[] buf, int offset, int length) + { + try + { + getRemote().sendBytes(ByteBuffer.wrap(buf, offset, length)); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + /** + * The most common websocket implementation. + *

+ * This version tracks the connection per socket instance and will + */ + @WebSocket + public static class MyEchoSocket + { + private Session session; + private RemoteEndpoint remote; + + public RemoteEndpoint getRemote() + { + return remote; + } + + @OnWebSocketClose + public void onClose(int statusCode, String reason) + { + this.session = null; + } + + @OnWebSocketConnect + public void onConnect(Session session) + { + this.session = session; + this.remote = session.getRemote(); + } + + @OnWebSocketMessage + public void onText(String message) + { + if (session == null) + { + // no connection, do nothing. + // this is possible due to async behavior + return; + } + + try + { + remote.sendString(message); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + /** + * Example of a stateless websocket implementation. + *

+ * Useful for websockets that only reply to incoming requests. + *

+ * Note: that for this style of websocket to be viable on the server side be sure that you only create 1 instance of this socket, as more instances would be + * wasteful of resources and memory. + */ + @WebSocket + public static class MyStatelessEchoSocket + { + @OnWebSocketMessage + public void onText(Session session, String text) + { + session.getRemote().sendString(text, null); + } + } + + /** + * The most basic websocket declaration. + */ + @WebSocket + public static class NoopSocket + { + /* intentionally do nothing */ + } + + /** + * (Test Case) + *

+ * Intentionally not specifying the @WebSocket annotation here + */ + public static class NotASocket + { + @OnWebSocketConnect + public void onConnect(Session session) + { + /* do nothing */ + } + } +} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java index 7672e7a1537..036fa6ea5da 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/JettyWebSocketFrameHandlerTest.java @@ -32,10 +32,6 @@ import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WebSocketConnectionListener; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerBasicSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerFrameSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerPartialSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerPingPongSocket; import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.CloseStatus; import org.eclipse.jetty.websocket.core.CoreSession; @@ -197,7 +193,7 @@ public class JettyWebSocketFrameHandlerTest public void testListenerPartialSocket() throws Exception { // Setup - ListenerPartialSocket socket = new ListenerPartialSocket(); + EndPoints.ListenerPartialSocket socket = new EndPoints.ListenerPartialSocket(); JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket); // Trigger Events @@ -228,7 +224,7 @@ public class JettyWebSocketFrameHandlerTest public void testListenerBasicSocket() throws Exception { // Setup - ListenerBasicSocket socket = new ListenerBasicSocket(); + EndPoints.ListenerBasicSocket socket = new EndPoints.ListenerBasicSocket(); JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket); // Trigger Events @@ -254,7 +250,7 @@ public class JettyWebSocketFrameHandlerTest public void testListenerBasicSocketError() throws Exception { // Setup - ListenerBasicSocket socket = new ListenerBasicSocket(); + EndPoints.ListenerBasicSocket socket = new EndPoints.ListenerBasicSocket(); JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket); // Trigger Events @@ -274,7 +270,7 @@ public class JettyWebSocketFrameHandlerTest public void testListenerFrameSocket() throws Exception { // Setup - ListenerFrameSocket socket = new ListenerFrameSocket(); + EndPoints.ListenerFrameSocket socket = new EndPoints.ListenerFrameSocket(); JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket); // Trigger Events @@ -304,7 +300,7 @@ public class JettyWebSocketFrameHandlerTest public void testListenerPingPongSocket() throws Exception { // Setup - ListenerPingPongSocket socket = new ListenerPingPongSocket(); + EndPoints.ListenerPingPongSocket socket = new EndPoints.ListenerPingPongSocket(); JettyWebSocketFrameHandler localEndpoint = newLocalFrameHandler(socket); // Trigger Events diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/LocalEndpointMetadataTest.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/LocalEndpointMetadataTest.java index 15f8bc40d9e..9c02961fa26 100644 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/LocalEndpointMetadataTest.java +++ b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/LocalEndpointMetadataTest.java @@ -19,21 +19,6 @@ package org.eclipse.jetty.websocket.common; import org.eclipse.jetty.websocket.api.InvalidWebSocketException; -import org.eclipse.jetty.websocket.common.endpoints.annotated.AnnotatedBinaryArraySocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.AnnotatedBinaryStreamSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.AnnotatedTextSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.AnnotatedTextStreamSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.BadBinarySignatureSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.BadDuplicateBinarySocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.BadDuplicateFrameSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.BadTextSignatureSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.FrameSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.MyEchoBinarySocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.MyEchoSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.MyStatelessEchoSocket; -import org.eclipse.jetty.websocket.common.endpoints.annotated.NoopSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerBasicSocket; -import org.eclipse.jetty.websocket.common.endpoints.listeners.ListenerFrameSocket; import org.eclipse.jetty.websocket.util.DuplicateAnnotationException; import org.eclipse.jetty.websocket.util.InvalidSignatureException; import org.eclipse.jetty.websocket.util.messages.ByteArrayMessageSink; @@ -85,7 +70,7 @@ public class LocalEndpointMetadataTest public void testAnnotatedBadDuplicateBinarySocket() throws Exception { // Should toss exception - Exception e = assertThrows(InvalidWebSocketException.class, () -> createMetadata(BadDuplicateBinarySocket.class)); + Exception e = assertThrows(InvalidWebSocketException.class, () -> createMetadata(EndPoints.BadDuplicateBinarySocket.class)); assertThat(e.getMessage(), allOf(containsString("Cannot replace previously assigned"), containsString("BINARY Handler"))); } @@ -96,7 +81,7 @@ public class LocalEndpointMetadataTest public void testAnnotatedBadDuplicateFrameSocket() throws Exception { // Should toss exception - Exception e = assertThrows(DuplicateAnnotationException.class, () -> createMetadata(BadDuplicateFrameSocket.class)); + Exception e = assertThrows(DuplicateAnnotationException.class, () -> createMetadata(EndPoints.BadDuplicateFrameSocket.class)); assertThat(e.getMessage(), containsString("Duplicate @OnWebSocketFrame")); } @@ -107,7 +92,7 @@ public class LocalEndpointMetadataTest public void testAnnotatedBadSignatureNonVoidReturn() throws Exception { // Should toss exception - Exception e = assertThrows(InvalidSignatureException.class, () -> createMetadata(BadBinarySignatureSocket.class)); + Exception e = assertThrows(InvalidSignatureException.class, () -> createMetadata(EndPoints.BadBinarySignatureSocket.class)); assertThat(e.getMessage(), containsString("must be void")); } @@ -118,7 +103,7 @@ public class LocalEndpointMetadataTest public void testAnnotatedBadSignatureStatic() throws Exception { // Should toss exception - Exception e = assertThrows(InvalidSignatureException.class, () -> createMetadata(BadTextSignatureSocket.class)); + Exception e = assertThrows(InvalidSignatureException.class, () -> createMetadata(EndPoints.BadTextSignatureSocket.class)); assertThat(e.getMessage(), containsString("must not be static")); } @@ -128,9 +113,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedBinaryArraySocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(AnnotatedBinaryArraySocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.AnnotatedBinaryArraySocket.class); - String classId = AnnotatedBinaryArraySocket.class.getSimpleName(); + String classId = EndPoints.AnnotatedBinaryArraySocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), EXISTS); assertThat(classId + ".binarySink", metadata.getBinarySink(), equalTo(ByteArrayMessageSink.class)); @@ -153,9 +138,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedBinaryStreamSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(AnnotatedBinaryStreamSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.AnnotatedBinaryStreamSocket.class); - String classId = AnnotatedBinaryStreamSocket.class.getSimpleName(); + String classId = EndPoints.AnnotatedBinaryStreamSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), EXISTS); assertThat(classId + ".binarySink", metadata.getBinarySink(), equalTo(InputStreamMessageSink.class)); @@ -178,9 +163,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedMyEchoBinarySocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(MyEchoBinarySocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.MyEchoBinarySocket.class); - String classId = MyEchoBinarySocket.class.getSimpleName(); + String classId = EndPoints.MyEchoBinarySocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), EXISTS); assertThat(classId + ".binarySink", metadata.getBinarySink(), equalTo(ByteArrayMessageSink.class)); @@ -203,9 +188,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedMyEchoSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(MyEchoSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.MyEchoSocket.class); - String classId = MyEchoSocket.class.getSimpleName(); + String classId = EndPoints.MyEchoSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -228,9 +213,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedMyStatelessEchoSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(MyStatelessEchoSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.MyStatelessEchoSocket.class); - String classId = MyStatelessEchoSocket.class.getSimpleName(); + String classId = EndPoints.MyStatelessEchoSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -253,9 +238,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedNoop() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(NoopSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.NoopSocket.class); - String classId = NoopSocket.class.getSimpleName(); + String classId = EndPoints.NoopSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -278,9 +263,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedOnFrame() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(FrameSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.FrameSocket.class); - String classId = FrameSocket.class.getSimpleName(); + String classId = EndPoints.FrameSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -303,9 +288,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedTextSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(AnnotatedTextSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.AnnotatedTextSocket.class); - String classId = AnnotatedTextSocket.class.getSimpleName(); + String classId = EndPoints.AnnotatedTextSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -328,9 +313,9 @@ public class LocalEndpointMetadataTest @Test public void testAnnotatedTextStreamSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(AnnotatedTextStreamSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.AnnotatedTextStreamSocket.class); - String classId = AnnotatedTextStreamSocket.class.getSimpleName(); + String classId = EndPoints.AnnotatedTextStreamSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); @@ -353,9 +338,9 @@ public class LocalEndpointMetadataTest @Test public void testListenerBasicSocket() { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(ListenerBasicSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.ListenerBasicSocket.class); - String classId = ListenerBasicSocket.class.getSimpleName(); + String classId = EndPoints.ListenerBasicSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), EXISTS); assertThat(classId + ".binarySink", metadata.getBinarySink(), equalTo(ByteArrayMessageSink.class)); @@ -378,9 +363,9 @@ public class LocalEndpointMetadataTest @Test public void testListenerFrameSocket() throws Exception { - JettyWebSocketFrameHandlerMetadata metadata = createMetadata(ListenerFrameSocket.class); + JettyWebSocketFrameHandlerMetadata metadata = createMetadata(EndPoints.ListenerFrameSocket.class); - String classId = ListenerFrameSocket.class.getSimpleName(); + String classId = EndPoints.ListenerFrameSocket.class.getSimpleName(); assertThat(classId + ".binaryHandle", metadata.getBinaryHandle(), nullValue()); assertThat(classId + ".binarySink", metadata.getBinarySink(), nullValue()); diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryArraySocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryArraySocket.java deleted file mode 100644 index 1f69bc65dce..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryArraySocket.java +++ /dev/null @@ -1,51 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.util.TextUtil; - -@WebSocket -public class AnnotatedBinaryArraySocket -{ - public EventQueue events = new EventQueue(); - - @OnWebSocketMessage - public void onBinary(byte[] payload, int offset, int length) - { - events.add("onBinary([%d],%d,%d)", payload.length, offset, length); - } - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); - } - - @OnWebSocketConnect - public void onConnect(Session sess) - { - events.add("onConnect(%s)", sess); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryStreamSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryStreamSocket.java deleted file mode 100644 index 31bb675172f..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedBinaryStreamSocket.java +++ /dev/null @@ -1,57 +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.common.endpoints.annotated; - -import java.io.InputStream; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.util.TextUtil; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; - -@WebSocket -public class AnnotatedBinaryStreamSocket -{ - public EventQueue events = new EventQueue(); - - @OnWebSocketMessage - public void onBinary(InputStream stream) - { - assertThat("InputStream", stream, notNullValue()); - events.add("onBinary(%s)", stream); - } - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); - } - - @OnWebSocketConnect - public void onConnect(Session sess) - { - events.add("onConnect(%s)", sess); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextSocket.java deleted file mode 100644 index ac273aae049..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextSocket.java +++ /dev/null @@ -1,58 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.util.TextUtil; - -@WebSocket -public class AnnotatedTextSocket -{ - public EventQueue events = new EventQueue(); - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); - } - - @OnWebSocketConnect - public void onConnect(Session sess) - { - events.add("onConnect(%s)", sess); - } - - @OnWebSocketError - public void onError(Throwable cause) - { - events.add("onError(%s: %s)", cause.getClass().getSimpleName(), cause.getMessage()); - } - - @OnWebSocketMessage - public void onText(String message) - { - events.add("onText(%s)", TextUtil.quote(message)); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextStreamSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextStreamSocket.java deleted file mode 100644 index d5e4b892e72..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/AnnotatedTextStreamSocket.java +++ /dev/null @@ -1,53 +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.common.endpoints.annotated; - -import java.io.Reader; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.util.TextUtil; - -@WebSocket -public class AnnotatedTextStreamSocket -{ - public EventQueue events = new EventQueue(); - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - events.add("onClose(%d, %s)", statusCode, TextUtil.quote(reason)); - } - - @OnWebSocketConnect - public void onConnect(Session sess) - { - events.add("onConnect(%s)", sess); - } - - @OnWebSocketMessage - public void onText(Reader reader) - { - events.add("onText(%s)", reader); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadBinarySignatureSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadBinarySignatureSocket.java deleted file mode 100644 index 3e80e10512b..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadBinarySignatureSocket.java +++ /dev/null @@ -1,45 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * Invalid Socket: Annotate a message interest on a method with a return type. - */ -@WebSocket -public class BadBinarySignatureSocket -{ - /** - * Declaring a non-void return type - * - * @param session the session - * @param buf the buffer - * @param offset the offset - * @param len the length - * @return the response boolean - */ - @OnWebSocketMessage - public boolean onBinary(Session session, byte[] buf, int offset, int len) - { - return false; - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateBinarySocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateBinarySocket.java deleted file mode 100644 index 65a8a53fcb7..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateBinarySocket.java +++ /dev/null @@ -1,55 +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.common.endpoints.annotated; - -import java.io.InputStream; - -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * Invalid Socket: Annotate 2 methods with interest in Binary Messages. - */ -@WebSocket -public class BadDuplicateBinarySocket -{ - /** - * First method - * - * @param payload the payload - * @param offset the offset - * @param len the len - */ - @OnWebSocketMessage - public void binMe(byte[] payload, int offset, int len) - { - /* ignore */ - } - - /** - * Second method (also binary) - * - * @param stream the input stream - */ - @OnWebSocketMessage - public void streamMe(InputStream stream) - { - /* ignore */ - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateFrameSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateFrameSocket.java deleted file mode 100644 index 38a9851c36e..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadDuplicateFrameSocket.java +++ /dev/null @@ -1,49 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; -import org.eclipse.jetty.websocket.core.Frame; - -@WebSocket -public class BadDuplicateFrameSocket -{ - /** - * The get a frame - * - * @param frame the frame - */ - @OnWebSocketFrame - public void frameMe(Frame frame) - { - /* ignore */ - } - - /** - * This is a duplicate frame type (should throw an exception attempting to use) - * - * @param frame the frame - */ - @OnWebSocketFrame - public void watchMe(Frame frame) - { - /* ignore */ - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadTextSignatureSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadTextSignatureSocket.java deleted file mode 100644 index c6572e83c1d..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/BadTextSignatureSocket.java +++ /dev/null @@ -1,42 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * Invalid Socket: Annotate a message interest on a static method - */ -@WebSocket -public class BadTextSignatureSocket -{ - /** - * Declaring a static method - * - * @param session the session - * @param text the text message - */ - @OnWebSocketMessage - public static void onText(Session session, String text) - { - /* do nothing */ - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/FrameSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/FrameSocket.java deleted file mode 100644 index 34218601b4a..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/FrameSocket.java +++ /dev/null @@ -1,38 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Frame; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketFrame; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -@WebSocket -public class FrameSocket -{ - /** - * A frame - * - * @param frame the frame - */ - @OnWebSocketFrame - public void frameMe(Frame frame) - { - /* ignore */ - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoBinarySocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoBinarySocket.java deleted file mode 100644 index ace78e4ec56..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoBinarySocket.java +++ /dev/null @@ -1,45 +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.common.endpoints.annotated; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * Test of constructing a new WebSocket based on a base class - */ -@WebSocket -public class MyEchoBinarySocket extends MyEchoSocket -{ - @OnWebSocketMessage - public void echoBin(byte[] buf, int offset, int length) - { - try - { - getRemote().sendBytes(ByteBuffer.wrap(buf, offset, length)); - } - catch (IOException e) - { - e.printStackTrace(); - } - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoSocket.java deleted file mode 100644 index 11eb9beadf3..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyEchoSocket.java +++ /dev/null @@ -1,78 +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.common.endpoints.annotated; - -import java.io.IOException; - -import org.eclipse.jetty.websocket.api.RemoteEndpoint; -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * The most common websocket implementation. - *

- * This version tracks the connection per socket instance and will - */ -@WebSocket -public class MyEchoSocket -{ - private Session session; - private RemoteEndpoint remote; - - public RemoteEndpoint getRemote() - { - return remote; - } - - @OnWebSocketClose - public void onClose(int statusCode, String reason) - { - this.session = null; - } - - @OnWebSocketConnect - public void onConnect(Session session) - { - this.session = session; - this.remote = session.getRemote(); - } - - @OnWebSocketMessage - public void onText(String message) - { - if (session == null) - { - // no connection, do nothing. - // this is possible due to async behavior - return; - } - - try - { - remote.sendString(message); - } - catch (IOException e) - { - e.printStackTrace(); - } - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyStatelessEchoSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyStatelessEchoSocket.java deleted file mode 100644 index d4aef194a4d..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/MyStatelessEchoSocket.java +++ /dev/null @@ -1,41 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * Example of a stateless websocket implementation. - *

- * Useful for websockets that only reply to incoming requests. - *

- * Note: that for this style of websocket to be viable on the server side be sure that you only create 1 instance of this socket, as more instances would be - * wasteful of resources and memory. - */ -@WebSocket -public class MyStatelessEchoSocket -{ - @OnWebSocketMessage - public void onText(Session session, String text) - { - session.getRemote().sendString(text, null); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NoopSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NoopSocket.java deleted file mode 100644 index 6c01d566ca7..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NoopSocket.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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.annotations.WebSocket; - -/** - * The most basic websocket declaration. - */ -@WebSocket -public class NoopSocket -{ - /* intentionally do nothing */ -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NotASocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NotASocket.java deleted file mode 100644 index 06c937b58ed..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/annotated/NotASocket.java +++ /dev/null @@ -1,36 +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.common.endpoints.annotated; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; - -/** - * (Test Case) - *

- * Intentionally not specifying the @WebSocket annotation here - */ -public class NotASocket -{ - @OnWebSocketConnect - public void onConnect(Session session) - { - /* do nothing */ - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerBasicSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerBasicSocket.java deleted file mode 100644 index 7afae82387d..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerBasicSocket.java +++ /dev/null @@ -1,60 +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.common.endpoints.listeners; - -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.WebSocketListener; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.util.TextUtil; - -public class ListenerBasicSocket implements WebSocketListener -{ - public EventQueue events = new EventQueue(); - - @Override - public void onWebSocketBinary(byte[] payload, int offset, int len) - { - events.add("onWebSocketBinary([%d], %d, %d)", payload.length, offset, len); - } - - @Override - public void onWebSocketClose(int statusCode, String reason) - { - events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); - } - - @Override - public void onWebSocketConnect(Session session) - { - events.add("onWebSocketConnect(%s)", session); - } - - @Override - public void onWebSocketError(Throwable cause) - { - events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); - } - - @Override - public void onWebSocketText(String message) - { - events.add("onWebSocketText(%s)", TextUtil.quote(message)); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerFrameSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerFrameSocket.java deleted file mode 100644 index b4d4ae3b524..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerFrameSocket.java +++ /dev/null @@ -1,55 +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.common.endpoints.listeners; - -import org.eclipse.jetty.websocket.api.Frame; -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.WebSocketFrameListener; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.util.TextUtil; - -public class ListenerFrameSocket implements WebSocketFrameListener -{ - public EventQueue events = new EventQueue(); - - @Override - public void onWebSocketClose(int statusCode, String reason) - { - events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); - } - - @Override - public void onWebSocketConnect(Session session) - { - events.add("onWebSocketConnect(%s)", session); - } - - @Override - public void onWebSocketError(Throwable cause) - { - events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); - } - - @Override - public void onWebSocketFrame(Frame frame) - { - events.add("onWebSocketFrame(%s)", frame.toString()); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPartialSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPartialSocket.java deleted file mode 100644 index 902681e84b3..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPartialSocket.java +++ /dev/null @@ -1,63 +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.common.endpoints.listeners; - -import java.nio.ByteBuffer; - -import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.WebSocketPartialListener; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.util.TextUtil; - -public class ListenerPartialSocket implements WebSocketPartialListener -{ - public EventQueue events = new EventQueue(); - - @Override - public void onWebSocketClose(int statusCode, String reason) - { - events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); - } - - @Override - public void onWebSocketConnect(Session session) - { - events.add("onWebSocketConnect(%s)", session); - } - - @Override - public void onWebSocketError(Throwable cause) - { - events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); - } - - @Override - public void onWebSocketPartialText(String payload, boolean fin) - { - events.add("onWebSocketPartialText(%s, %b)", TextUtil.quote(payload), fin); - } - - @Override - public void onWebSocketPartialBinary(ByteBuffer payload, boolean fin) - { - events.add("onWebSocketPartialBinary(%s, %b)", BufferUtil.toDetailString(payload), fin); - } -} diff --git a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPingPongSocket.java b/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPingPongSocket.java deleted file mode 100644 index 0260092904c..00000000000 --- a/jetty-websocket/websocket-jetty-common/src/test/java/org/eclipse/jetty/websocket/common/endpoints/listeners/ListenerPingPongSocket.java +++ /dev/null @@ -1,63 +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.common.endpoints.listeners; - -import java.nio.ByteBuffer; - -import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.websocket.api.Session; -import org.eclipse.jetty.websocket.api.WebSocketPingPongListener; -import org.eclipse.jetty.websocket.common.EventQueue; -import org.eclipse.jetty.websocket.core.CloseStatus; -import org.eclipse.jetty.websocket.util.TextUtil; - -public class ListenerPingPongSocket implements WebSocketPingPongListener -{ - public EventQueue events = new EventQueue(); - - @Override - public void onWebSocketClose(int statusCode, String reason) - { - events.add("onWebSocketClose(%s, %s)", CloseStatus.codeString(statusCode), TextUtil.quote(reason)); - } - - @Override - public void onWebSocketConnect(Session session) - { - events.add("onWebSocketConnect(%s)", session); - } - - @Override - public void onWebSocketError(Throwable cause) - { - events.add("onWebSocketError((%s) %s)", cause.getClass().getSimpleName(), TextUtil.quote(cause.getMessage())); - } - - @Override - public void onWebSocketPing(ByteBuffer payload) - { - events.add("onWebSocketPing(%s)", BufferUtil.toDetailString(payload)); - } - - @Override - public void onWebSocketPong(ByteBuffer payload) - { - events.add("onWebSocketPong(%s)", BufferUtil.toDetailString(payload)); - } -}