9 Replies Latest reply on May 18, 2007 5:06 AM by ulmer

    Stateless and JNDI once again

    peper

      Hi.
      I'm using JBoss 4.2.0 CR 2

      I've got:

      @Stateless
      @Remote(ProjectFacade.class)
      public class ProjectFacadeBean implements ProjectFacade, ProjectFacadeLocal

      found it in the JNDI Console as :

      ProjectFacadeBeanRemote (proxy: $Proxy108 implements interface facade.ProjectFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)

      so my lookup code is :
      [code = java]
      ProjectFacade projectFacade = (ProjectFacade)context.lookup("ProjectFacadeBeanRemote");


      And I get :

      java.lang.ClassCastException : $Proxy108 cannot be cast to facade.ProjectFacade



        • 1. Re: Stateless and JNDI once again
          peper

          //Once again - there were some problems with the code parts//

          Hi.
          I'm using JBoss 4.2.0 CR 2

          I've got:

          @Stateless
          @Remote(ProjectFacade.class)
          public class ProjectFacadeBean implements ProjectFacade, ProjectFacadeLocal

          found it in the JNDI Console as :

          ProjectFacadeBeanRemote (proxy: $Proxy108 implements interface facade.ProjectFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)

          so my lookup code is :

          ProjectFacade projectFacade = (ProjectFacade)context.lookup("ProjectFacadeBeanRemote");


          And I get :

          java.lang.ClassCastException : $Proxy108 cannot be cast to facade.ProjectFacade


          As You can see JNDI Console said that : $Proxy108 implements interface facade.ProjectFacade

          What am I doing wrong ??

          Second try :

          JNDI console :

          +- webapp1 (class: org.jnp.interfaces.NamingContext)
          | +- ProjectFacadeBean (class: org.jnp.interfaces.NamingContext)
          | | +- local (proxy: $Proxy117 implements interface facade.ProjectFacadeLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)

          The lookup code :


          ProjectFacadeLocal projectFacade = (ProjectFacadeLocal)context.lookup("webapp1/ProjectFacadeBean/local");


          and ....

          java.lang.ClassCastException : $Proxy117 cannot be cast to facade.ProjectFacadeLocal


          What's the trick?!

          • 2. Re: Stateless and JNDI once again
            alrubinger

            Do you have an @Local annotation on ProjectFacadeLocal?

            S,
            ALR

            • 3. Re: Stateless and JNDI once again
              peper

              Sure, I've got.

              Testing :
              Object projectFacade = context.lookup("ProjectFacadeBean/local");

              return ( projectFacade.toString() + " " + (projectFacade instanceof facade.ProjectFacadeLocal) + (projectFacade instanceof facade.ProjectFacade) + (projectFacade instanceof ProjectFacadeBean) + " " + projectFacade.getClass());


              Returned :

              ProjectFacadeBean falsefalsefalse class $Proxy76


              whlie JNDI console said that :

              ProjectFacadeBean (class: org.jnp.interfaces.NamingContext)
              | +- local (proxy: $Proxy76 implements interface facade.ProjectFacadeLocal.....


              I really don't understand it, and really need help.

              • 4. Re: Stateless and JNDI once again
                peper

                I give up.
                I tried on JBoss 4.2.0 RC2 and on JBoss 4.2.0.GA , on Java5 and on Java6...

                Does anyone have a simple ear with an EJB3 jar and webapp war inside, which I can simply run and test ?

                I would be most grateful for such an example.

                • 5. Re: Stateless and JNDI once again
                  alrubinger

                  Curious as to why you're having this problem.

                  If you ZIP/TAR up your source and email me, I'll have a look. Contact info in my profile.

                  S,
                  ALR

                  • 6. Re: Stateless and JNDI once again
                    ulmer

                     

                    "ALRubinger" wrote:
                    ...


                    i have similar problem... could you post your solution about the peper's code here?

                    • 7. Re: Stateless and JNDI once again
                      alrubinger

                      Peper sent me his code, and the fix was related to Classloading in JBoss.

                      Reference:

                      http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoading

                      Peper had an EAR, and in it, a WAR and EJB3 JAR. Within the WAR WEB-INF/classes were class files also defined in the EJB3 JAR.

                      Because more than one classloader was picking up duplicates of the class definitions, the WAR-scoped classloader was attempting to cast the object retrieved from JNDI (of type recognized by the EJB3 JAR Classloader) and cast it (incorrectly) into its own version.

                      I'm not the most succinct at explaining this, I'm sure, so check the references above for a much more detailed and correct description.

                      Steps I took to get this to work:

                      * Download and unzip/untar JBoss 4.2.0GA
                      * Delete the WEB-INF/classes directory from the WAR in the EAR
                      * Deploy the EAR

                      S,
                      ALR

                      • 8. Re: Stateless and JNDI once again
                        peper

                        Thanks for Your help! Of course it was the problem.

                        • 9. Re: Stateless and JNDI once again
                          ulmer

                           

                          "ALRubinger" wrote:
                          ...
                          Because more than one classloader was picking up duplicates of the class definitions, the WAR-scoped classloader was attempting to cast the object retrieved from JNDI (of type recognized by the EJB3 JAR Classloader) and cast it (incorrectly) into its own version.

                          I'm not the most succinct at explaining this, I'm sure, so check the references above for a much more detailed and correct description.

                          Steps I took to get this to work:

                          * Download and unzip/untar JBoss 4.2.0GA
                          * Delete the WEB-INF/classes directory from the WAR in the EAR
                          * Deploy the EAR

                          S,
                          ALR


                          thank you, ALRubinger, it goes!