4 Replies Latest reply on Jul 3, 2003 5:38 AM by mfrost

    ClassCastException looking up ConnectionFactory

    mfrost

      I'm trying to issue the following from my client app:

      Context context = new InitialContext();
      // Get the connection factory
      System.out.println("ConnectionFactory class name: " + context.lookup("ConnectionFactory").getClass().getName());

      QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");

      I get a ClassCastException. The actual class that comes back is a javax.naming.Reference??

      Inspecting my environment using the JNDIView MBean shows the following in both JNDI namespace and Global Namespace:

      +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)

      So why is the incorrect class being looked up?

      I'm running jboss-3.2.1_tomcat-4.1.24 from the server/default folder.

      Many thanks

        • 1. Re: ClassCastException looking up ConnectionFactory

          from where are you running this code? Inside JBoss or from a remote client?

          If remote, do not forget to add the jbossclient.jar in your classpath

          • 2. Re: ClassCastException looking up ConnectionFactory
            mfrost

            Yes i'm trying to run this from a remote client.

            I have the following in my classpath:

            jboss-client.jar
            log4j.jar
            jnp-client.jar
            jboss-common-client.jar

            my jndi properties are:

            java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
            java.naming.provider.url=jnp://127.0.0.1:1099/
            java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

            Basically, the JNDI lookup finds the name "ConnectionFactory" but the returned class is javax.naming.Reference. If I use the JNDI API's to list all the name-class pairs it correctly returns (amongst other entries):

            ConnectionFactory - org.jboss.mq.SpyConnectionFactory
            XAConnectionFactory - org.jboss.mq.SpyXAConnectionFactory

            I've tried looking up both ConnectionFactory and XAConnectionFactory but still ClassCastException.

            I can't get any of the JBOSS JMS client examples to run because of this problem! Help!

            Cheers

            Mark

            • 3. Re: ClassCastException looking up ConnectionFactory

              1/ Check that JMS starts fine (see the server.log of the default server)
              2/ Here's a code snipet that runs fine on my 3.2.1

              jndiContext = new InitialContext();
              queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("ConnectionFactory");
              queue = (Queue) jndiContext.lookup(queueName);
              queueConnection = queueConnectionFactory.createQueueConnection();
              queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

              my jndi properties are :

              java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
              java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
              java.naming.provider.url=127.0.0.1

              try to put everything in the client directory in your classpath.



              • 4. Re: ClassCastException looking up ConnectionFactory
                mfrost

                Finally got it to work!

                As you suggested I added jbossall-client.jar and it works fine now - phew!

                Any ideas why this is the case? I could understand a ClassNotFoundException being raised if I didn't have the right CLASSPATH but actually a different class returned from the JNDI lookup - weird!

                Maybe I just need to delve deeper into JNDI for an explanation.

                Anyway - many thanks for your help.

                Best regards

                mark