7 Replies Latest reply on Feb 1, 2006 11:17 AM by ppphoenixxx

    accessing stateful session beans in ears from the outside

      Hi,

      I have a strange ClassCastException problem in latest (today) Branch_4_0 CVS. I have not tried this on earlier versions, and the tutorial examples do all work - so I suspect it has something to do with ears and/or keeping interfaces separated.

      I have something like that:

      ifs.jar (contains interfaces)

      public interface Example
      {
       @Remove
       public void logout();
      }


      application.ear(contains a webapp + persistence beans + business logic, also contains ifs.jar in cp)
      @Stateful
      @Remote("Example.class")
      public class ExampleBean
      {
       public void logout()
       {
       dosomestuff;
       }
      }


      external_client (ifs.jar are in cp):

      .
      .
      InitialContext ic = new InitialContext();
      Example e = (Example) ic.lookup("application/ExampleBean/remote");
      .
      .


      I get a ClassCastException after the successful lookup. Debugging shows that an "Object obj = ic.lookup(...)" works perfectly and I get a $Proxy??? (??? are some numbers) Object.. but for some reason the cast does not work. In the tutorial the Object looks very similar but the cast does work. Has anyone an idea? If helpful I can provide a complete *.ear/*.jar example showing this behaviour.

      Regards,
      Bernd Froemel

        • 1. Re: accessing stateful session beans in ears from the outsid

          of course ExampleBean implements the interface Example.

          • 2. Re: accessing stateful session beans in ears from the outsid

            Searching the Forums d o e s help! - I probably found the root of my problems: I use a copy of a the interface class in the same JVM.
            (The remote client is actually a second webapp).

            I'll check that out tomorrow and give feedback if this wasn't the solution.

            • 3. Re: accessing stateful session beans in ears from the outsid
              bill.burke

              There are a couple of things with this:

              If you have copies of interface class then you will get CCEs as you're dealing with scoped classloaders here. this may solve your problems

              If you are communicating to a scoped ear, then the only safe way to communicate to it is with a remote interface. For this case, you'll have to enable CallByValue for JNDI in server/xxx/conf/jboss-service.xml.

              • 4. Re: accessing stateful session beans in ears from the outsid
                ejb3workshop

                Have a look at the classpath. I had similar problems when I used the wrong jars. In the installation docs it is mentioned :


                because you patched 4.0.3SP1, the client jars in the jboss-4.0.3SP1/client directory will be invalid. Build your client classpath from:

                1. jboss-4.0.3SP1/lib
                2. jboss-4.0.3SP1/server/all/lib
                3. jboss-4.0.3SP1/server/all/deploy/ejb3.deployer
                4. jboss-4.0.3SP1/server/all/deploy/jboss-aop-jdk50.deployer



                Hope this helps

                Alex
                ejb3workshop.com

                • 5. Re: accessing stateful session beans in ears from the outsid

                  Thanks for the fast replies - I "fixed" my problems by throwing temporarly the second webapp into the ear too and will make sure that on customer side things are running, as intended, in separated VMs.

                  If you are communicating to a scoped ear, then the only safe way to communicate to it is with a remote interface. For this case, you'll have to enable CallByValue for JNDI in server/xxx/conf/jboss-service.xml.

                  I tried that one too, but it doesn't seem to solve my problems (-> no difference if callbyvalue is enabled or not). Besides: this sound like to have a *big* performance impact.

                  How about a devel/user related faq wiki-page?

                  I guess this would be a frequent obstacle during development (especially for beginners like me):

                  Q: I'am getting a ClassCastException when I try to cast a Session Bean to it's interface after I successfully obtained the Session Bean over InitialContext lookup. Whats going on?

                  A: You are probably dealing with scoped Beans, remote interfaces and trying to run everything in the same VM while package multiple copies of your interface classes into the different parts of your application(s).
                  Solve this by:
                  * eliminate multiple copies of interfaces, package everything into the same ear
                  * run your application in different VMs
                  * if required to let different EARs interact with one another in the same VM: enable CallByValue for JNDI in server/xxx/conf/jboss-service.xml

                  Unfortunately the last one either needs a bugfix or I am not using/understanding it correctly.

                  Have a look at the classpath. I had similar problems when I used the wrong jars. In the installation docs it is mentioned :

                  No, this is unrelated to my problem (I use the greatest and latest from CVS, no "old" stuff in my client or server).

                  • 6. Re: accessing stateful session beans in ears from the outsid
                    bill.burke

                    Please help us expand the WIKI

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

                    • 7. Re: accessing stateful session beans in ears from the outsid

                      done. Maybe you should make a sticky to advice users after they found a solution on this forum or elsewhere to extend the WIKI.