Info: WebSocket connection closed, Code: 1006 while trying to run websocket samples

I've embedded tomcat 8.0.20 and using that in my server. I build the tomcat websocket example and when I'm trying to run it in my server for all 4 examples (Echo, chat, etc..) I'm getting

Info: WebSocket connection closed, Code: 1006

In the console it prints something like (url is correct per sample)

WebSocket connection to 'ws://localhost:9763/examples/websocket/echoProgrammatic' failed: Error during WebSocket handshake: Unexpected response code: 302

When I deploy this on tomcat it shows 404 error instead of 302.

Can someone tell me what could be the reason for this?

In the pom, my dependency is as follows

 <dependency>
     <groupId>javax.websocket</groupId>
     <artifactId>javax.websocket-api</artifactId>
     <version>1.0</version>
     <scope>provided</scope>
 </dependency>

It seems that websocket implementations are not get deployed correctly. Can somebody help?

Upvotes: 4

Views: 2873

Answers (2)

Konstantin Kolinko
Konstantin Kolinko

Reputation: 3946

<dependency> <groupId>javax.websocket</groupId> <artifactId>javax.websocket-api</artifactId> <version>1.0</version> <scope>provided</scope> </dependency>

Use websocket API and websocket Implementation provided by Tomcat (groupId: org.apache.tomcat), instead of some random third-party jar.

You can either search Maven or look the pom files in the res/maven directory of the source thee.

Scope "provided" means that the jar is only used at compile time, not at run time.

BTW, current versions of Tomcat implement WebSocket 1.1.

Scanning for websocket endpoints is triggered by an implementation of javax.servlet.ServletContainerInitializer (as configured in META-INF/services/javax.servlet.ServletContainerInitializer file of tomcat-websocket.jar).

Upvotes: 4

This was totally a mistake. In the tomcat example all the URLS are hard coded with examples but my context is example(without s). That was a mistake.

Upvotes: 0

Related Questions