Flex如此简单访问EJB

1 篇文章 0 订阅

1、通过blazeds/lcds访问远程EJB,Pomer框架封装了blazeds/lcds的访问式,用户无须添加配置文件,只须在EJBDestinationRegister注册即可将Java对象发布成blazeds/lcds的远程对象(RemoteObject),进行远程访问。

2、新建EJB项目并增加一个无状态的SessionBean,在Myeclipse中如何新建和布署EJB不在本讲解范围,用户可参照MyEclipse相关帮助文档。用户自己建一个HelloEJB的SessionBean,并增加public String hello(String name)方法; 确认HelloEJB可以被远程访问。这里主要讲解Flex与EJB之间的调用,亲不懂Flex,没用过EJB,那。。。

3、注册EJB
在cn.org.pomer.flex.remoting.services.EJBDestinationRegister的构造函数增加EJB注册信息。
复制内容到剪贴板
代码:
public EJBDestinationRegister() {
super();
this.list = new ArrayList<EJBDestination>();

//add here
add("helloEJB", "HelloServicesImpl/remote");
}

4、新建Flex项目

代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private function helloClick():void{
helloSpring.hello("pomer");
}
private function helloEJBFault(e:FaultEvent):void{
Alert.show(e.fault.message.toString());
}
private function helloEJBResult(e:ResultEvent):void{
Alert.show(e.result as String);
}
]]>
</mx:Script>

<mx:RemoteObject endpoint="../messagebroker/amf"
id="helloEJB"
fault="helloEJBFault(event)"
result="helloEJBResult(event)"
destination="helloEJB" showBusyCursor="true"/>


<mx:Button label="hello" click="helloClick();"/>
</mx:Application>

5、布署运行

  • 启动Tomcat,日志出现如下标记,布署成功


  • 右击HelloJava.mxml->Run as->Flex application

6、原理分析


查看WEB-INF\flex\services- config.xml,EJBRemotingDestinationBootstrapService类从 EJBDestinationRegister类得到所有要远程访问的Ejb,自动加入服务中。EJBFactory根据 EJBDestinationRegister提供的内容自动创建远程对象。
 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值