diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2019-09-05 15:30:09 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2019-09-05 15:30:09 +0300 |
commit | f10a8a03a13b7659a887b2550a4e58d99d36a050 (patch) | |
tree | e10ac5ce622b22231cf65c877f6879dba2d15dfd /test/java/websockets_mirror | |
parent | 2b8cab1e2478547398ad9c2fe68e025c180cac54 (diff) | |
download | unit-f10a8a03a13b7659a887b2550a4e58d99d36a050.tar.gz unit-f10a8a03a13b7659a887b2550a4e58d99d36a050.tar.bz2 |
Tests: Java websockets tests.
Diffstat (limited to '')
-rw-r--r-- | test/java/websockets_mirror/app.java | 57 |
1 files changed, 57 insertions, 0 deletions
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 + } +} |