Issue #4691 - Use MethodHandles.lookup() consistently in WebSocket code.
* Using MethodHandles.publicLookup().in(...) instead of privateLookupIn(...). * Moved test WebSocket EndPoint classes into the proper package, otherwise they would not be accessible because the test package is not exported. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
6c5c98b266
commit
10f4fda0de
|
@ -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
|
||||
|
|
|
@ -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<String>
|
||||
public static class EndpointAdapter extends Endpoint implements MessageHandler.Whole<String>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Useful for websockets that only reply to incoming requests.
|
||||
* <p>
|
||||
* 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)
|
||||
* <p>
|
||||
* Intentionally not specifying the @WebSocket annotation here
|
||||
*/
|
||||
public static class NotASocket
|
||||
{
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(Session session)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 */
|
||||
}
|
||||
}
|
|
@ -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 */
|
||||
}
|
||||
}
|
|
@ -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 */
|
||||
}
|
||||
}
|
|
@ -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 */
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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.
|
||||
* <p>
|
||||
* Useful for websockets that only reply to incoming requests.
|
||||
* <p>
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -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 */
|
||||
}
|
|
@ -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)
|
||||
* <p>
|
||||
* Intentionally not specifying the @WebSocket annotation here
|
||||
*/
|
||||
public class NotASocket
|
||||
{
|
||||
@OnWebSocketConnect
|
||||
public void onConnect(Session session)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue