jakartaee / jakartaee/messaging
Injection of JMSContext objects not possible in a WebSocket @OnMessage or @OnClose callback method
- Dominant language
- Java
- Stars
- 49
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
If you inject a JMSContext into a websocket ServerEndpoint you can use it in the @OnOpen callback, but if you attempt to use it from the @OnMessage or @OnClose 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:
```
@ServerEndpoint("/websocket")
public class SampleWebSocket {
@Resource(lookup="java:comp/DefaultJMSConnectionFactory") ConnectionFactory cf;
@Resource(lookup = "jms/myQueue") Queue myQueue;
@Inject
private JMSContext jmsContext;
@OnOpen
public void onOpen(final Session session) {
// works OK as there is a valid request scope here
context.createProducer().send(myQueue, message);
}
@OnMessage
public void onMessage(final String message, final Session client) {
// fails as there is no valid request scope here
context.createProducer().send(myQueue, message);
}
@OnClose
public void onClose(final Session session) {
// fails as there is no valid request scope here
context.createProducer().send(myQueue, message);
}
```
#### Affected Versions
[2.0]
Contributor guide
Research direction
Start by reproducing the issue from the ServerEndpoint example in the body, comparing injected JMSContext behavior in @OnOpen, @OnMessage, and @OnClose callbacks on the affected 2.0 version. Determine the required request and transaction scope behavior for each callback; done means the callbacks can use the injected context without the CDI scope exception, with coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100