2 Replies Latest reply on Jul 12, 2007 3:41 AM by andixt

    Cast fails after successful JNDI lookup

    mikeperik

      I'm using NetBeans with JBoss to develop two services. One service uses the second one. I am using NetBeans 5.5 and JBoss 4.0.5 on linux

      The JMX Management Console shows the two apps

      basketmanager
      app=ejb3
      service=BasketManager
      service=FTPConnection
      fixendpoint
      app=ejb3
      service=FixEndPointManager

      I have a JBoss management interface for the FixEndPointManager application and when it is invoked the management interface is able to lookup and call the methods on the Remote interface successfully.

      I also have a JBoss management interface for the BasketManager and when I invoke the methods that will use the FixEndPointManager interface methods the lookup fails with a ClassClassException.

      Caused by: java.lang.ClassCastException: $Proxy100
      at com.foxriver.basket.impl.BasketBean.lookupEndPointManagerBean(BasketBean.java:152)
      at com.foxriver.basket.impl.BasketBean.executeOrder(BasketBean.java:97)


      If I look at the JNDIView I find the remote interface bound to $Proxy100

      +- FixEndPoint (class: org.jnp.interfaces.NamingContext)
      | +- FixEndPointManagerMBean (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy104 implements interface com.foxriver.fix.jboss.FixEndPointManagerMBeanInterface,interface org.jboss.ejb3.JBossProxy)
      | +- FixEndPointManagerBean (class: org.jnp.interfaces.NamingContext)
      | | +- local (proxy: $Proxy101 implements interface com.foxriver.fix.api.FixEndPointManagerLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
      | | +- remote (proxy: $Proxy100 implements interface com.foxriver.fix.api.FixEndPointManagerRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)

      Here is my code for looking up the remote interface:
      private FixEndPointManagerRemote lookupEndPointManagerBean() {
      try {
      javax.naming.Context c = new javax.naming.InitialContext();
      Object obj = c.lookup("FixEndPoint/FixEndPointManagerBean/remote");
      Logger.getLogger(getClass().getName()).log(Priority.DEBUG, "Bean Class: " + obj.getClass().getName());
      Logger.getLogger(getClass()).log(Priority.INFO, "Proxy instanceof FixEndPointManagerBean " + String.valueOf(obj instanceof FixEndPointManagerRemote) );
      return (FixEndPointManagerRemote) obj;
      }
      catch(javax.naming.NamingException ne) {
      Logger.getLogger(getClass().getName()).log(Priority.ERROR,"exception caught" ,ne);
      throw new RuntimeException(ne);
      }
      }

      The instanceof check on 'obj' returns false, but if I attach the debugger and set a break point after the lookup and look at 'obj' I see FixEndPointManagerRemote as a super class of 'obj'.

      Both ear (BasketManager and FixEndPoint) files have the FixEndPoint-ejb.jar file in them. Is that a problem?

      I planning on creating a library jar of the interfaces and putting that in the lib directory to see if that is part of the issue. Otherwise, I may just move all of the FixEndPoint stuff into the BasketManager project.

      Are there any glaring problems with what I'm doing? Any obvious configuration or errors I just can't see because I've been looking at it for too long?

      Any help would be appreciated.

      Thanks,
      Mike

        • 1. Re: Cast fails after successful JNDI lookup
          mikeperik

          Also, here is the FixEndPointManager interface and Bean declarations

          public interface FixEndPointManagerRemote {
          }

          public interface FixEndPointManagerLocal extends FixEndPointManagerRemote {
          }

          @Stateless
          @Remote(FixEndPointManagerRemote.class)
          @Local(FixEndPointManagerLocal.class)
          public class FixEndPointManagerBean implements FixEndPointManagerLocal, FixEndPointManagerRemote {
          }

          Any problems here?

          Mke

          • 2. Re: Cast fails after successful JNDI lookup
            andixt

            Its a problem of Classloader. You need to separate interfaces from implementations in portal-forums-ui.jar (also in auth plugin jar) and put interfaces somewhere where they would be accessed by both services