当前位置: 首页 > 知识库问答 >
问题:

确定 javax.enterprise.inject.spi.Extension 中的 JNDI 可移植名称

司空均
2023-03-14

我正在实现一个 JCA 入站资源适配器,以允许 EIS 将消息发送到部署在 Java EE 应用程序服务器上的应用程序。

应该只有使用我的注释进行了注释的EJB才是可访问的,所以我使用了一个javax . enterprise . inject . SPI . extension来观察ProcessAnnotatedType,然后我可以使用它来存储关于部署在应用服务器上的使用我的注释进行了注释的所有EJB方法的详细信息。

注释包含一个简短的唯一名称,该名称可以像逻辑服务名称一样使用,以允许来自EIS的入站调用。然后通过JNDI将这些调用分派到相应的endpoint。

目前这一切都很好,但是JNDI的名字必须作为一个值在我的注释中提供。我想取消这一要求,让我的分机决定全球便携式JNDI名称。

由于我在JCA资源适配器中,我必须使用java:global表单:

java:global[/application name]/module name/enterprise bean name[/interface name]

我正在测试的示例包括:

java:global/testappwar01/SimpleService!org.example.service.ISimpleService
java:global/testappear01/test-ejb/SimpleService!org.example.service.ISimpleService

从我收到的ProcessAnnotatedType对象中,我或多或少可以算出接口名称和企业bean名称,但是应用程序名称和模块名称被证明有点难以捉摸。

我尝试过使用java: app/AppName和java:模块/模块名称的查找。当部署是. war时,这些在Wildfly(10. x)中运行良好,但在. ears中由于某种原因这些值不存在。在weblogic 12. x中,无论部署存档类型如何,这些值都根本不存在。

我正在寻找的东西,将在任何Java EE兼容的应用服务器上工作,所以理想情况下没有应用服务器特定的依赖关系。尽管更糟糕的情况下,一些与weblogic和wildfly一起工作的东西是可以接受的。

已更新 - 野蝇日志

部署的应用程序并不完全如前所述,我已经清理了它们:

casual-test-app-0.0.1.ear在application.xml中有一个自定义名称“casual-test-app-custom-2 ”,其中包含test-ejb.jar和test-ejb2.jar

war是我可以让appName和moduleName工作的地方。

casual-jca-0.0.1.ear是我的资源适配器

2018-02-21 10:18:03,226 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment casual-test-app-0.0.1.ear
2018-02-21 10:18:03,520 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment casual-jca-0.0.1.ear
2018-02-21 10:18:03,852 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) WFLYWELD0003: Processing weld deployment test-ejb.jar
2018-02-21 10:18:03,853 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment test-ejb2.jar
2018-02-21 10:18:03,873 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment casual-java-testapp.war
2018-02-21 10:18:03,877 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-2) WFLYEJB0473: JNDI bindings for session bean named 'SimpleServiceNoViewEjb' in deployment unit 'subdeployment "test-ejb2.jar" of deployment "casual-test-app-0.0.1.ear"' are as follows:

    java:global/casual-test-app-custom-2/test-ejb2/SimpleServiceNoViewEjb!se.kodarkatten.casual.example.service.SimpleServiceNoViewEjb
    java:app/test-ejb2/SimpleServiceNoViewEjb!se.kodarkatten.casual.example.service.SimpleServiceNoViewEjb
    java:module/SimpleServiceNoViewEjb!se.kodarkatten.casual.example.service.SimpleServiceNoViewEjb
    java:global/casual-test-app-custom-2/test-ejb2/SimpleServiceNoViewEjb
    java:app/test-ejb2/SimpleServiceNoViewEjb
    java:module/SimpleServiceNoViewEjb

2018-02-21 10:18:03,878 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-2) WFLYEJB0473: JNDI bindings for session bean named 'SimpleService2' in deployment unit 'subdeployment "test-ejb2.jar" of deployment "casual-test-app-0.0.1.ear"' are as follows:

    java:global/casual-test-app-custom-2/test-ejb2/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:app/test-ejb2/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:module/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:jboss/exported/casual-test-app-custom-2/test-ejb2/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:global/casual-test-app-custom-2/test-ejb2/SimpleService2
    java:app/test-ejb2/SimpleService2
    java:module/SimpleService2

2018-02-21 10:18:03,881 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-8) WFLYEJB0473: JNDI bindings for session bean named 'SimpleService2' in deployment unit 'subdeployment "test-ejb.jar" of deployment "casual-test-app-0.0.1.ear"' are as follows:

    java:global/casual-test-app-custom-2/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:app/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:module/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:jboss/exported/casual-test-app-custom-2/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
    java:global/casual-test-app-custom-2/test-ejb/SimpleService2
    java:app/test-ejb/SimpleService2
    java:module/SimpleService2

2018-02-21 10:18:03,909 INFO  [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0003: Processing weld deployment casual-jca-0.0.1.rar
2018-02-21 10:18:03,911 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0002: Bound JCA ConnectionFactory [java:/JmsXA]
2018-02-21 10:18:03,912 INFO  [org.wildfly.extension.messaging-activemq] (MSC service thread 1-2) WFLYMSGAMQ0002: Bound messaging object to jndi name java:jboss/DefaultJMSConnectionFactory
2018-02-21 10:18:03,916 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment casual-inbound-handler-fielded-buffer.jar
2018-02-21 10:18:03,917 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-1) WFLYEJB0473: JNDI bindings for session bean named 'FieldedBufferHandler' in deployment unit 'subdeployment "casual-inbound-handler-fielded-buffer.jar" of deployment "casual-jca-0.0.1.ear"' are as follows:

    java:global/casual-jca-app/casual-inbound-handler-fielded-buffer/FieldedBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:app/casual-inbound-handler-fielded-buffer/FieldedBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:module/FieldedBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:global/casual-jca-app/casual-inbound-handler-fielded-buffer/FieldedBufferHandler
    java:app/casual-inbound-handler-fielded-buffer/FieldedBufferHandler
    java:module/FieldedBufferHandler

2018-02-21 10:18:03,918 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0003: Processing weld deployment casual-inbound-handler-jscd-buffer.jar
2018-02-21 10:18:03,919 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment casual-inbound-handler-javaee-service.jar
2018-02-21 10:18:03,919 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment casual-inbound-handler-casual-service.jar
2018-02-21 10:18:03,920 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment casual-inbound.jar
2018-02-21 10:18:03,921 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-7) WFLYEJB0473: JNDI bindings for session bean named 'JavaServiceCallBufferHandler' in deployment unit 'subdeployment "casual-inbound-handler-jscd-buffer.jar" of deployment "casual-jca-0.0.1.ear"' are as follows:

    java:global/casual-jca-app/casual-inbound-handler-jscd-buffer/JavaServiceCallBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:app/casual-inbound-handler-jscd-buffer/JavaServiceCallBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:module/JavaServiceCallBufferHandler!se.kodarkatten.casual.jca.inbound.handler.buffer.BufferHandler
    java:global/casual-jca-app/casual-inbound-handler-jscd-buffer/JavaServiceCallBufferHandler
    java:app/casual-inbound-handler-jscd-buffer/JavaServiceCallBufferHandler
    java:module/JavaServiceCallBufferHandler

2018-02-21 10:18:03,921 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0473: JNDI bindings for session bean named 'CasualServiceHandler' in deployment unit 'subdeployment "casual-inbound-handler-casual-service.jar" of deployment "casual-jca-0.0.1.ear"' are as follows:

    java:global/casual-jca-app/casual-inbound-handler-casual-service/CasualServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:app/casual-inbound-handler-casual-service/CasualServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:module/CasualServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:global/casual-jca-app/casual-inbound-handler-casual-service/CasualServiceHandler
    java:app/casual-inbound-handler-casual-service/CasualServiceHandler
    java:module/CasualServiceHandler

2018-02-21 10:18:03,921 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'JavaeeServiceHandler' in deployment unit 'subdeployment "casual-inbound-handler-javaee-service.jar" of deployment "casual-jca-0.0.1.ear"' are as follows:

    java:global/casual-jca-app/casual-inbound-handler-javaee-service/JavaeeServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:app/casual-inbound-handler-javaee-service/JavaeeServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:module/JavaeeServiceHandler!se.kodarkatten.casual.jca.inbound.handler.service.ServiceHandler
    java:global/casual-jca-app/casual-inbound-handler-javaee-service/JavaeeServiceHandler
    java:app/casual-inbound-handler-javaee-service/JavaeeServiceHandler
    java:module/JavaeeServiceHandler

2018-02-21 10:18:03,964 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'EchoService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/EchoService!se.kodarkatten.casual.example.EchoService
    java:app/casual-java-testapp/EchoService!se.kodarkatten.casual.example.EchoService
    java:module/EchoService!se.kodarkatten.casual.example.EchoService
    java:global/casual-java-testapp/EchoService
    java:app/casual-java-testapp/EchoService
    java:module/EchoService

2018-02-21 10:18:03,968 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'SimpleService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/SimpleService!se.kodarkatten.casual.example.service.ISimpleService
    java:app/casual-java-testapp/SimpleService!se.kodarkatten.casual.example.service.ISimpleService
    java:module/SimpleService!se.kodarkatten.casual.example.service.ISimpleService
    java:jboss/exported/casual-java-testapp/SimpleService!se.kodarkatten.casual.example.service.ISimpleService
    java:global/casual-java-testapp/SimpleService
    java:app/casual-java-testapp/SimpleService
    java:module/SimpleService

2018-02-21 10:18:03,968 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'QueueService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/QueueService!se.kodarkatten.casual.example.QueueService
    java:app/casual-java-testapp/QueueService!se.kodarkatten.casual.example.QueueService
    java:module/QueueService!se.kodarkatten.casual.example.QueueService
    java:global/casual-java-testapp/QueueService
    java:app/casual-java-testapp/QueueService
    java:module/QueueService

2018-02-21 10:18:03,972 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'InboundOrderRestService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/InboundOrderRestService!se.kodarkatten.casual.example.inbound.InboundOrderRestService
    java:app/casual-java-testapp/InboundOrderRestService!se.kodarkatten.casual.example.inbound.InboundOrderRestService
    java:module/InboundOrderRestService!se.kodarkatten.casual.example.inbound.InboundOrderRestService
    java:global/casual-java-testapp/InboundOrderRestService
    java:app/casual-java-testapp/InboundOrderRestService
    java:module/InboundOrderRestService

2018-02-21 10:18:03,973 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'OrderRestService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/OrderRestService!se.kodarkatten.casual.example.order.OrderRestService
    java:app/casual-java-testapp/OrderRestService!se.kodarkatten.casual.example.order.OrderRestService
    java:module/OrderRestService!se.kodarkatten.casual.example.order.OrderRestService
    java:global/casual-java-testapp/OrderRestService
    java:app/casual-java-testapp/OrderRestService
    java:module/OrderRestService

2018-02-21 10:18:03,974 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'CasualOrderService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderServiceRemote
    java:app/casual-java-testapp/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderServiceRemote
    java:module/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderServiceRemote
    java:jboss/exported/casual-java-testapp/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderServiceRemote
    java:global/casual-java-testapp/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderService
    java:app/casual-java-testapp/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderService
    java:module/CasualOrderService!se.kodarkatten.casual.example.service.order.ICasualOrderService

2018-02-21 10:18:03,975 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'OrderService' in deployment unit 'deployment "casual-java-testapp.war"' are as follows:

    java:global/casual-java-testapp/OrderService!se.kodarkatten.casual.example.service.order.IOrderService
    java:app/casual-java-testapp/OrderService!se.kodarkatten.casual.example.service.order.IOrderService
    java:module/OrderService!se.kodarkatten.casual.example.service.order.IOrderService
    java:global/casual-java-testapp/OrderService!se.kodarkatten.casual.example.service.order.IOrderServiceRemote
    java:app/casual-java-testapp/OrderService!se.kodarkatten.casual.example.service.order.IOrderServiceRemote
    java:module/OrderService!se.kodarkatten.casual.example.service.order.IOrderServiceRemote
    java:jboss/exported/casual-java-testapp/OrderService!se.kodarkatten.casual.example.service.order.IOrderServiceRemote

2018-02-21 10:18:04,005 INFO  [org.jboss.weld.Version] (MSC service thread 1-3) WELD-000900: 2.3.5 (Final)

共有2个答案

严曜文
2023-03-14

我已经找到了一些不同的方法来实现这一点,但没有一个是完全理想的。最后,我们选择了解决方案2,因为这在我们需要支持的大多数场景中都有效。

解决方案 1 - 在需要时使用注释数据创建服务

使用 CDI BeanManager,以便根据在 SPI 扩展注释元数据中发现的信息创建我的远程服务对象。这在16.5节中有所记录,尽管这是有效的最终版本:

public Object getServiceReference( AnnotatedType<CasualService> type )
{
    BeanManager beanManager = CDI.current().getBeanManager();
    CreationalContext<CasualService> ctx = beanManager.createCreationalContext(null);
    BeanAttributes<CasualService> attributes = beanManager.createBeanAttributes( type );
    InjectionTargetFactory<CasualService> itf = beanManager.getInjectionTargetFactory( type );
    Bean<CasualService> bean = beanManager.createBean( attributes, type.getJavaClass(), itf );
    Object reference = beanManager.getReference( bean, type.getBaseType(), ctx );
    return reference;
}

不幸的是,这只在Wildfly中有效,而不是在Weblogic中。weblogic中的问题是由于Weblogic bean管理器实现创建Bean的方式造成的;它不使用当前的 Threads 类装入器,导致由于依赖项不满意或找不到类而导致异常。

我也不完全满意每次都需要创建服务对象,因为slb缓存等的应用程序服务器设置将不被遵守。

解决方案 2 - 使用计时器服务遍历 JNDI 树以查找匹配项,从而执行延迟查找

  1. 在 spi 扩展发现批注期间,保存所有批注元数据。
  2. 定时器服务定期运行以遍历 JNDI 树以查找所有代理对象/远程服务。(需要计时器服务,因为在扩展发现运行时,weblogic 没有可用的 JNDI 条目。
  3. 使用服务注释元数据将它们“匹配”到候选 JNDI URL。基于全局可移植 JNDI 名称信息的基于文本的匹配
  4. 使用代理对象类装入器加载实现类以检查其方法注释数据,以查看它是否是预期的服务(装入类是必需的,因为代理类方法不包含任何注释元数据)
  5. 重复该过程,直到所有服务都具有匹配的 JNDI。

在一些边缘情况下,匹配不起作用,但是对于这些边缘情况,我创建了另一个注释,可以在服务类上提供,该注释对预期的JNDI路径进行硬编码,因此我们不必搜索。

这种方法适用于wildfly和weblogic。

景嘉实
2023-03-14

正如您的日志所说,您可以使用任何列出的JNDI名称访问您的EJB。

java:global/casual-test-app-custom-2/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
java:app/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
java:module/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
java:jboss/exported/casual-test-app-custom-2/test-ejb/SimpleService2!se.kodarkatten.casual.example.service.ISimpleService2
java:global/casual-test-app-custom-2/test-ejb/SimpleService2
java:app/test-ejb/SimpleService2
java:module/SimpleService2

可能在您的情况下,使用java: global/...的方法效果最好。

 类似资料:
  • 以前的尝试是让Netbean将EJB模块部署到Netbean可以访问的Glassfish服务器上,该模块以JAR而不是EAR的形式构建。但是,通过CLI使用将该JAR部署到Glassfish可能会遇到错误。 EAR通过CLI部署时没有问题--但是,EJB的JNDI名称似乎不起作用。差异是什么? 32.4.1.1可移植JNDI语法 三个JNDI名称空间用于可移植JNDI查找:java:global、

  • WebAssembly的二进制格式是被设计成可在不同操作系统与指令集上高效执行的,无论在Web或非Web环境中。 对高效执行的设想 尽管执行环境是有条件的,本地的,不确定的,也不要向WebAssembly提供下述特性。有些情况下为了WebAssembly模块执行,也许不得不模拟一些宿主硬件或操作系统不提供的特性,让它们似乎被支持。这种情况将会导致糟糕的性能。 随着WebAssembly的标准化推进

  • 2.2.1.可移植性 Linux可以轻松地移植到各种不同的硬件平台上。有了Linux做硬件抽象层,Android就不必为不同硬件的兼容性而劳心。Linux 的绝大多数底层代码都是用可移植的 C 代码编写,因此第三方开发者可以将 Android 移植到很多不同的设备上。

  • "C语言结合了汇编的强大功能和可移植性" -- 无名氏,暗指比尔.萨克。 可移植代码的好处是有目共睹的。这一节将阐述一些编写可移植代码的指导原则。这里"可移植的"是指一个源码文件能够在不同机器上被编译和执行,其 前提仅仅是在不同平台上可能包含不同的头文件,使用不同的编译器开关选项罢了。头文件包含的#define和typedef可能因机器而异。一般 来说,一个新"机器"是指一种不同的硬件,一种不同的

  • 主要内容:什么是PCL在本章中,我们将讨论什么是PCL(可移植类库),以及为什么我们需要PCL。 为了理解这个概念,让我们打开在前面章创建的类库项目文件夹。 在这个文件夹中,除了和CS文件之外,还可以看到文件,这是因为Visual Studio安装.NET Core项目类型为而不是。 正如微软所提到的,将会消失,但它仍然在预览工具中。UWP应用程序使用。 现在把引用和实际上是不可行的,而且这个功能不会被执行,因为将会移

  • 问题内容: 我在家中使用linux,但在学校中我们使用Windows7。我想在我的USB上安装python,以便可以在Windows和linux上使用它(ubuntu 13.04)。有没有办法可以在USB上安装python,以便win和linux计算机都可以使用它?我对python 2.7更加感兴趣。我在Linux机器上安装了Wine。可能不理想,但我可以使用便携式python并在wine下运行它