2014年7月20日星期日

EAP_009:远程客户端如何使用JNDI调用EJB?

开发运行环境:JBoss EAP 6.2.0

本以为这个问题很简单,实际上还是费了些周折,特地总结一下。
JBoss EAP 6.x 对应社区版JBoss AS 7。

JBoss AS 6/7 与 JBoss AS 5 的调用方式不一样,这里介绍的是EAP 6(即JBoss AS 7)下的调用方式。

1. 创建jboss-ejb-client.properties文件,内容如下:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

2. 按如下JNDI规则查找EJB
(1)Stateless EJB
ejb:[app-name]/[module-name]/[distinct-name]/[bean-name]![fully-qualified-classname-of-the-remote-interface]
(2)Stateful EJB
ejb:[app-name]/[module-name]/[distinct-name]/[bean-name]![fully-qualified-classname-of-the-remote-interface]?stateful
说明如下:
(1)app-name:ear应用的名字,如果不是ear格式,此项为空。
(2)module-name:jar或war的名字,该名字可以在ejb-jar.xml中重新定义。
(3)distinct-name:可以定义一个唯一的名字,如果没定义,此项为空。
(4)bean-name:实现接口的EJB类名。
(5)fully-qualified-classname-of-the-remote-interface:接口的全限定路径名+类名。

具体例子可以参考JBoss EAP 6.2的quickstarts中的ejb-remote例子。

参考文献:
1. https://docs.jboss.org/author/displa/AS72/EJB+invocations+from+a+remote+client+using+JNDI
2. http://bbs.csdn.net/topics/380264639
3. http://k1280000.iteye.com/blog/1654740


没有评论: