Search code examples
websocketjettyweld

Is it possible to set up Jetty with CDI for websockets?


I have managed to get weld CDI to work with jetty embedded for both servlets and rest. My question is: Is it possible to get CDI to work with WebSockets (JSR-356)?


Solution

  • CDI with javax.websocket is not well defined in the official JSR-356 spec, and wiring it up has proven sufficiently odd that each implementation is doing it differently, with different levels of support.

    (This is likely because the JSR-356 spec was written to be intentionally unconnected to Java EE and Servlet in general, allowing it to exist in non Java EE environments)

    There are a few open issues with it at the Jetty side.

    • 423647 - New Extensions should be created via ServletContextHandler.createInstance(Class)
    • 423645 - New ClientEndpointConfig.Configurators should be created via ServletContextHandler.createInstance(Class)
    • 423367 - New ServerApplicationConfig objects should be created via ServletContextHandler.createInstance(Class)
    • 423365 - New ServerEndpointConfig.Configurators should be created via ServletContextHandler.createInstance(Class)
    • 423364 - New Encoders should be created via ServletContextHandler.createInstance(Class)
    • 423363 - New Decoders should be created via ServletContextHandler.createInstance(Class)
    • 423336 - New Endpoints should be created via ServletContextHandler.createInstance(Class)

    I'm one of the maintainers of the websocket impl at Jetty, and would love to have someone help test the CDI integration (none of the Jetty developers themselves use CDI so its hard to get good, real-world, test cases to work against)