开发者

access a Local Session Bean from another EAR?

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 Test开发者_开发技巧SessionBeanClient, 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.


Per 3.2.2 of the EJB 3.1 specification:

Access to an enterprise bean through the local client view is only required to be supported for local clients packaged within the same application as the enterprise bean that provides the local client view. Compliant implementations of this specification may optionally support access to the local client view of an enterprise bean from a local client packaged in a different application. The configuration requirements for inter-application access to the local client view are vendor-specific and are outside the scope of this specification. Applications relying on inter-application access to the local client view are non-portable.

Here is the GlassFish FAQ: I have an EJB component with a Local interface. Can I access it from a web component in a different application?

(That said, you could try packaging your interface such that it is loaded by a ClassLoader that is common to both applications.)


You really don't want to do that. as another answer stated, it's not required to be supported. one of the many reasons it's problematic is because it can cause classloader issues. if you have classes in one ear with references to classes in another ear, all kinds of bad things can happen (e.g. having cross-classloader references which will become invalid if the other ear gets redeployed).


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

I think I found an alternative solution to this issue :

I have annotated my EJB with @Remote and here's my sun-ejb config.

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 appears that the EJB is not accessible by a client without a known certificate. The others EARs can access to this EJB without any authentication.

Edit: I tried the ClassLoader solution but it's not viable for my project

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜