2 Replies Latest reply on Feb 19, 2004 3:26 AM by wansbrough

    problem retrieving Topic from JNDI

    wansbrough Newbie

      I am trying to get a Topic to use with a MB.

      I am getting a ClassCastException, I have already noticed that others have got this problem too, but the the responses did not help my problem. And I have even bought a JBoss Administration book incase there was something I missed but all to no avail. Below I list the output,code,and xml that may help to find problem.

      OUTPUT
      Starting Client . . .
      Looking up the JMS destination(Topic) via JNDI.
      java.lang.ClassCastException
      java.lang.ClassCastException
      at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
      at day14.Client.main(Client.java:24)


      I am simply trying to get a topic using jndi.
      This is how I am running it:
      java -classpath C:\jboss-3.2.2\server\default\lib\jnpserver.jar;C:\jboss-3.2.2\lib\jboss-common.jar;C:\jboss-3.2.2\server\default\lib\jboss-j2ee.jar;C:\JavaStuff\EJB\day05\build day14.Client
      Should I being using the server jars for running the client? Are there client equivs somewhere?

      Below is my code:

      ###############################Client.java########

      package day14;
      
      import javax.jms.*;
      import javax.naming.*;
      import javax.ejb.*;
      import java.util.*;
      
      import day11.OrderHome;
      import day11.Order;
      
      public class Client {
      public static void main(String[] args)
      {
       print("Starting Client . . .");
       try
       {
       String orderVerifierJndiName = "topic/OrderVerifierTopic";
       //String orderVerifierJndiName = "testTopic";
       print("Looking up the JMS destination(Topic) via JNDI.");
       Context context = new InitialContext();
       //Topic topic = (javax.jms.Topic) context.lookup
       (OrderVerifierJndiName);
      
       Object o = context.lookup(orderVerifierJndiName);
       Topic topic = (Topic) javax.rmi.PortableRemoteObject.narrow
       (o,Topic.class);
       }
       catch(Exception ex) {
       System.err.println(ex);
       ex.printStackTrace();
       }
      }
      static void print(String s) {
       System.out.println(s);
      }
      }


      ##############################jboss.xml
      ........
      <message-driven>
      <ejb-name>OrderVerifierMDB</ejb-name>
      <destination-jndi-name>topic/OrderVerifierTopic</destination-jndi-name>
      <jndi-name>day14/OrderVerifierMDB</jndi-name>
      </message-driven>
      .
      ............
      ################################ejb-jar.xml
      ............
      <message-driven>
      <ejb-name>OrderVerifierMDB</ejb-name>
      <ejb-class>day14.OrderVerifierMDB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Topic</destination-type>
      <subscription-durability>NonDurable</subscription-durability>
      </message-driven-destination>
      </message-driven>
      ..........
      ###############################jbossmq-destinations-service.xml
      .........................

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


      .

        • 1. Re: problem retrieving Topic from JNDI
          kbutler Newbie

          Try adding reference to the JNDI provider on the cmd line:

          -Djava.naming.provider.url=jnp://localhost:1099
          -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

          Means you have to include the jbossall-client.jar (there's a JNDI subset somewhere also) in your classpath.

          • 2. Re: problem retrieving Topic from JNDI
            wansbrough Newbie

            I tried your suggestion

            Try adding reference to the JNDI provider on the cmd line:

            -Djava.naming.provider.url=jnp://localhost:1099
            -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

            Unfortunately still got the exact same ClassCastException.
            I also include and built the client with the client jars and it made no difference.

            I think I will download another appserver and try my luck with that. I have got session beans and entity beans to work fine but I am new to MBeans.