How to get Websockets working on tomcat 8

1,812 views
Skip to first unread message

Cory Showers

unread,
Jul 11, 2014, 5:24:28 PM7/11/14
to gran...@googlegroups.com
Using 3.1.0.RC1 release
Java 7 
Tomcat 8.0.9

I just deployed my web app on Tomcat 8 and wanted to see how to get websockets going.  I got an exception on startup
java.lang.ClassNotFoundException: org.apache.catalina.websocket.WebSocketServlet

Did some digging and tomcat deprecated this class on Tomcat 8.  my web.xml looks like the following.     Does 3.1.0.RC1  have tomcat 8 support?  My app works with Tomcat 7 but not 8
   <servlet-class>org.granite.gravity.tomcat.TomcatWebSocketServlet</servlet-class>  
      <!--  <servlet-class>org.granite.gravity.servlet3.GravityAsyncServlet</servlet-class>  -->

<load-on-startup>1</load-on-startup>

</servlet>
  <servlet-mapping>
<servlet-name>WebSocketServlet</servlet-name>
<url-pattern>/websocketamf/*</url-pattern>
</servlet-mapping>  

Cory Showers

unread,
Jul 16, 2014, 11:08:29 AM7/16/14
to gran...@googlegroups.com
Any ideas on this? Tomcat8 docs said WebSocketServlet is deprecated,   Also as per the RC1 release notes its says granite support JSR 356 Websockets on tomcat 7/8.   Do I have configuration wrong?
  • Websocket JSR 356 specification support on both client and server, for AMF and JMF. GraniteDS websockets now supports Jetty 8/9, Tomcat 7/8, GlassFish 3/4, WildFly 8 and Tyrus (client).

Cory Showers

unread,
Jul 16, 2014, 11:09:57 AM7/16/14
to gran...@googlegroups.com
I also noticed there is no tomcat8 server maven dependency but there is tomcat7/6 dependencies.

William Drai

unread,
Jul 16, 2014, 11:20:42 AM7/16/14
to gran...@googlegroups.com
Hi.
With Tomcat 8, you should be able to use the JSR 356 support.
The spec is quite different from servlets, so it's not any more a servlet definition, but you have to bootstrap it with this:

<listener>org.granite.gravity.websocket.GravityWebSocketDeployer</listener>




--

---
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Granite Data Services Forum".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse graniteds+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

William Drai

unread,
Jul 16, 2014, 11:23:28 AM7/16/14
to gran...@googlegroups.com
There is no specific support for Tomcat 8.
The tomcat7 jar should apply (except for websockets...).

In fact the org.granteds:granite-server maven dependency contains everything needed for most app servers.


Cory Showers

unread,
Jul 16, 2014, 1:17:36 PM7/16/14
to gran...@googlegroups.com
ahh ok.  So I should just remove the GravityServlet definition?  The only servlet definition in my web.xml should be the spring Dispatcher servlet.  and the new websocket listener.


<listener>org.granite.gravity.websocket.GravityWebSocketDeployer</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
 
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/graniteamf/*</url-pattern>
</servlet-mapping>

Cory Showers

unread,
Jul 16, 2014, 1:29:45 PM7/16/14
to gran...@googlegroups.com
made the change that did the trick.

thanks

Sharif El-Borgi

unread,
Aug 3, 2014, 4:15:39 AM8/3/14
to gran...@googlegroups.com
Cory would you mind posting an example of the web.xml!

For the life of me - i cannot work out how to get a simple websocket example going.

Thanks in advance
Sharif

Cory Showers

unread,
Aug 6, 2014, 12:08:57 AM8/6/14
to gran...@googlegroups.com
sure

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
            /WEB-INF/spring/app-config.xml
         </param-value>
</context-param>
  
<!-- Spring listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<listener>
<listener-class>org.granite.config.GraniteConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.granite.gravity.websocket.GravityWebSocketDeployer</listener-class>
</listener>

<!-- Spring MVC dispatcher servlet that handles incoming AMF requests on 
the /graniteamf endpoint -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/graniteamf/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>

Sharif El-Borgi

unread,
Aug 11, 2014, 9:36:11 AM8/11/14
to gran...@googlegroups.com
Did you only have a spring example. 

Im just trying to do a vanilla example where i can leverage the websockets.

Cory Showers

unread,
Aug 19, 2014, 9:14:43 AM8/19/14
to gran...@googlegroups.com
yes I haven't tried to do it using non spring projects
Reply all
Reply to author
Forward
0 new messages