Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Accepted subprotocol is not provided when @OnWebSocketConnect method is invoked


I'm following the example [1] for Jetty WebSocket Server API.

In my WebSocketCreator implementation I'm setting the accepted subprotocol to the response:


Then in my @WebSocket implementation, I expect in the method annotated with @OnWebSocketConnect when I call
the statement below to receive the subprotocol that was set earlier by the WebSocketCreator:


With the latest available Jetty 9.4.x this call returns "null".

I think that the following line [2] causes this "null" to be returned. When the specified key is not available in the map, the default is returned, but this default is not added to the map.

With the patch below when I call getAcceptedSubProtocol, the expected value is returned.

diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/
index ff6846f..b44daf7 100644
--- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/
+++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/
@@ -111,7 +111,12 @@ public class ServletUpgradeResponse implements UpgradeResponse
             String name = entry.getKey();
             Collection<String> prepend = entry.getValue();
-            List<String> values = headers.getOrDefault(name,headers.containsKey(name)?null:new ArrayList<>());
+            List<String> values = headers.get(name);
+            if (values==null)
+            {
+                values = new ArrayList<>();
+                headers.put(name,values);
+            }
What do you think?

Best Regards,
Violeta Georgieva


Back to the top