JBOSS 7创建客户端通过JNDI调用 EJB

JBOSS 6,7调用通过JNDI查找EJB的方法和JBOSS5不一样

 

JBOSS 5

 

Java代码   收藏代码
  1. Properties props = new Properties();  
  2. props.setProperty("java.naming.factory.initial""org.jnp.interfaces.NamingContextFactory");  //jndi factory   
  3. props.setProperty("java.naming.provider.url""localhost:1099"); //jndi server url  
  4. props.setProperty("java.naming.factory.url.pkgs""org.jboss.naming");  //jndi finding package  
  5.   
  6. InitialContext ctx = new InitialContext (props);  
  7. DBBeanRemote db = (DBBeanRemote) ctx.lookup("DBBean/remote");  

 

 

JBOSS 6,7

EJB invocations from a remote client using JNDI

官方文档https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

 

总结:

 

1. 查找JNDI

 

 

Java代码   收藏代码
  1. final Hashtable jndiProperties = new Hashtable();  
  2. jndiProperties.put(Context.URL_PKG_PREFIXES,  
  3.         "org.jboss.ejb.client.naming");//让JNDI API知道是由谁来管理我们用来查找JNDI 名字的命名空间的。  
  4. final Context context = new InitialContext(jndiProperties);  
  5. //appName 和 moduleName分别就打包的格式而定  
  6. //如果是.ear就是appName,其它的是moduleName(.jar,.war)  
  7. final String appName = "";  
  8. final String moduleName = "EJBDBTest";  
  9. final String distinctName = "";  
  10. //实现类名  
  11. final String beanName = DB.class.getSimpleName();  
  12. System.out.println(beanName);  
  13. //接口类名  
  14. final String viewClassName = DBRemote.class.getName();  
  15. System.out.println(viewClassName);  
  16. String jndi = "ejb:" + appName + "/" + moduleName + "/"  
  17.         + distinctName + "/" + beanName + "!" + viewClassName;  
  18. System.out.println(jndi);  
  19. DBRemote db = (DBRemote) context.lookup(jndi);  

 

 In AS7, for remote access to EJBs, you use the ejb: namespace with the following syntax:

Xml代码   收藏代码
  1. For stateless beans:  
  2. ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>  
  3. For stateful beans:  
  4. ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>?stateful  

 

2.加入JAR文件

 jboss-client jar加入到项目,在 JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar 目录下.

 

 

3. 创建客户端调环境(告诉客户端应该去哪里,怎么调server的EJB)

在project path 下创建  jboss-ejb-client.properties 

 

 

Xml代码   收藏代码
  1. endpoint.name=client-endpoint  
  2. remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false  
  3.    
  4. remote.connections=default  //connection 的名字  
  5.    
  6. remote.connection.default.host=xx.xxx.xxx.xx <strong>//IP</strong>  
  7. remote.connection.default.port = xxxx <strong>//port</strong>  
  8. remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false  
  9.   
  10. //JBOSS 用户名密码  
  11. remote.connection.default.username=appuser     
  12. remote.connection.default.password=apppassword  

      或者你可以另外命名这个文件的名字,只要加入系统参数里就好,如下 

       -Djboss.ejb.client.properties.file.path=/home/me/my-client/custom-jboss-ejb-client.properties

 

   你还可以建立不同的连接

   remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

Xml代码   收藏代码
  1.    
  2. remote.connections=one, two  
  3.    
  4. remote.connection.one.host=localhost  
  5. remote.connection.one.port=6999  
  6. remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false  
  7.    
  8. remote.connection.two.host=localhost  
  9. remote.connection.two.port=7999  
  10. remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值