简体   繁体   English

从另一个EAR访问本地会话Bean?

[英]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? 如何在另一个EAR中调用EAR中的本地会话Bean,这两个EAR都部署在同一个Glassfish v3域中?

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. TestSessionBean实现了TestSessionLocal,两个EAR都有common.jar。

I need to use TestSessionBean from TestSessionBeanClient. 我需要使用TestSessionBeanClient中的TestSessionBean。 I would like to take advantage of local session bean because of performance. 我想利用本地会话bean的性能。

I know I can't use a simple @EJB call in the TestSessionBeanClient, so I tried to lookup like this: 我知道我不能在TestSessionBeanClient中使用简单的@EJB调用,所以我试着像这样查找:

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: 这将抛出ClassCastException,因为返回的对象不是TestSessionLocal,而是代理类,如:

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: 根据EJB 3.1规范的3.2.2:

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. 只有在与提供本地客户端视图的企业bean相同的应用程序中打包的本地客户端才需要通过本地客户端视图访问企业bean。 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. 此规范的兼容实现可以选择支持从打包在不同应用程序中的本地客户端访问企业bean的本地客户端视图。 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. 这是GlassFish FAQ: 我有一个带有Local接口的EJB组件。 Can I access it from a web component in a different application? 我可以从其他应用程序中的Web组件访问它吗?

(That said, you could try packaging your interface such that it is loaded by a ClassLoader that is common to both applications.) (也就是说,您可以尝试打包您的界面,使其由两个应用程序共有的ClassLoader加载。)

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 (eg 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. 这是我在Stackoverflow上发布的第一条消息,但我承认我经常阅读它。 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. 我用@Remote注释了我的EJB,这是我的sun-ejb配置。

sun-ejb-jar.xml 太阳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. 经过一些测试后,似乎没有已知证书的客户端无法访问EJB。 The others EARs can access to this EJB without any authentication. 其他EAR可以在不进行任何身份验证的情况下访问此EJB。

Edit: I tried the ClassLoader solution but it's not viable for my project 编辑:我尝试了ClassLoader解决方案,但它对我的项目不可行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM