From f10a8a03a13b7659a887b2550a4e58d99d36a050 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Thu, 5 Sep 2019 15:30:09 +0300 Subject: Tests: Java websockets tests. --- test/java/websockets_mirror/app.java | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/java/websockets_mirror/app.java (limited to 'test/java/websockets_mirror') diff --git a/test/java/websockets_mirror/app.java b/test/java/websockets_mirror/app.java new file mode 100644 index 00000000..ada60231 --- /dev/null +++ b/test/java/websockets_mirror/app.java @@ -0,0 +1,57 @@ +import java.io.IOException; +import java.nio.ByteBuffer; + +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.PongMessage; +import javax.websocket.Session; +import javax.websocket.server.ServerEndpoint; + +@ServerEndpoint("/") +public class app { + + @OnOpen + public void onOpen(Session session) { + session.setMaxTextMessageBufferSize(8388608); + } + + @OnMessage + public void echoTextMessage(Session session, String msg) { + try { + if (session.isOpen()) { + session.getBasicRemote().sendText(msg, true); + } + } catch (IOException e) { + try { + session.close(); + } catch (IOException e1) { + // Ignore + } + } + } + + @OnMessage + public void echoBinaryMessage(Session session, ByteBuffer bb) { + try { + if (session.isOpen()) { + session.getBasicRemote().sendBinary(bb, true); + } + } catch (IOException e) { + try { + session.close(); + } catch (IOException e1) { + // Ignore + } + } + } + + /** + * Process a received pong. This is a NO-OP. + * + * @param pm Ignored. + */ + @OnMessage + public void echoPongMessage(PongMessage pm) { + // NO-OP + } +} -- cgit