WebSocket Client in JBoss environment

Posted on

What is the recommended way of making outbound WebSocket connections from a Jakarte EE 10 environment, in particular JBoss EAP 8?

I would have expected that it would be possible to use CDI to obtain an instance of javax.websocket.WebSocketContainer, and then use its connectToServer() method to open a client connection. However, the WebSocketContainer appears not to be available via CDI.

The alternative mechanism of using ContainerProvider.getWebSocketContainer() fails out of the box, as no default ContainerProvider is available. Only when I explicitly enable a dependency on the private JBoss module io.undertow.websocket, does ContainerProvider.getWebSocketContainer() yield a usable instance (io.undertow.websockets.jsr.ServerWebSocketContainer).

Is there a better way of handling this, that does not require a private JBoss module to be used?