Reputation: 113
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
Upvotes: 4
Views: 31292
Reputation: 1
I also had the same problem. Try removing the unwanted jars which contains websocket in your $JAVA_HOME/lib folder. and then add only what you are importing in serverendpoint file.
Upvotes: -1
Reputation: 3718
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>
Upvotes: 7