I don't understand why CDI use of injection doesn't work with websockets, using undertow.
Below is the code I have for a simple websocket endpoint.
@ServerEndpoint("/")
public class TestWebSocketEndpoint {
@Inject
private RetrieveAccessor retrieveAccessor;
private final Logger logger = Logger.getLogger(this.getClass().getName());
@OnOpen
public void onConnectionOpen(Session session) {
logger.info("Connection opened ... " + session.getId());
}
@OnMessage
public String onMessage(String message) {
if (!message.isEmpty()) {
return message;
}
System.out.println("RETRIEVE BEAN -> " + retrieveAccessor);
if (retrieveAccessor != null) {
return "BEAN NOT NULL";
}
return ":(";
}
@OnClose
public void onConnectionClose(Session session) {
logger.info("Connection close .... " + session.getId());
}
}
Of course the issue is that the injected property is null. I have no problems of course using the rest side of things for this deployment and injection of the stateless bean described below. Is there a work around for this, what are the problems I could run into if I just init properties I need that are beans? Because that definitely works.
RetrieveAccessor retrieveAccessor = new.... {code}