Miserable Variable
Miserable Variable

Reputation: 28761

How to deploy Tomcat's example websocket applications?

I am trying understand how to deploy the examples referenced in the Apache Tomcat 7 WebSocket How-To page.

The Application Development section advises reading javadoc on WebSocketServlet class. But looking at the server side code of the examples, none of the classes in the three examples extend WebSocketServlet, which is what I had expected it to do.

I am returning to servlet development after over a decade and feeling quite lost with all the annotations in these examples. Is there another How-To that has step-by-step simple instructions for getting a WebSocket using servlet up and running?

Upvotes: 5

Views: 14785

Answers (2)

Ahmed Samir
Ahmed Samir

Reputation: 127

start tomcat and go to url

/examples/websocket/echo.xhtml

select one of the two options annotation or progammatic API change the url of the websocket to

/examples/websocket/echo.xhtml

and don't use the default that was in .

Upvotes: -1

Jacek Laskowski
Jacek Laskowski

Reputation: 74759

When you download the distribution of Apache Tomcat (7.0.37 is the latest version at the moment), you will have the examples web application already deployed. It comes with the WebSocket Examples. You don't have to deploy it yourself.

Start Tomcat and open http://localhost:8080/examples.

Apache Tomcat Examples

Click WebSocket Examples and pick whatever WebSocket example you want.

Apache Tomcat WebSocket Examples

You don't have to do anything other than to start Tomcat with bin/catalina.sh run (or whatever command works for you).

When you look into [TOMCAT_HOME]/webapps/examples directory, you may want to look at WEB-INF/web.xml where you see the WebSocket servlets deployed.

Their source code is in [TOMCAT_HOME]/WEB-INF/classes/websocket directory.

The servlet websocket.echo.EchoMessage does extend org.apache.catalina.websocket.WebSocketServlet.

I wonder if I should have asked you about the version of Apache Tomcat you use? Perhaps you use some other not-so-recent version? I recommend to start with the latest version as it worked fine for me.

Upvotes: 10

Related Questions