2 Replies Latest reply on Jun 26, 2003 2:38 PM by Larry Farrar

    ConnectionFactory not Bound

    Larry Farrar Newbie

      Hi, I am running JBoss 3.2.1 and have stw, and stf for an answer, but no luck.

      I have RecursiveSearch set to true but still get the exception "ConnectionFactory" not bound.

      This is a remote client (Unix) trying to gain access to a queue on Windows 2000 Server. Cannot get it to work as a local client on the Windows Server either.

      Same code works fine on JBoss 3.0.4 locally - but not remotely(I get authenication errors).

      thanks in advance

      Code and exception:
      import javax.naming.InitialContext;
      import javax.naming.Context;
      import javax.naming.NamingException;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.Queue;
      import javax.jms.ConnectionFactory;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.ObjectMessage;
      import java.util.Properties;

      public class TestJmsClient
      {
      Properties env = null;
      Context jndiContext = null;
      QueueConnection qConn = null;
      Queue aQueue = null;
      QueueSession qSession = null;
      QueueSender qSender = null;
      ObjectMessage objMsg = null;

      public TestJmsClient()
      {
      env = new Properties();
      try
      {
      env.put(Context.PROVIDER_URL, "jnp://155.224.98.222:1099");
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
      jndiContext = new InitialContext(env);

      System.out.println("Got Initial Context");
      setupPTP();
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }

      private void setupPTP() throws JMSException, NamingException
      {
      Object ref = jndiContext.lookup("ConnectionFactory");
      if (ref == null)
      System.out.println("got null ref to ConnectionFactory");

      QueueConnectionFactory qcf = (QueueConnectionFactory) ref;
      qConn = qcf.createQueueConnection();
      aQueue = (Queue) jndiContext.lookup("queue/testQueue");
      qSession = qConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      qSender = qSession.createSender(aQueue);
      objMsg = qSession.createObjectMessage();
      System.out.println("Connected to testQueue");

      }

      public static void main(String [] args)
      {
      TestJmsClient client = new TestJmsClient();
      }
      }


      Got Initial Context
      javax.naming.NameNotFoundException: ConnectionFactory not bound
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:245)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
      at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
      at javax.naming.InitialContext.lookup(InitialContext.java:350)
      at TestJmsClient.setupPTP(TestJmsClient.java:53)
      at TestJmsClient.(TestJmsClient.java:43)
      at TestJmsClient.main(TestJmsClient.java:69)


        • 1. Re: ConnectionFactory not Bound
          ch_lakshmi Newbie

          I am migrating our app from jboss2.4.4 to jboss3.2.1 and I get the same error " Connection not bound"
          I used the sample code from JBoss documentation examples folder. ( listed below ).
          /*
          *
          * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
          *
          * This software is the proprietary information of Sun
          * Microsystems, Inc. Use is subject to license terms.
          *
          */
          /**
          * The SimpleTopicPublisher class consists only of a main method,
          * which publishes several messages to a topic.
          *
          * Run this program in conjunction with SimpleTopicSubscriber.
          * Specify a topic name on the command line when you run the
          * program. By default, the program sends one message.
          * Specify a number after the topic name to send that number
          * of messages.
          */
          import javax.jms.*;
          import javax.naming.*;
          import java.util.Properties;

          public class SimpleTopicPublisher {

          /**
          * Main method.
          *
          * @param args the topic used by the example and,
          * optionally, the number of messages to send
          */
          public static void main(String[] args) {
          String topicName = null;
          Context jndiContext = null;
          TopicConnectionFactory topicConnectionFactory = null;
          TopicConnection topicConnection = null;
          TopicSession topicSession = null;
          Topic topic = null;
          TopicPublisher topicPublisher = null;
          TextMessage message = null;
          final int NUM_MSGS;

          if ( (args.length < 1) || (args.length > 2) ) {
          System.out.println("Usage: java " +
          "SimpleTopicPublisher <topic-name> " +
          "[<number-of-messages>]");
          System.exit(1);
          }
          topicName = new String(args[0]);
          System.out.println("Topic name is " + topicName);
          if (args.length == 2){
          NUM_MSGS = (new Integer(args[1])).intValue();
          } else {
          NUM_MSGS = 1;
          }

          /*
          * Create a JNDI InitialContext object if none exists
          * yet.
          */
          try {
          Properties props = new Properties ();

          props.put ( Context.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");

          props.put ( Context.PROVIDER_URL, "localhost:1099" );
          props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
          jndiContext = new InitialContext(props);
          System.out.println("--------------- created JNDI context: "+jndiContext.getNameInNamespace());

          // NamingEnumeration enum = jndiContext.listBindings(jndiContext.toString());
          // while (enum.hasMore()) {
          // System.out.println("elem : "+((NameClassPair)enum.next()).toString());
          // }

          } catch (NamingException e) {
          System.out.println("Could not create JNDI " +
          "context: " + e.toString());
          e.printStackTrace();
          System.exit(1);
          }

          /*
          * Look up connection factory and topic. If either does
          * not exist, exit.
          */
          try {
          topic = (Topic) jndiContext.lookup("job");
          topicConnectionFactory = (TopicConnectionFactory)
          jndiContext.lookup("XAConnectionFactory");
          //topic = (Topic) jndiContext.lookup("job");
          } catch (NamingException e) {
          System.out.println("JNDI lookup failed: " +
          e.toString());
          e.printStackTrace();
          System.exit(1);
          }

          /*
          * Create connection.
          * Create session from connection; false means session is
          * not transacted.
          * Create publisher and text message.
          * Send messages, varying text slightly.
          * Finally, close connection.
          */
          try {
          topicConnection =
          topicConnectionFactory.createTopicConnection();
          topicSession =
          topicConnection.createTopicSession(false,
          Session.AUTO_ACKNOWLEDGE);
          topicPublisher = topicSession.createPublisher(topic);
          message = topicSession.createTextMessage();
          for (int i = 0; i < NUM_MSGS; i++) {
          message.setText("This is message " + (i + 1));
          System.out.println("Publishing message: " +
          message.getText());
          topicPublisher.publish(message);
          }
          } catch (JMSException e) {
          System.out.println("Exception occurred: " +
          e.toString());
          } finally {
          if (topicConnection != null) {
          try {
          topicConnection.close();
          } catch (JMSException e) {}
          }
          }
          }
          }

          Pl let me know if any solution is hit upon.
          Thanks
          Lakshmi Prasanna

          • 2. Re: ConnectionFactory not Bound
            Larry Farrar Newbie

            I ended up running the cluster version and everything worked just fine. The ConnectionFactory could be located and connections to queues/topics worked as prescribed. So I assumed that I had a configuration error and posted a question to the Installation and Configuration forum - http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=