Access a local Bean session from another EAR?

How can I invoke a local Bean session 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, both EARs have common.jar.

I need to use TestSessionBean from TestSessionBeanClient. I would like the advantage of a local Bean session due to performance.

I know that I cannot use the simple @EJB call in TestSessionBeanClient, so I tried to search:

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

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

 TestSessionLocal_1389930137 

in order to be able to call it a metosome, I have to make a reflection to find its methods.

Please, help.

Thanks in advance.

+2
source share
3 answers

According to 3.2.2 of the EJB 3.1 specification:

Access to the bean enterprise through the local client view is required only to support local clients packaged in one application as a bean enterprise, which provides a local client view. compliant implementations of this specification may optionally support access to a local enterprise bean client view from a local client packaged in various applications. configuration requirements for access between applications to a local customer view are vendor-specific and are beyond the scope of this specification. Applications that rely on access between applications to the local client view are not portable.

Here are the frequently asked questions about GlassFish: I have an EJB component with a local interface. Can I access it from a web component in another application?

(However, you can try packing your interface so that it loads ClassLoader, which is common to both applications.)

+7
source

You really don't want to do this. as another answer stated, it does not need support. one of the many reasons that the problem arises because it can cause problems with class loaders. if you have classes in one ear with references to classes in the other ear, all kinds of bad things can happen (for example, with links to cross loaders that will become invalid if the other ear is redistributed).

+4
source

This is the first post I post on Stackoverflow, but I admit that I read it often. By the way, sorry in advance for my English.

I think I found an alternative solution to this problem:

I annotated my EJB using @Remote and here is my sun-ejb configurator.

Sun-ejb-jar.xml

  <ejb> <ejb-name>XXX</ejb-name> <ior-security-config> <transport-config> <integrity>required</integrity> <confidentiality>required</confidentiality> <establish-trust-in-target>supported</establish-trust-in-target> <establish-trust-in-client>required</establish-trust-in-client> </transport-config> <sas-context> <caller-propagation>supported</caller-propagation> </sas-context> </ior-security-config> </ejb> 

After some tests, it seems that EJB is not available to the client without a known certificate. Other EARs can access this EJB without any authentication.

Edit: I tried ClassLoader solution, but it was not viable for my project

0
source

All Articles