linlinyu

          linlinyu
          posts - 0, comments - 4, trackbacks - 0, articles - 15

          Flex 訪問 Ejb如此簡單

          Posted on 2008-10-09 21:32 linlin yu 閱讀(1176) 評論(1)  編輯  收藏 所屬分類: ejbjavaflex
          • 開始之前
            學(xué)習(xí)本文內(nèi)容之前,你至少要能用JAVA、EJB和Flex寫出Helloword這樣簡單的應(yīng)用程序,并且下載安裝了Pomer和運(yùn)行過PomerUserIndex.mxml,但不一定要了解blazedslcds。如果閱讀過Pomer簡介Pomer下載與安裝Pomer架構(gòu)介紹 有助于學(xué)習(xí)本文。

          • 概述
            本文主要演示通過blazeds/lcds訪問遠(yuǎn)程EJB,Pomer框架封裝了blazeds/lcds的訪問式,用戶無須添加配置文件,只須在EJBDestinationRegister注冊即可將Java對象發(fā)布成blazeds/lcds的遠(yuǎn)程對象(RemoteObject),進(jìn)行遠(yuǎn)程訪問。


          • 新建EJB項(xiàng)目并增加一個無狀態(tài)的SessionBean
            在Myeclipse中如何新建和布署EJB不在本講解范圍,用戶可參照MyEclipse相關(guān)幫助文檔。
            用戶自己建一個HelloEJB的SessionBean,并增加public String hello(String name)方法; 確認(rèn)HelloEJB可以被遠(yuǎn)程訪問


          • 注冊EJB
            在cn.org.pomer.flex.remoting.services.EJBDestinationRegister的構(gòu)造函數(shù)增加EJB注冊信息。
            復(fù)制內(nèi)容到剪貼板
            代碼:
            public EJBDestinationRegister() {
            super();
            this.list = new ArrayList<EJBDestination>();

            //add here
            add("helloEJB", "HelloServicesImpl/remote");
            }
          • 新建Flex應(yīng)用HelloEJB.mxml
            復(fù)制內(nèi)容到剪貼板
            代碼:
            <?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>
          • 布署運(yùn)行

            • 啟動Tomcat,日志出現(xiàn)如下標(biāo)記,布署成功



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



          • 原理分析
            查看WEB-INF\flex\services- config.xml,EJBRemotingDestinationBootstrapService類從 EJBDestinationRegister類得到所有要遠(yuǎn)程訪問的Ejb,自動加入服務(wù)中。EJBFactory根據(jù) EJBDestinationRegister提供的內(nèi)容自動創(chuàng)建遠(yuǎn)程對象。

          Feedback

          # re: Flex 訪問 Ejb如此簡單  回復(fù)  更多評論   

          2012-03-01 14:33 by akan
          我是特意來感謝的,一個游戲項(xiàng)目做了2年多,還挺火的一個游戲,最近辭職了重新審視架構(gòu)代碼,才發(fā)現(xiàn)用的原來是樓主的框架。這個架構(gòu)對我這個老java程序員,最好的地方是自動生成代碼那塊,省了不少工作量。我希望在通信模塊和db那塊都做些修改,以便更適應(yīng)今天的游戲項(xiàng)目,有了進(jìn)展再來你這里。

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 合水县| 松桃| 张北县| 潮州市| 德保县| 静宁县| 重庆市| 盘锦市| 五家渠市| 米易县| 科技| 奈曼旗| 博兴县| 阿坝县| 中阳县| 武邑县| 明水县| 平和县| 抚远县| 西平县| 全州县| 新丰县| 腾冲县| 凭祥市| 钦州市| 枣阳市| 云霄县| 高雄县| 临夏市| 清丰县| 五河县| 平利县| 耒阳市| 邢台市| 探索| 扬州市| 资源县| 巧家县| 明星| 康保县| 乌海市|