Open glassfishrobot opened 11 years ago
@glassfishrobot Commented Reported by @nigeldeakin
@glassfishrobot Commented @nigeldeakin said: JMS 2.0 defines an injected JMSContext to have transaction scope if there is a current transaction, and request scope otherwise. However neither scope is available in a websocket tt>@OnMessage</tt or tt>@OnClose</tt callback.
This seems to be an inconsistency in the CDI specification. Although there is no valid HTTP request during the tt>@OnMessage</tt and tt>@OnClose</tt callbacks, CDI already widens the definition of tt>@RequestScoped</tt to cover cases which have no relationship with HTTP. For example CDI 1.0 states that a MDB's onMessage method is executed within a request scope, even though there is no HTTP request involved. Now that WebSockets are part of Java EE 7 (JSR 356), it seems a bit arbitrary for a MDB callback to have a valid request scope, but for a WebSocket callback to not be.
I have asked the CDI expert group to consider whether a future version of CDI should extend the definition of @RequestScoped to include a WebSocket @OnMessage callback. This is https://issues.jboss.org/browse/CDI-370
If no such change is made, the JMS expert group may need to consider whether any changes are needed to the definition of the scope of an injected JMSContext.
@glassfishrobot Commented genomeprjct said: A similar issue is currently floating around the CDI spec. This isn't an issue for CDI or JMS, but that WebSockets spec needs to indicate what contexts need to be activated (for example, regular CDI injections for any object that is request or transaction scoped are not injected either) for each of these annotated methods.
I haven't tested it yet, but I believe the work around will be to make your server endpoint a session bean (which makes it fall under the EJB spec) or to make the endpoint a standard CDI object.
Here's the link to the existing CDI issue: https://issues.jboss.org/browse/CDI-370
@glassfishrobot Commented miojo said: I tried that John and it does not work. A different instance is created to the CDI context, besides the one for the ws endpoint.
@glassfishrobot Commented @nigeldeakin said: Added link to WEBSOCKET_SPEC-196
@glassfishrobot Commented Issue-Links: is related to WEBSOCKET_SPEC-196
@glassfishrobot Commented This issue was imported from java.net JIRA JMS_SPEC-121
If you inject a JMSContext into a websocket ServerEndpoint you can use it in the tt>@OnOpen</tt callback, but if you attempt to use it from the tt>@OnMessage</tt or tt>@OnClose</tt callbacks you get an exception from the CDI container because there is no valid request scope or transaction scope. From a user perspective it would seem reasonable to expect to be able to use an injected JMSContext in these places.
Here's an example of a websocket ServerEndpoint that injects a JMSContext:
Affected Versions
[2.0]