1
votes

I am following this tutorial to establish a WebSocket connection between java server and javascript client but I am facing below-mentioned error on the browser end

WebSocket connection to 'ws://localhost:8080/ws/echo' failed: Error during WebSocket handshake: Unexpected response code: 404

I am using tomcat 7.0.42 for Liferay and javax.websocket 1.1 jar

What I have tried :

  • changing scope of javax.websocket jar to provided - same error
  • using tomcat7.websocket - this cause my server to break down completely

PS: Some have suggested using tomcat 7.0.47 or above but I cant change the server for existing application this has to be done on tomcat 7.0.42

1
A 404 is a "Not Found" HTTP server code. It means the URL you hit caused the server to believe that the resource you requested was not where you told it to look. I would suggest looking into the URL you are using. Perhaps you typo'ed it or maybe the tutorial has it typo'ed? - CodeChimp
@CodeChimp I have checked it multiple times (different possible URL's) and also followed other tutorials but with all of them, the problem is same. In the url "/ws" represents the package name and "/echo" represents the endpoint - Abdul Ahad
Are you sure the ports are correct? Are you sure the EchoServer class is being loaded? Maybe try to put in a default constructor with a printout and see if it's being loaded at all? Again, the server will only 404 if it can't find the resource. Also, your URL doesn't match what I see in the tutorial, which is using ws://localhost:8080/EchoChamber/echo in the comments of the EchoServer. With most app servers, the first part is the deployment name (the JAR/WAR name), so in your example your JAR/WAR would be something like ws.jar or ws.war. - CodeChimp
the EchoChameber in tutorial is the name of the package containing the class EchoServer with the endpoint "/echo", I named my package "ws" the rest is same, also tried the war file name in combination with package name/url - Abdul Ahad
You need the /ws/ only if you define in your endpoint path or it's in your context root. It is not related to your package. The URL should be ws://localhost:8080/{context root if any}/echo. If your context root is empty (ie your "welcome page" is http://localhost:8080/), then ws://localhost:8080/echo is enough. If your context root is EchoChamber, your welcome page is http://localhost:8080/EchoChamber/ then your websocket URI is ws://localhost:8080/EchoChamber/echo - Al-un

1 Answers

0
votes

As per my understanding websocket is not supported on tomcat 7.0.42