glassfish
  1. glassfish
  2. GLASSFISH-20468

Can't send a JMS message from WebSocket's onMessage

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 4.0_b86_RC2
    • Fix Version/s: future release
    • Component/s: web_socket
    • Labels:
      None

      Description

      The following code fails to send an incoming WebSocket message to a JMS queue:

      @ServerEndpoint("/websocket")
      public class SampleWebSocket implements Serializable {
      
          @Resource(mappedName = "jms/myQueue")
          private Queue myQueue;
          @Inject
          private JMSContext jmsContext;
      
          @OnMessage
          public void onMessage(String message, Session client) {
              try {
                  jmsContext.createProducer().send(myQueue, message);
                  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "message sent to queue");
              } catch (RuntimeException ex) {
                  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "RE on websocket.onMessage", ex);
              }
          }
      }
      

      This is the exception (not logged by GF due to GLASSFISH-20467)

      SEVERE:   RE on websocket.onMessage
      org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
      	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:667)
      	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:74)
      	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
      	at org.glassfish.jms.injection.RequestedJMSContextManager$Proxy$_$$_WeldClientProxy.getType(Unknown Source)
      	at org.glassfish.jms.injection.InjectableJMSContext.delegate(InjectableJMSContext.java:126)
      	at org.glassfish.jms.injection.ForwardingJMSContext.createProducer(ForwardingJMSContext.java:61)
      	at org.glassfish.javaee7wsjms.SampleWebSocket.onMessage(SampleWebSocket.java:65)
      

      Because JMSContext is @RequestScoped, and a WebSocket message has the same behaviour as an HTTP request, it should be possible to use the injected JMSContext to send a message to a Queue from WebSocket.onMessage method.

      The following code works fine:

      @ServerEndpoint("/websocket")
      public class SampleWebSocket implements Serializable {
      
          @Resource(mappedName = "jms/myQueue")
          private Queue myQueue;
          @Resource(lookup = "java:comp/DefaultJMSConnectionFactory")
          private ConnectionFactory defaultConnectionFactory;
      
          @OnMessage
          public void onMessage(String message, Session client) {
              try (JMSContext context = defaultConnectionFactory.createContext();) {
                  context.createProducer().send(myQueue, message);
                  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "message sent to queue");
              } catch (RuntimeException ex) {
                  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "websocket.onMessage", ex);
              }
          }
      }
      

      This issue is also related to GLASSFISH-20371 (and it might influence JMS_SPEC-100)

        Activity

        Bruno Borges created issue -
        jjsnyder83 made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Duplicate [ 3 ]
        jjsnyder83 made changes -
        Resolution Duplicate [ 3 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        jjsnyder83 made changes -
        Fix Version/s future release [ 11148 ]
        jjsnyder83 made changes -
        Assignee jjsnyder83 [ jjsnyder83 ] phil.zampino [ phil.zampino ]
        jjsnyder83 made changes -
        Assignee phil.zampino [ phil.zampino ] dannycoward [ dannycoward ]
        Component/s jms [ 10604 ]
        Component/s cdi [ 10637 ]

          People

          • Assignee:
            dannycoward
            Reporter:
            Bruno Borges
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: