FLEX 與JAVA的LCDS BLAZEDS配置.

來源:互聯網
上載者:User

FLEX 與JAVA的LCDS BLAZEDS配置.
1.構架原理
Flash Remoting的原理類似於Resin的Hessian,都是使用基於HTTP協議的輕量級二進位協議,即AMF。

Flash Remoting使用AMF來和伺服器通訊。基本過程的原理可以參考Flash網站上面的文檔。簡單來說就是在伺服器端,需要有一個Servlet,接收Flash的HTTP請求,然後把AMF格式封裝的HTTP請求解析成為對伺服器端對象的調用(例如調用Java的業務對象);在用戶端,Flash Remoting API接收伺服器端的HTTP Response,把AMF格式封裝的Response解析成為Flash 資料對象。

採用Flash Remoting方式下的軟體架構如下:

Flash(Client) <-----(HTTP AMF)----> Spring Bean(Server) <-> Hibernate PO

由上面可以看到,傳統的Web層完全被砍掉了,Flash通過AMF協議和Gateway的轉換,可以直接存取伺服器端的 Bean。

2.修改WEB.XML,加入Servlet配置..

<servlet><br /> <servlet-name>MessageBrokerServlet</servlet-name><br /> <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class><br /> <init-param><br /> <param-name>services.configuration.file</param-name><br /> <param-value>/WEB-INF/flex/services-config.xml</param-value><br /> </init-param><br /> <load-on-startup>1</load-on-startup><br /> </servlet></p><p><servlet-mapping><br /><servlet-name>MessageBrokerServlet</servlet-name><br /><url-pattern>/messagebroker/*</url-pattern><br /></servlet-mapping>

3.在WEB-INF/LIB下加入以下JAR包 (以上JAR包來源於下載的BLAZEDS庫包)
commons-httpclient-3.0.1.jar
flex-messaging-common.jar
flex-messaging-core.jar
flex-messaging-opt.jar
flex-messaging-proxy.jar
flex-messaging-remoting.jar
flex-rds-server.jar

4.在WEB-INF/flex下加入設定檔(以上設定檔來源於下載的BLAZEDS庫包)
services-config.xml
messaging-config.xml
proxy-config.xml
remoting-config.xml

至此,JAVA端的AMF已經配置OK.....

先測試一下:
將commons-httpclient-3.0.1.jar刪除.輸入以下URL
http://localhost:8080/baosteel_sgm/messagebroker/amf
會顯示HTTP Status 500 - 錯誤
javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/httpclient/UsernamePasswordCredentials
這時說明配置已經起作用了..
將commons-httpclient-3.0.jar放回去以便下一步使用 ...

 

5.建立JAVA測試類別
package com;

public class Hello {

//定義一個方法返回字串,等待遠程調用。

public String HelloLCDSRemoting(String name){

return "Hello"+name+"LCDS";

}

}

6.修改WEB-INF/flex/remoting-config.xml,加入以下內容

 

 

 

<destination id="HelloRemoting"><br /> <properties><br /> <source> com.Hello</source><br /> </properties><br /> </destination>

 

然後將WEB伺服器運行起來

7.下來開始FLEX端配置:
在FLEX BUILDE項目上查看屬性,>FLEX 伺服器:: 應用伺服器選J2EE.
溝選"使用遠端存取服務", BLAZE DS.
在"伺服器位置"TAB中,配置如下:
根資料夾:E:/baosteel_sgm
根URL : http://localhost:8080/baosteel_sgm
上下文根目錄 : /baosteel_sgm

點擊"驗證配置" ,此要求WEB伺服器啟動起來才可以難通過...

這時"確定"按鈕才可以用了..點擊儲存...

 

如果伺服器不在運行,無法驗證通過,可以直接更改項目下的.flexProperties檔案,內容如下


<?xml version="1.0" encoding="UTF-8" standalone="no"?><br /><flexProperties enableServiceManager="false" flexServerFeatures="4" flexServerType="2" serverContextRoot="/baosteel_sgm" </p><p>serverRoot="E:/baosteel_sgm" serverRootURL="http://localhost:8080/baosteel_sgm" toolCompile="true" useServerFlexSDK="false" </p><p>version="2"/><br />

8.建立FLEX測試代碼

protected function button11_clickHandler(event:MouseEvent):void
{

var HelloJava:RemoteObject=new RemoteObject("HelloRemoting");

//添加調用成功和調用失敗的監聽

HelloJava.addEventListener(FaultEvent.FAULT,HelloJavaFault);

HelloJava.addEventListener(ResultEvent.RESULT,HelloJavaResult);

HelloJava.HelloLCDSRemoting(" tata ");

}

//聲明調用失敗的監聽函數

private function HelloJavaFault(event:FaultEvent):void{

//顯示錯誤資訊

Alert.show(event.message.toString(),"調用失敗");

}

//聲明調用成功的監聽函數

private function HelloJavaResult(event:ResultEvent):void{

//顯示返回結果

Alert.show(String(event.result),"調用成功");

}

 

Powered by Zoundry

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.