users@glassfish.java.net

Re: Help: access a Local Session Bean from another EAR

From: Jason Lee <jason.d.lee_at_oracle.com>
Date: Fri, 15 Apr 2011 13:58:49 -0500

I don't think you can do that. The Local interface is only accessible
inside the same application (which is your .ear). To access it from
another application, even running on the same GlassFish instance, you
will have to use a Remote interface (or some other approach, for
example, a coarse-grained JAX-RS (REST) web service).

On 4/15/11 12:50 PM, Xavier Callejas wrote:
> 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.
>


-- 
Jason Lee 
Senior Member of Technical Staff
GlassFish REST API / Administration Console
Oracle Corporation
Phone +1 405-216-3193
Blog http://blogs.steeplesoft.com