3
votes

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

2
What happens when you visit ws://localhost:8080/WebsocketHome/actions via your browser ? - Bellash
I'm using latest Chrome and get "This webpage is not available" ERR_DISALLOWED_URL_SCHEME - sam

2 Answers

7
votes

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>
-1
votes

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.