3 Replies Latest reply on May 24, 2006 2:30 PM by k e

    java.lang.ClassCastException javax.rmi.PortableRemoteObject.

    wei yonglai Newbie

      I want to get EJB Home object, the exception occurred!

      client code:
      Object objref = new InitialContext().lookup("java:comp/env/ejb/User");
      Class[] c = objref.getClass().getInterfaces();
      for (int i=0; i<c.length; i++) {
       System.out.println(c.getName());
       }
       userHome = (UserHome)PortableRemoteObject.narrow(objref, UserHome.class);
       return userHome;
      
       sub-ejb-jar.xml:
       <ejb-name>User</ejb-name>
       <home>cn.edu.jlu.ejb.UserHome</home>
       <remote>cn.edu.jlu.ejb.User</remote>
       <ejb-class>cn.edu.jlu.ejb.UserBean</ejb-class>
       <persistence-type>Bean</persistence-type>
      
       sub-jboss.xml:
       <entity>
       <ejb-name>User</ejb-name>
       <jndi-name>ejb/User</jndi-name>
       </entity>
      
       sub-jboss-web.xml:
       <ejb-ref>
       <ejb-ref-name>ejb/User</ejb-ref-name>
       <jndi-name>ejb/User</jndi-name>
       </ejb-ref>
      
       sub-web.xml:
       <ejb-ref>
       <ejb-ref-name>ejb/User</ejb-ref-name>
       <ejb-ref-type>Entity</ejb-ref-type>
       <home>cn.edu.jlu.ejb.UserHome</home>
       <remote>cn.edu.jlu.ejb.User</remote>
       <ejb-link>User</ejb-link>
       </ejb-ref>
      
      



      how can the exception occurred? can anybody here give me some idea, i will be so appreciate!


        • 1. Re: java.lang.ClassCastException javax.rmi.PortableRemoteObj
          Laurent PAGE Newbie

          Hi,
          I've the same problem.

          From Junit Classes It's works fine ( remote Ejb only).
          From Servlet Classes :

          If I Use : new InitialContext().lookup("java:comp/env/ejb/xxx") , i have a ClassCastException.
          If I Use :
          Hashtable props = new Hashtable();
          props.put(
          Context.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");
          props.put(
          Context.URL_PKG_PREFIXES,
          "org.jboss.naming:org.jnp.interfaces");
          props.put(Context.PROVIDER_URL, "jnp://localhost:2099");
          Context ctx = new InitialContext(props);

          I have a EJBException during the home.create()

          13:38:44,712 ERROR [LogInterceptor] EJBException in method: public abstract com.apollo.server.interfaces.Fibo com.apollo.server.interfaces.FiboHome.create() throws javax.ejb.CreateException,java.rmi.RemoteException:
          javax.ejb.EJBException: Invalid invocation, check your deployment packaging, method=public abstract com.apollo.server.interfaces.Fibo com.apollo.server.interfaces.FiboHome.create() throws javax.ejb.CreateException,java.rmi.RemoteException
          at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invokeHome(StatelessSessionContainer.java:161)

          I dont understant, the same code with Junit works.

          • 2. Re: java.lang.ClassCastException javax.rmi.PortableRemoteObj
            Laurent PAGE Newbie

            The solution :

            First, edit the conf/jboss-service.xml file and set the NamingService CallByValue to true:


            <!-- The call by value mode. true if all lookups are unmarshalled using
            the caller's TCL, false if in VM lookups return the value by reference.
            -->
            true

            ...


            Second, edit the deploy/ear-deployer.xml file and set the Isolated and CallByValue attributes to true:


            <!-- EAR deployer, remove if you are not using ear deployments -->

            <!-- A flag indicating if ear deployments should have their own scoped
            class loader to isolate their classes from other deployments.
            -->
            true
            <!-- A flag indicating if the ear components should have in VM call
            optimization disabled.
            -->
            true



            Last, edit the deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml file and set the Java2ClassLoadingCompliance and UseJBossWebLoader attributes to false:





            <!-- Get the flag indicating if the normal Java2 parent first class
            loading model should be used over the servlet 2.3 web container first
            model.
            -->
            false

            true

            <!-- A flag indicating if the JBoss Loader should be used. This loader
            uses a unified class loader as the class loader rather than the tomcat
            specific class loader.
            -->
            false

            ...

            • 3. Re: java.lang.ClassCastException javax.rmi.PortableRemoteObj
              k e Newbie

              this worked like a charm for me...except i'm using 4.0.4.GA and there is no conf/jboss-service.xml file that has a naming section and call by attribute...

              so instead find the settings in the $jboss-home/server/default/deploy/naming-service.xml file.

              i was able to leave call-by-value=false in both locations (naming-service.xml and ear-deployer.xml) and everything works.