Indeed, forward()
and include()
are meant to be used when processing a request. So they might not be the best option given what you want to achieve.
What you could do is create a third component, let's call it EventManager
for the time being, and have the Rest servlet signal changes to the EventManager
. The websocket, on the other hand, could be notified by the EventManager
that new data are available and then get that new data in order to write it back to the client.
In this approach it is essential that both the Rest servlet and the websocket servlet share the same instance of the EventManager
. You could achieve that by marking the EventManager
as a singleton EJB by adding the @Singleton
annotation, and inject it to both the Rest servlet and the websocket servlet.