Current best way to use websockets with DropWizard

2,006 views
Skip to first unread message

joshg

unread,
Jun 27, 2017, 8:35:05 PM6/27/17
to dropwizard-user
What's the recommended way to use websockets with DropWizard?  
Everything I've tried either can't use websockets and falls back to long polling or throws an exception about not being able to find WebSocketServerFactory in the classpath.

Douglas Patriarche

unread,
Jun 28, 2017, 3:55:31 PM6/28/17
to dropwizard-user
I can't say whether it's the "recommended" way, but here's what my project does:
  • Since Dropwizard is based on Jetty, it seemed like a good idea to stick with Jetty's websocket implementation.
  • Include the Jetty websocket server on your server side (using the same Jetty version as your Dropwizard package depends on):
        <dependency>
           
<groupId>org.eclipse.jetty.websocket</groupId>
           
<artifactId>websocket-server</artifactId>
           
<version>9.4.2.v20170220</version>
       
</dependency>

  • If you are using a Java client, include the Jetty websocket client:
        <dependency>
           
<groupId>org.eclipse.jetty.websocket</groupId>
           
<artifactId>websocket-client</artifactId>
           
<version>9.4.2.v20170220</version>
       
</dependency>

  • Follow the Jetty websocket documentation to implement.
  • Implementing websockets was not trivial, so give yourself some time to experiment and refactor.
I hope that helps,
Doug

jpl...@gmail.com

unread,
Jun 28, 2017, 8:39:51 PM6/28/17
to dropwizard-user
Similar to what Doug suggested, but https://github.com/LivePersonInc/dropwizard-websockets may do what you are looking for.  I also found https://github.com/WhisperSystems/WebSocket-Resources

-Justin


On Tuesday, June 27, 2017 at 8:35:05 PM UTC-4, joshg wrote:
Reply all
Reply to author
Forward
0 new messages