4 Replies Latest reply on Jul 15, 2008 11:05 PM by colintongzw

    ClassCastException on JNDI context.Lookup();

      I've got this constructor that does the EJB JNDI lookup but throws a ClassCastException when it trys to cast the lookup return Object to what it's suppose to be

      public ManageParticularAction(){
       super();
      
       Context context;
       IParticularManagerBeanLocal toto = null;
       try {
       context = new InitialContext();
       this.particularManagementService = (IParticularManagerBeanLocal)context.lookup("ParticularManagerBean/local");
       } catch (NamingException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       } catch ( Throwable t ){
       t.printStackTrace();
       }
      
       }
      


      In JBoss consol output, at startup, is shows that the ParticularManagerBean is instantiated.
      19:53:41,384 INFO [EJBContainer] STARTED EJB: com.kedc.ejb.session.services.ParticularManagerBean ejbName: ParticularManagerBean
      19:53:41,400 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=kedc_ejb-sessions.jar,name=PaymentScheduleManagerBean,service=EJB3 with dependencies:
      19:53:41,400 INFO [JmxKernelAbstraction] persistence.units:unitName=kedc
      
      


      thru debugging I foud that the Object that context.lookup() returns is an instance of class Proxy.

      Is this normal? If not, how do I correct the situation? If it's normal, then how to I cast the return Object from the context.lookup call?

      Thanks for the help.

        • 1. Re: ClassCastException on JNDI context.Lookup();
          jaikiran

           

          thru debugging I foud that the Object that context.lookup() returns is an instance of class Proxy.

          Is this normal?


          Yes, its normal. The proxy will implement the appropriate bean interface. Follow the steps mentioned at http://wiki.jboss.org/wiki/DisplayTheJNDITreeWithTheJMXConsole and see what object is bound to ParticularManagerBean/local jndi-name. If you are not able to understand the output from the JNDIView, post that output here (remember to wrap it in a code block while posting).




          • 2. Re: ClassCastException on JNDI context.Lookup();
            jaikiran

            Just re-read your post:

            IParticularManagerBeanLocal toto = null;
            try {
            context = new InitialContext();
            this.particularManagementService = (IParticularManagerBeanLocal)context.lookup("ParticularManagerBean/local");


            What's the type for this.particularManagementService? Shouldn't that be:

            IParticularManagerBeanLocal toto = null;
             try {
             context = new InitialContext();
             toto = (IParticularManagerBeanLocal)context.lookup("ParticularManagerBean/local");
            
            
            


            • 3. Re: ClassCastException on JNDI context.Lookup();
              dlarosa11

              I am having the same problem. I've seen this discussion all over the place dating back to 2002. My understanding is that there is no bug in jboss, it's just the way it is. However, I'd love to see a discussion of a workaround. The only one I've seen is to bundle everything in the same ear.

              In our situation, this is not possible. We have a server app which exposes our bean, and we want our customers to be able to create their own clients of it. There is no way we are going to get their apps in our ear.

              We need to be able to hot deploy our application and not have all the clients get a subsequent ClassCastException when doing a jndi lookup of our bean.

              Is the solution to redeploy all the clients after the server app with our bean is redeployed?

              I obviously can catch the exception, but I'm wondering what do I do about it once it's caught. Is there any way I can recover in my client app once I get this CastClassException when doing the jndi lookup? Can I force a reload of something so that I don't have to restart the client?

              Here's the diff of the JNDIView output of the relevant bean in our situation. Proxy90 is before the hot deploy of our server app and bean. Proxy145 is from after.

              Thanks for any and all help.

              < | +- local (proxy: $Proxy90 implements interface com.perimeter.anyswitch.IAnySwitchLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
              
              ---
              
              > | +- local (proxy: $Proxy145 implements interface com.perimeter.anyswitch.IAnySwitchLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
              
              
              


              • 4. Re: ClassCastException on JNDI context.Lookup();
                colintongzw

                notice the classloader,JBoss has changed to the Servlet spec classloading model, i.e. it uses the Tomcat classloader, you can make a try to use its classloader ,not tomcat's