Hi,

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

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


response.setAcceptedSubProtocol(subprotocol);


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:


session.getUpgradeResponse().getAcceptedSubProtocol();


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/ServletUpgradeResponse.java
b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
index ff6846f..b44daf7 100644
---
a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
+++
b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java
@@ -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);
+            }
             values.addAll(0,prepend);
         }

What do you think?

Best Regards,
Violeta Georgieva

[1]
https://www.eclipse.org/jetty/documentation/9.4.x/jetty-websocket-server-api.html
[2]
https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/ServletUpgradeResponse.java#L114
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to