users@glassfish.java.net

Help: access a Local Session Bean from another EAR

From: Xavier Callejas <xavier_at_sistemasaereos.com.sv>
Date: Fri, 15 Apr 2011 11:50:22 -0600

Hi,

How can I call a Local Session Bean inside an EAR from another EAR, both
deployed in the same Glassfish v3 domain?

This is the structure:

Glassfish v3 Domain1
        EAR1
                EAR1-EJB.jar
                        class TestSessionBean <-- @Stateless
                common.jar
                        interface TestSessionLocal <-- @Local

        EAR2
                EAR2-EJB.jar
                        class TestSessionBeanClient <-- @Singleton, @LocalBean
                common.jar
                        interface TestSessionLocal <-- @Local


TestSessionBean implements TestSessionLocal, boths EARs has common.jar.


I need to use TestSessionBean from TestSessionBeanClient. I would like to take
advantage of local session bean because of performance.

I know I can't use a simple @EJB call in the TestSessionBeanClient, so I tried
to lookup like this:

InitialContext ic = new InitialContext();
TestSessionLocal tsl = ic.lookup("java:global/EAR1/EAR1-
EJB/TestSessionBean!org.test.TestSessionLocal");

That will throw a ClassCastException because the returned object will not be
TestSessionLocal but a proxy class like:

TestSessionLocal_1389930137

that to be able to call its methos I must do reflection to find its methods.

Please help.

Thank you in advance.