6 Replies Latest reply on Sep 1, 2002 9:21 AM by Juha Lindfors

    invoking MDB from a servlet

    Ernst Newbie

      Can somebody help?

      I'm trying to have as servlet send a message to a MDB. This seems like a simple thing, but I can't get it to work.

      Here is the MDB code:

      public void onMessage(Message message) {
      try {
      System.out.println("treating message");
      TextMessage textMsg = (TextMessage) message;
      String collectionUri = textMsg.getText();
      //Directory dmsCollection = (Directory) dms.getDmsObject(collectionUri);
      //handleCollection(dmsCollection);
      //handleLegislations(dmsCollection);
      System.out.println("sending response");
      sendResponse(message,"ok");
      System.out.println("response sent");
      }
      catch (Exception e) {
      throw new EJBException(e);
      }
      }

      here is the ejb-jar.xml

      <ejb-jar>
      <display-name>CanliiDBJAR</display-name>
      <enterprise-beans>
      <message-driven>
      <display-name>DmsSynchronizationProcessEJB</display-name>
      <ejb-name>DmsSynchronizationProcessEJB</ejb-name>
      <ejb-class>org.canlii.ejb.DmsSynchronizationProcessEJB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Topic</destination-type>
      <subscription-durability>NonDurable</subscription-durability>
      </message-driven-destination>
      <security-identity>

      <run-as>

      <role-name>guest</role-name>
      </run-as>
      </security-identity>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      the jboss.xml

      <enterprise-beans>
      <message-driven>
      <ejb-name>DmsSynchronizationProcessEJB</ejb-name>
      <destination-jndi-name>topic/dmsTopic</destination-jndi-name>
      </message-driven>
      </enterprise-beans>


      when I deploy it I notice the following warning:
      WARNING element resource-env-ref not handled in WebApplicationContext[/dmstest, DmsSyncWAR]

      When I run the following code the bean isn't invoked:
      Context jndiContext = new InitialContext();
      TopicConnectionFactory topicFactory = (TopicConnectionFactory)
      jndiContext.lookup("java:comp/env/jms/TopicFactory");
      Topic dmsTopic = (Topic)
      jndiContext.lookup("java:comp/env/jms/Topic");
      TopicConnection connection = topicFactory.createTopicConnection();
      TopicSession session = connection.createTopicSession(true,0);
      TopicPublisher publisher = session.createPublisher(dmsTopic);
      TextMessage msg = session.createTextMessage("/collections/test");
      QueueConnectionFactory queueFactory = (QueueConnectionFactory)
      jndiContext.lookup("java:comp/env/jms/QueueFactory");
      QueueConnection queueConnection = queueFactory.createQueueConnection();
      QueueSession queueSession = queueConnection.createQueueSession(true,0);
      Queue replyQueue = queueSession.createTemporaryQueue();
      msg.setJMSReplyTo(replyQueue);
      QueueReceiver receiver = queueSession.createReceiver(replyQueue);
      System.out.println("sending message");
      publisher.publish(msg);
      queueConnection.start();
      System.out.println("receiving message");
      TextMessage response = (TextMessage) receiver.receive();
      System.out.println("got message");

      here is the web.xml file:
      <resource-env-ref>
      <resource-env-ref-name>jms/Topic</resource-env-ref-name>
      <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
      </resource-env-ref>
      <resource-ref>
      <res-ref-name>jms/TopicFactory</res-ref-name>
      <res-type>javax.jms.TopicConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <resource-ref>
      <res-ref-name>jms/QueueFactory</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      and the jboss-web.xml

      <jboss-web>
      <resource-env-ref>
      <resource-env-ref-name>jms/Topic</resource-env-ref-name>
      <jndi-name>topic/dmsTopic</jndi-name>
      </resource-env-ref>
      <resource-ref>
      <res-ref-name>jms/TopicFactory</res-ref-name>
      <jndi-name>ConnectionFactory</jndi-name>
      </resource-ref>
      <resource-ref>
      <res-ref-name>jms/QueueFactory</res-ref-name>
      <jndi-name>ConnectionFactory</jndi-name>
      </resource-ref>
      </jboss-web>

      Am I doing something wrong? Thanks,