2 Replies Latest reply on Jun 19, 2004 11:32 AM by Stephane Nicoll

    Null ConnectionFactory

    pfonseca Newbie

      Hello all,

      I have a small problem in my first JMS client program. I have installed a fresh and clean JBoss 3.2.4 server, and without any further configuration, tried a little program, that is posted next.

      Can anybody please tell me why do i always get a null reference on context.lookup("ConnectionFactory") instruction ?

      I notice that ConnectionFactory appears on the JNDI object list of the Jmx Console.

      Regards
      Pedro F.



      QueueConnectionFactory queueFactory = null;
      QueueConnection queueConnection = null;
      QueueSession queueSession = null;
      QueueSender queueSender = null;
      Queue queue = null;
      Context context = null;
      Hashtable prop = new Hashtable();
      boolean bReply = false;
      Object factory = null;


      String sCommand = "Hello MSG!!";

      prop.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      prop.put("java.naming.factory.url", "localhost:1099");
      prop.put("javax.naming.rmi.security.manager", "no");
      prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
      prop.put(Context.PROVIDER_URL, "localhost:1099");
      context = new InitialContext(prop);

      factory = context.lookup("ConnectionFactory");
      if (factory == null) {
      throw new Exception("ConnectionFactory is null ...");
      }

      queue = (Queue)context.lookup("queue/A");
      if (queue == null) {
      throw new Exception("queue/A is null ...");
      }

      queueFactory = (QueueConnectionFactory)factory;
      queueConnection = queueFactory.createQueueConnection();
      queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      queueSender = queueSession.createSender(queue);


      TextMessage message = queueSession.createTextMessage();
      message.setText(sCommand);
      queueSender.send(queue, message);
      queueSession.close();
      queueConnection.close();

        • 1. Re: Null ConnectionFactory
          bushra Newbie

          Hello

          were u able to resolve that issue. I am facing the same problem of getting a nullpointer exception when i try to get the factory.

          Let me know if you could resolve this and if so how.

          regs
          Bushra

          • 2. Re: Null ConnectionFactory
            Stephane Nicoll Master

            If you're running your sample code inside JBoss you only need to create a default InitialContext object.

            Context context = new InitialContext();
            


            If you're running for a separate process, you need to set the property that are inside $JBOSS_HOME/server/default/conf/jndi.properties and only those

            Regards,

            Stephane