5 Replies Latest reply on Sep 8, 2004 10:56 AM by jae77

    invoke EJB session bean across applications

    tse_sherman

      Hi,

      Has anyone of you tried to invoke an EJB which is deployed in a seperate application within the same server (i.e. same host and deployed in the same server deploy directory)? I searched the web and found a site at http://www.huihoo.com/jboss/online_manual/3.0/ch07s13.html and used
      the "External EJB reference" deployment method but I keep getting Class cast exception when trying to call the PortableRemoteObject.narrow(Object, Class) method. I am using jboss 3.2.2 and is pretty sure that the error is not caused by the code since I am able to access the same bean from another server.

      I have been looking around for solution for hours and still couldn't find anything that helps... : (

      Your help is greatly apprieciated.

      Below are my set up:

      ejb-jar.xml:

       <session>
       <ejb-name>BeanA</ejb-name>
       <local-home>bean_a_package.IBeanALocalHome</local-home>
       <local>bean_a_package.IBeanALocal</local>
       <ejb-class>bean_a_package.BeanA</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       <ejb-ref>
       <ejb-ref-name>
       BeanB
       </ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <home>bean_b_package.IBeanBRemoteHome</home>
       <remote>bean_b_package.IBeanBRemote</remote>
       </ejb-ref>
       </session>
      
      
      jboss.xml:
      
       <session>
       <ejb-name>BeanA</ejb-name>
       <jndi-name>BeanA</jndi-name>
       <local-jndi-name>IBeanALocalHome</local-jndi-name>
       <ejb-ref>
       <ejb-ref-name>BeanB</ejb-ref-name>
       <jndi-name>jnp://localhost:1099/applicationB/BeanB</jndi-name>
       </ejb-ref>
       </session>
      
      
      


        • 1. Re: invoke EJB session bean across applications
          darranl

          This sounds like the problem that a bug was raised for yesterday http://sourceforge.net/tracker/index.php?func=detail&aid=1021980&group_id=22866&atid=376685

          • 2. Re: invoke EJB session bean across applications
            tse_sherman

            Thank you darranl. I tried the workarounds suggested in the bug description and is able to call the PortableRemoteObject.narrow method. But when I call the create of the casted object method I get the following error message. The same piece of code works find if I call BeanB from a separate server.

            javax.ejb.EJBException: Invalid invocation, check your deployment packaging

            This is the code I am using to get a remote reference.

             env = new Properties();
             env.put(Context.PROVIDER_URL,
             "jnp://host:1099");
             ic = new InitialContext(env);
             Object objref = ic.lookup("BeanB");
             Object obj = PortableRemoteObject.narrow(objref, bean_b_package.IBeanBRemoteHome.class);
             home = (bean_b_package.IBeanBRemoteHome) obj;
             isc = home.create(); // error occurs here
            


            • 3. Re: invoke EJB session bean across applications
              jae77

              are the ejbs deployed inside an ear archive? if yes, are they scoped?

              • 4. Re: invoke EJB session bean across applications
                tse_sherman

                Yes. The ejbs are deployed inside a jar which in turn is packaged in an ear file and are scoped. Both application A and B are scoped (I think...). The following are the settings in the application.xml of the two ears.

                Application A
                
                <?xml version="1.0" encoding="UTF-8"?>
                <jboss-app>
                 <loader-repository>localhost:Aloader=A.ear</loader-repository>
                </jboss-app>
                
                Application B:
                
                <?xml version="1.0" encoding="UTF-8"?>
                <jboss-app>
                 <loader-repository>localhost:Bloader=B.ear</loader-repository>
                </jboss-app>
                
                


                • 5. Re: invoke EJB session bean across applications
                  jae77

                  go read this: http://www.jboss.org/wiki/Wiki.jsp?page=HotDeployClassCastExceptions

                  more or less same situation as this - basically, you need to pull out the local/home interfaces and any other dependent classes for those ejbs and package them outside of both of those ears.

                  you could also turn on "pass by value" for ejb invocations, but that reduces your performance dramatically.

                  from my experiences, scoping works best if you have a stand alone legacy application that has older/incompatible library dependencies (i'm sure there are other useful scenarios too, but i have not stumbled across them yet).

                  if you have the jboss admin book, read chapter 2, it talks all about how the classloader works.