1 Reply Latest reply on Feb 10, 2003 3:23 AM by Bernd Zeitler

    Sending message from Session Bean

    Bart van Riel Newbie

      Hi,

      I'm trying to send a message to a queue from a session bean. The code in the session bean is:

      Context initial = new InitialContext();
      ....
      QueueConnectionFactory factory = (QueueConnectionFactory)initial.lookup("ConnectionFactory");

      Queue queue = (Queue)initial.lookup("java:comp/env/jms/MyQueue");
      ....

      The jndi-name of the queue is "test/qestQueue" (this is one of the preconfigured ones in the JBoss 3.04 download).

      Now here's the strange thing: from a standalone client, I can send messages fine (I have a MDB listening to the queue/testQueue queue and it reacts OK). From the session bean, the lookup of the queue throws a NullPointerException, "could not dereference object". Some fumbling with the 'looked up' name removes this error, but then a NamingException "queue not bound" is thrown.

      I'm sure it has something to do with entering the correct <resource-ref> info in ejb-jar.xml and jboss.xml. But what should I enter where, and how should I call the queue from the session bean?

      Thanx,
      Bart van Riel,
      The Netherlands.

        • 1. Re: Sending message from Session Bean
          Bernd Zeitler Expert

          Hi,

          your jboss.xml must have similar entries like this if you want to use JMS as a managed resource:
          [pre]
          <resource-manager>
          <res-name>managedQueueConnectionFactory</res-name>
          <res-jndi-name>java:JmsXA</res-jndi-name>
          </resource-manager>
          <resource-manager>
          <res-name>managedQueue</res-name>
          <res-jndi-name>queue/myQueue</res-jndi-name>
          </resource-manager>
          [/pre]
          This is a simple mapping of the originial jndi namespace to the component namespace (managed this time).

          You must use component namespace for lookup otherwise you will get the resource, but not managed.
          [pre]
          QueueConnectionFactory queueConnectionFactory =
          (QueueConnectionFactory) jndiContext.lookup("java:comp/env/managedQueueConnectionFactory");
          Queue queue = (Queue) jndiContext.lookup("java:comp/env/managedQueue");
          [/pre]

          Regards,

          Frito