Closed linusheck closed 5 years ago
Hi @glatteis,
It seems to work fine for my chat-app. Could you create a minimal broken example repo?
Currently experiencing the same issue. When I reverted to 2.5.5 everything works excellently. What could be causing this issue in the latest 2.7 release .
I want to add that I have not solved this issue myself. A minimal example should be pretty trivial to build, I'll see what I can do. Might take a little while as I have other priorities right now :D
I had to same problem upgrading from 2.3 to 2.7.2 - my webapp would get a 404 trying to connect. What I noticed is that in 2.3, I had to my code setup as such: Server.java
webSocket("/logs", LogsWebSocketHandler.class);
index.html
var webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port + "/logs/");
Notice the trailing slash on /logs/
in the js code: the java code binds to /logs
but js to /logs/
. For some reason, that was fine before.
I've updated my js code to be:
var webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port + "/logs");
and everything is working fine now.
I tested on 2.5.5 as a sanity check, and both version of my js file work (js can connect using either /logs/
and /logs
). But on 2.7.x, the url has to match exactly.
I can confirm this trailing slash issue. In 2.5.4 I was using:
webSocket("/chat", WebSocketHandler.class);
in the server and
var webSocket = new WebSocket("ws://" + location.hostname + ":" + location.port + "/chat/");
in the client which was working fine. Then I switched to 2.8.0 (tested 2.6.0 and had the 404 issue as well) and I had to change the client to ".../chat"
!
It seems to be an issue with Jetty 9.4.x: https://github.com/eclipse/jetty.project/issues/1800 I was looking for hours to solve the problem by investigating this Jetty web.xml stuff until I found this comment about the slash O_o
Here is my websocket initialisation:
Here's my dummy websocket:
You cannot connect to the websocket if you are running sparkjava 2.7.1. I was very confused by this, and as a last resort I changed the number down to a version in which I have already used websockets, which is 2.5.5. The websocket works perfectly fine in 2.5.5.