Question

I'm trying to set up the "Echo" websocket example on Tomcat 8. I believe I am missing the step where you tell tomcat about the websocket classes.

Here's what I have done:

  • Created a new dynamic web project in Eclipse, added maven, and linked tomcat 8 runtimes
  • Copied EchoAnotation.java, EchoEndpoint.java, ExamplesConfig.java, and echo.xhtml into the project.
  • Started the app.

When I start the app, I can navigate to the echo.xhtml file, but no matter what url I enter, I can't seem to figure out how to get to web sockets--I always get 404. Putting breakpoints in the constructors, it looks like the websocket classes aren't being loaded.

Normally you set up the class configuration in web.xml or some other framework config, but I couldn't find a matching configuration in the examples web.xml on the Tomcat8 SVN (or any other xml.)

Any insight on how this is done?

Thanks!


Source Code

EchoAnotation.java, EchoEndpoint.java, ExamplesConfig.java Location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo

Echo.xhtml location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/

Example web.xml location:

http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/

My web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"> 
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>
Was it helpful?

Solution

Figured it out. Newest versions of war-based webapps do component scans automatically. Mine was not, because I had included this:

Do not include if you have tomcat included!

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

Reference on Websocket endpoints:

https://tyrus.java.net/documentation/1.3.3/index/deployment.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top