6 Replies Latest reply on Sep 6, 2005 9:22 AM by darranl

    ClassCastException on Queue JNDI lookup

    zhensley2

      Hello,
      I am getting a ClassCastException when trying to look up a Queue. I am getting the javax.naming.Reference type back instead of the javax.jms.Queue type.

      I am looking up the following queue definition.

      mbean code="org.jboss.mq.server.jmx.Queue"
      name="jboss.mq.destination:service=Queue,name=POSLog"
      depends optional-attribute-name="DestinationManager" jboss.mq:service=DestinationManager /depends
      /mbean


      the Exception is being generated when executing the following client code:

      obj = (Queue) jndiContext.lookup("queue/POSLog");

      and the jdni.properties file looks like:

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


      thank you for your help.

        • 1. Re: ClassCastException on Queue JNDI lookup
          genman

          jdni.properties -> jndi.properties ? You can turn on debug and see if you're actually talking to JBoss.

          • 2. Re: ClassCastException on Queue JNDI lookup
            anand.g.verma

            Hi
            I am also facing the same problem.
            I am using samples given in the JBoss distribution as per the JBossMQWiki.
            However when I use testQueue then I get ClassCastException and if I use queue A then I get Queue not bound exception.
            ==============================================
            Here is my code:

            Properties properties = new Properties();
            properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
            properties.put("java.naming.provider.url","jnp://localhost:1099");
            properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
            InitialContext ctx = new InitialContext(properties);
            log.info("Looking up queueA");
            Queue queue = (Queue) ctx.lookup("Queue/A");
            =============================================
            My jbossmq-destinations-service.xml

            <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager
            <depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager
            -1









            <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager

            ===============================================
            Please let me know if this is incorrect and if yes then what needs to be done.

            • 3. Re: ClassCastException on Queue JNDI lookup
              darranl

              If you are getting a ClassCastException post the Exception stack trace and message.

              • 4. Re: ClassCastException on Queue JNDI lookup
                anand.g.verma

                Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference
                at QClient.main(QClient.java:33)

                • 5. Re: ClassCastException on Queue JNDI lookup
                  anand.g.verma

                  I found the reason for this. It has nothing to do with ClassCastException actually.

                  The JMS client was not able to connect to JBoss server hence I was not getting the Queue type object and thus the ClassCastException.

                  Putting jbossall-client.jar in the classpath solved the problem.

                  • 6. Re: ClassCastException on Queue JNDI lookup
                    darranl

                    Yes the fact the ClassCastException mentions javax.naming.Reference is enough information to realise you had jars missing on your classpath.