getOrDefault in WebSocketConnection.java always returns the default value
See original GitHub issueIn line 646 of the file WebSocketConnection.java,
String protocol = getOrDefault(serverHandshake.headers,
"Sec-WebSocket-Protocol", null);`
the function getOrDefault
is called. This function then checks if (obj.containsKey(key)
and returns the value if the key is present or the default value otherwise.
We had the key Sec-WebSocket-Protocol
in our map (I printed the map within this function as well) and it was set to the value wamp.2.cbor
. However, the if condition never gets executed and the default value (null) is always returned.
I am not sure what might be causing this issue. I fixed it temporarily by making the function return wamp.2.cbor
instead of the default value for the time being (but that won’t work for everyone obviously).
This is also the root cause of the issue #420 (and probably even #146 ). Atleast, I can tell that from my experience of forking this library and figuring out this issue (which took multiple hours), this is the root issue!
I don’t know what sorcery this is or how this could be fixed but yes, this is a completely real issue and this was the root cause of our development being stuck for more than a week. And this, THIS was the main issue. Changing this one line of code fixed the entire thing!
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
I was having similar problem today. In my case, I’m using Caddy as a server, which proxies requests to nexus router. Problem was that Caddy returns HTTP headers in different case, instead of
Sec-WebSocket-Protocol
, it returnsSec-Websocket-Protocol
(notice lowecase S). I came to conclusion, that it’s autobahn-java problem, because it relies on header key case, when it should not.As a workaround, I’ve added these lines in ServerHandshake.java:
and changed all hardcoded header strings in other files into lowercase.
@om26er I’ll share some sample code and logs with you tomorrow (it’s past 2 am here:)
This issue seems to happen in both the latest and the 2nd latest version of the library. I had downloaded the zip of your latest release v19.3.1 to debug this issue. The mobile OS - Android Pie (Absurd 9.0 and also on Android N)