3 Replies Latest reply on Dec 10, 2002 4:06 PM by Patrick Ryan

    Problem looking up ConnectionFactory on JBoss restart

    Patrick Ryan Newbie

      Hi Everyone,

      I am using JBoss3.0.4 with jdk1.4.1

      I have a simple test application with 2 jms clients using the topic/testTopic. If I start JBoss followed by the clients everything seems to run well.

      My problems come about when I try to make it tolerant of JBoss server restarts.

      If I stop / start JBoss, I have code in place which I thought would re-initialize the connection to JBoss. However I keep seeing the following exception in org.jnp.interfaces.NamingContext.lookUp line 466 in my debugger:

      java.rmi.ConnectException
      detail = java.net.ConnectException
      detailMessage = Connection refused: connect
      detailMessage = Connection refused to host: <my IP addr where jboss is running which happens to be local >



      Below are the methods I use to create the connection,sessions, etc as well as the onException method. The BOLD line below is the line that keeps failing.

      private void setupPubSub() throws Exception {




      try {
      try {
      // closing the connection will close all constituent objects...
      if( connection != null ) connection.close();
      } catch (JMSException e) {
      }

      Properties env = new Properties();
      // java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      // java.naming.provider.url=jnp://localhost:1099
      // java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      env.put(
      "java.naming.factory.initial",
      "org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.provider.url", "jnp://DSI1:1099");
      env.put(
      "java.naming.factory.url.pkgs",
      "org.jboss.naming:org.jnp.interfaces");

      jndi = new InitialContext(env);


      Object tmp = jndi.lookup("ConnectionFactory");

      if( tmp == null ) throw new Exception("Could NOT lookup ConnectionFactory from jndi IntialContext");
      // jms topic connection factory - you can type cast this to a QueueConnectionFactory as well
      TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;

      // Get a connection to the JMS service from the connection factory
      // all publishers and subscribers from this application can use the same connection
      connection = tcf.createTopicConnection(); // could take a username and password

      connection.setExceptionListener(this);
      // create a session for publishing and a session for subscribing
      pubSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
      subSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);

      // Look up JMS Topic
      Topic topic = (Topic) jndi.lookup("topic/testTopic");

      // Create a JMS Publisher
      publisher = pubSession.createPublisher(topic);


      // Create a subscriber
      TopicSubscriber subscriber = subSession.createSubscriber(topic, null, true);
      subscriber.setMessageListener(this);

      // start the connection - must be the last step
      connection.start();
      initialized = true;

      } catch (Exception e) {


      e.printStackTrace();
      throw e;
      }

      }



      public void onException(JMSException e) {

      System.out.println("@@@@@ On Exception called: " + e.getMessage());
      System.out.println("Trying to setup PubSub again...");
      try {
      setupPubSub();
      } catch (Exception e1) {
      System.out.println("in OnException setupPubSub threw exception: " + e1.getMessage());
      }
      }

      If anyone has any suggestions I sure would appreciate it.

        • 1. Re: Problem looking up ConnectionFactory on JBoss restart
          pradeep Newbie

          Hi,
          I am using Jboss3.0.4 and keep getting the following exception in my jboss console. But starngely there are no exception when in my client routines when I create topic connection using Topic Connection Factory.With jboss2.2 I used to configure the jbossmq-service.xml with ConnectionReceiverClass and Server Class. But I am not having any provision to define these classes in Jboss3.0 configuration file.Can this be a cause for my following exception.
          Thanks in Advance
          Deepoo


          16:59:48,171 ERROR [OILClientIL] Cannot connect to the ConnectionReceiver/Server

          java.net.SocketException: Option unsupported by protocol: connect
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:323)
          at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:136)
          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:123)
          at java.net.Socket.(Socket.java:273)
          at java.net.Socket.(Socket.java:127)
          at org.jboss.mq.il.oil.OILClientIL.createConnection(OILClientIL.java:175
          )
          at org.jboss.mq.il.oil.OILClientIL.checkSocket(OILClientIL.java:156)
          at org.jboss.mq.il.oil.OILClientIL.close(OILClientIL.java:72)
          at org.jboss.mq.server.JMSDestinationManager.connectionClosing(JMSDestin
          ationManager.java:572)
          at org.jboss.mq.server.JMSServerInterceptorSupport.connectionClosing(JMS
          ServerInterceptorSupport.java:112)
          at org.jboss.mq.security.ServerSecurityInterceptor.connectionClosing(Ser
          verSecurityInterceptor.java:50)
          at org.jboss.mq.server.TracingInterceptor.connectionClosing(TracingInter
          ceptor.java:150)
          at org.jboss.mq.server.JMSServerInvoker.connectionClosing(JMSServerInvok
          er.java:114)
          at org.jboss.mq.il.oil.OILServerILService$Client.run(OILServerILService.
          java:263)

          • 2. Re: Problem looking up ConnectionFactory on JBoss restart
            Jim Voris Newbie

            There is a bug in the 3.0.4 naming service code that makes it so a client cannot reconnect to a re-started JBoss server. The fix has already been checked in on the HEAD in CVS.

            See the file in the naming subsystem:

            org.jnp.interfaces.NamingContext.java around line 478.

            • 3. Re: Problem looking up ConnectionFactory on JBoss restart
              Patrick Ryan Newbie

              Thank you... I will look at getting the update