WebSocket Handshake: Unexpected Response Code: 404 -

I learn about websites and follow the instructions here: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HomeWebsocket/WebsocketHome.html

I am using tomcat v8.0.21 to deploy my webapp, but I get the following error

My JavaScript project looks great when I visit webapp: my localhost and visit WebSocketJavaScriptProject

Although in the console window you will receive an error message: 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

The difference between my application and the example in Oracle is that I divided it as two projects into one service and another webapp.

I cannot understand why I get 404, because the .war service file is called WebsocketHome. Any ideas that might cause this problem? Usually 404 is not found, so he realizes that he canโ€™t find the service, I'm sure I'm doing something stupid, but I canโ€™t understand where the problem is

thanks

+3
source share
2 answers

A handshake error occurs because Tomcat has its own api for websockets. That way you could add a JSR implementation or something like javax.websocket-api in your pom.xml, a run-time conflict occurs.

Try not to export your Websocket library to your web server, so it uses its own implementation.

If you are using maven, specify 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> 
+7
source

I also had the same problem. Try removing unnecessary jars that contain websocket in the $ JAVA_HOME / lib folder. and then add only what you import in the serverendpoint file.

-one
source

All Articles