NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
Jason Lee Posted via mailing list.
|
Posted: Fri Apr 15, 2011 7:45 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
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:
| Quote: | 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 |
|
| Back to top |
|
 |
Xavier Callejas Posted via mailing list.
|
Posted: Fri Apr 15, 2011 7:55 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
| On Vie 15 Abr 2011 12:58:49 Jason Lee escribi |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Fri Apr 15, 2011 8:44 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
| Nope. |
|
| Back to top |
|
 |
Xavier Callejas Posted via mailing list.
|
Posted: Fri Apr 15, 2011 9:36 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
| On Vie 15 Abr 2011 14:13:01 Steven Siebert escribi |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Fri Apr 15, 2011 9:52 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
| I completely agree, I wish there was a specification-compliant way to get around using a remote interface for this very situation. |
|
| Back to top |
|
 |
Marina Vatkina Posted via mailing list.
|
Posted: Sun Apr 17, 2011 1:06 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
Local EJB access across applications is not supported in GlassFish.
-marina
Xavier Callejas wrote:
| Quote: | 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.
|
|
|
| Back to top |
|
 |
Sahoo Posted via mailing list.
|
Posted: Sun Apr 17, 2011 11:09 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
The EJB spec does not disallow invocation of local EJBs from other applications. It is an optional feature and left to vendors. In GlassFish, one can access local EJBs from other applications by using OSGi/EJB applications approach, where in the local EJBs are made available as OSGi services and then consumed from other bundles using OSGi service registry.
Sahoo
On Saturday 16 April 2011 01:43 AM, Steven Siebert wrote: | Quote: | Nope. I believe Jason iis correct, as according to the EJB specification, you must use the remote interface to access and EJB from another archive (EAR, EJB, or WAR). This is for security reasons, because you may have both a local and remote interface on a single EJB class, allowing you to specify different interfaces for internal and external consumption. I'm curious as to why the JNDI approach works - and wonder if this is actually a bug. There are several cases I would not like to expose my internal business interface out to the world, but if it was simply available through JNDI from another EAR running on the same domain. I think you might have found a bug =)
Which version of GF are you running (3.0.1, 3.1)? I'm interested in testing this, as it has security implications for me.
Thanks,
S
On Fri, Apr 15, 2011 at 3:24 PM, Xavier Callejas <address-removed ([email]address-removed[/email])> wrote:
| Quote: | | On Vie 15 Abr 2011 12:58:49 Jason Lee escribi |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Thu Apr 21, 2011 4:49 pm Post subject: Re: Help: access a Local Session Bean from another EAR |
|
|
Sahoo,
You are absolutely right! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|