From c114e925ef9a116aeb187342b785ae1fdd80051a Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 8 May 2013 12:31:48 -0700 Subject: [PATCH] Using subprotocols (its more websockety) in example instead --- .../java/examples/MyAdvancedEchoCreator.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/jetty-websocket/websocket-servlet/src/test/java/examples/MyAdvancedEchoCreator.java b/jetty-websocket/websocket-servlet/src/test/java/examples/MyAdvancedEchoCreator.java index 5df436498c4..98789a1811c 100644 --- a/jetty-websocket/websocket-servlet/src/test/java/examples/MyAdvancedEchoCreator.java +++ b/jetty-websocket/websocket-servlet/src/test/java/examples/MyAdvancedEchoCreator.java @@ -37,11 +37,21 @@ public class MyAdvancedEchoCreator implements WebSocketCreator @Override public Object createWebSocket(UpgradeRequest req, UpgradeResponse resp) { - String[] type = req.getParameterMap().get("type"); - if ((type != null) && (type.length >= 1) && ("binary".equals(type[0]))) + for (String subprotocol : req.getSubProtocols()) { - return binaryEcho; + if ("binary".equals(subprotocol)) + { + resp.setAcceptedSubProtocol(subprotocol); + return binaryEcho; + } + if ("text".equals(subprotocol)) + { + resp.setAcceptedSubProtocol(subprotocol); + return textEcho; + } } - return textEcho; + + // No valid subprotocol in request, ignore the request + return null; } }