WebSocket handshake: Unexpected response code: 404 -
The Error during the handshake happens, because Tomcat has its own api for websockets. Thus you might have added the JSR implementation or something similar as javax.websocket-api in your pom.xml there comes a conflict at runtime.
Try to not export your Websocket-library to your webserver, thus it uses its own implementation.
If you use maven, set the websocket dependency as provided:
<!-- Provided Websocket API, because tomcat has its own implementation -->
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
sam
Updated on July 21, 2020Comments
-
sam almost 4 years
I am learning about websockets and followed the instructions here: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html
I' using tomcat v8.0.21 to deploy my webapp but get the following error
My JavaScript Project looks fine, when I visit the webapp: my localhost and visit WebSocketJavaScriptProject
Although in the console window get the error: WebSocket connection to 'ws://localhost:8080/WebsocketHome/actions' failed: Error during WebSocket handshake: Unexpected response code: 404
My code lives here: https://github.com/darkcloudi/WebSocketProject
Difference between my app and the example on Oracle is I have split it as two projects one service and the other webapp.
I cannot figure out why I would be getting a 404 as the service .war file is called WebsocketHome. Any ideas what would be causing this issue? Usually a 404 is not found so guessing it cannot finding the service , i'm sure i'm doing something stupid but cannot figure out where the problem is
Thanks
-
sam almost 9 yearsThanks for responding. So I tried what you suggested and it worked. Thanks :) I can see in the console that I get Status Code:101 Switching Protocols so thats good. But now get a different error in the logs (see below), need to look into why, main thing the service is running. 08-Jun-2015 20:40:31.276 SEVERE [http-nio-8080-exec-13] org.example.websocket.DeviceWebSocketServer.onError null java.lang.NullPointerException
-
sam almost 9 yearsAppears the first error is when its opening connection so need to do some more debugging. duffy - thanks again as I never realised that Tomcat had its own implementation. 08-Jun-2015 20:55:41.287 SEVERE [http-nio-8080-exec-26] org.example.websocket.DeviceWebSocketServer.onError null java.lang.NullPointerException at org.example.websocket.DeviceWebSocketServer.open(DeviceWebSocketServer.java:29)
-
Ishmael almost 8 yearsThis is the holy grail of answers. I've spent days finding this answer.
-
raksheetbhat almost 6 yearsThis isn't helpful.
-
Abdul Majid Bajwa about 5 yearsThanks buddy. I was added wesocket api jar and also add this jar in deployment assembly. But I should add websocket api for compile time usage but for runtime I need to remove from deployment assembly as TOMCAT server have already contain websocket api. Great help man thanks