2 Replies Latest reply on Aug 23, 2005 12:02 PM by nishanth

    Help needed for running a client to access MDB

    nishanth

      hello there,

      i have deployed the MDB application in JBOSS using Intellij idea. When i run the client program i get the following error i have been trying it for the whole weekend but still i didnot get the output

      any help would be appreciable

      my ejbjar file is
      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar
      PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
      "http://java.sun.com/dtd/ejb-jar_2_0.dtd"
      >

      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>TextMDB</ejb-name>
      <ejb-class>org.jboss.chap4.ex2.TextMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      <resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>


      my jbossxml is

      <?xml version="1.0"?>

      <enterprise-beans>
      <message-driven>
      <ejb-name>TextMDB</ejb-name>
      <destination-jndi-name>queue/B</destination-jndi-name>
      <resource-ref>
      <res-ref-name>jms/QCF</res-ref-name>
      <jndi-name>QueueConnectionFactory</jndi-name>
      </resource-ref>
      </message-driven>
      </enterprise-beans>



      my client program is

      package org.jboss.chap4.ex2;


      /**
      * Created by IntelliJ IDEA.
      * User: ian
      * Date: Aug 21, 2005
      * Time: 2:10:56 AM
      * To change this template use File | Settings | File Templates.
      */

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.TextMessage;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.naming.Context;

      import EDU.oswego.cs.dl.util.concurrent.CountDown;

      import java.util.Properties;

      /** A complete JMS client example program that sends N
      TextMessages to a Queue B and asynchronously receives the
      messages as modified by TestMDB from QueueB.

      @author Scott.Stark@jboss.org
      @version $Revision:$
      */
      public class SendRecvClient
      {
      static final int N = 10;
      static CountDown done = new CountDown(N);
      QueueConnection conn;
      QueueSession session;
      Queue queA;
      Queue queB;

      public static class ExListener implements MessageListener
      {
      public void onMessage(Message msg)

      {
      System.out.println("====> comes to the on message method");
      done.release();
      TextMessage tm = (TextMessage) msg;
      try
      {
      System.out.println("onMessage, recv text="+tm.getText());
      }
      catch(Throwable t)
      {
      t.printStackTrace();
      }
      }
      }

      public void setupPTP()
      throws JMSException, NamingException
      {
      // System.out.println("comes to thisptp method aswell");
      //Properties env = new Properties();
      Properties properties = new Properties();
      properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      properties.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
      properties.put(Context.PROVIDER_URL,"jnp://localhost:1099");




      //System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      //System.setProperty("java.naming.provider.url","localhost:1099");
      //System.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      // System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      //System.setProperty("java.naming.provider.url","localhost:1099");

      //java.util.Hashtable env = new java.util.Hashtable();
      //env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      //env.put(javax.naming.Context.PROVIDER_URL,"jnp://localhost:1099");
      //env.put(javax.naming.Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
      InitialContext iniCtx = new InitialContext(properties);
      // InitialContext iniCtx = new InitialContext();
      System.out.println("comes to thisptp method aswell");
      Object tmp = iniCtx.lookup("QueueConnectionFactory");
      System.out.println("comes to thisptp method aswell");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      queA = (Queue) iniCtx.lookup("queue/A");

      queB = (Queue) iniCtx.lookup("queue/B");
      session = conn.createQueueSession(false,
      QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }

      public void sendRecvAsync(String textBase)
      throws JMSException, NamingException, InterruptedException
      {
      System.out.println("Begin sendRecvAsync");
      // Setup the PTP connection, session
      setupPTP();
      // Set the async listener for queA
      QueueReceiver recv = session.createReceiver(queA);
      recv.setMessageListener(new ExListener());
      // Send a few text msgs to queB
      QueueSender send = session.createSender(queB);
      for(int m = 0; m < 10; m ++)
      {
      TextMessage tm = session.createTextMessage(textBase+"#"+m);
      tm.setJMSReplyTo(queA);
      send.send(tm);
      System.out.println("sendRecvAsync, sent text="+tm.getText());
      }
      System.out.println("End sendRecvAsync");
      }

      public void stop() throws JMSException
      {
      conn.stop();
      }

      public static void main(String args[]) throws Exception
      {
      SendRecvClient client = new SendRecvClient();
      client.sendRecvAsync("A text msg");
      client.done.acquire();
      client.stop();
      System.exit(0);
      }

      }


      the following error is what i get when i run the client

      javax.naming.NameNotFoundException: QueueConnectionFactory not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:505)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:278)
      at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:534)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:544)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at org.jboss.SendRecvClient.setupPTP(SendRecvClient.java:93)
      at org.jboss.SendRecvClient.sendRecvAsync(SendRecvClient.java:111)
      at org.jboss.SendRecvClient.main(SendRecvClient.java:135)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
      Exception in thread "main"
      Process finished with exit code 1


      thank you in advance!!