我正在实现JCA inbound resource adapter以允许EIS将消息发送到部署在Java EE应用服务器上的应用程序。
只有使用我的注释注释的EJB应该是可访问的,所以我使用javax.enterprise.inject.spi.Extension来观察ProcessAnnotatedType然后我可以使用它来存储有关所有部署的注释的EJB方法的详细信息在应用程序服务器上。
注释包含一个简短的唯一名称,可以像逻辑服务名一样使用,以允许来自EIS的入站调用。然后通过JNDI将这些调用分派到相应的端点。
此刻一切正常,但JNDI名称当前必须作为我的注释中的值提供。我想删除此要求,并让我的扩展程序确定Global Portable JNDI Name。
当我在JCA资源适配器中时,我必须使用java:global form:
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
接口名称和企业bean名称我或多或少可以从我收到的ProcessAnnotatedType对象中解决,但是应用程序名称和模块名称被证明有点难以捉摸。
我尝试过使用lookups of java:app/AppName and java:module/Module名称。当部署是.war时,这些与wildfly(10.x)一起工作正常,但在.ear中,由于某种原因,这些值不存在。在weblogic 12.x中,无论部署存档类型如何,这些值都不存在。
我正在寻找适用于任何Java EE兼容应用程序服务器的东西,因此理想情况下没有特定于应用程序服务器的依赖项。虽然更糟糕的情况是可以使用weblogic和wildfly的东西。
已更新 - wildfly日志:
部署的应用程序并不完全如前所述,我已经对它们进行了清理:
casual-test-app-0.0.1.ear在application.xml" casual-test-app-custom-2"中有自定义名称。其中包含test-ejb.jar和test-ejb2.jar
casual-java-testapp.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)
答案 0 :(得分:0)
正如您的日志所说,您可以使用任何列出的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 / ...的方法效果最好。
答案 1 :(得分:0)
我找到了几种不同的方法来实现这一点,但没有一种方法是完全理想的。最后,我们选择了解决方案2,因为这在我们需要支持的大多数情景中都有效。
解决方案1 - 使用注释数据在需要时创建服务
使用CDI BeanManager从SPI扩展注释元数据中发现的信息创建我的远程服务对象。这有点在section 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树的计时器服务执行延迟查找以进行匹配
有一些边缘情况,匹配不起作用,但对于那些边缘情况,我创建了另一个注释,可以在服务类上提供硬编码预期的JNDI路径,所以我们不必搜索范围。
这种方法适用于wildfly和weblogic。