BlazeDS來源網站連結參考
BlazeDS請於Adobe Open Source網站下載
BlazeDS下載首頁,可選擇一般檔案下載或原碼下載(SVN)。
BlazeDS一般檔案下載頁。
BlazeDS Source Code下載頁。
這篇文章將會使用一般檔案安裝。
安裝步驟:
Step1.配置JDK環境
請參考
- Linux上配置JDK (如果你測試執行結果不是使用Sun JAVA可以參考install Sun JAVA)
- install Sun JAVA
- Linux 上安裝 Eclipse (下載javaEE版本)
- Linux 安裝tomcat6
Step2.下載BlazeDS
- 進入一般檔案下載頁
- 點擊Release Builds下方的連結點Download the latest BlazeDS Release builds,進入檔案下載頁面。
- 點擊後會進入Adobe下載頁面,輸入你在Adobe註冊的帳號與密碼。
- 登入完畢後會出現BlazeDS的使用條款,點擊IAgree(我同意)。
- 選擇Binary Distribution版本下載(這個版本沒有內含Tomcat,因為我們選擇自己安裝Tomcat)。
下載頁面也有列出BlazeDS的技術支援表:
BlazeDS不支援Hibernate adapter,但有支援Spring
在ubuntu使用firefox下載完後檔案會預設存放在home/Downloads裡面
Step3.將BlazeDS解壓縮(解ZIP)
- /~Downloads$ unzip blazeds-bin-4.0.0.14931.zip
Step4.將blazeds.war放置tomcat6中的webapps目錄下
tomcat6預設上會將war解壓
webapps是tomcat6預設的web資料夾位置
- /~Downloads$ sudo mv blazeds.war /opt/tomcat6/webapps
Step5.修改blazeds名稱成為blazedsAMF
- /opt/tomcat6/webapps$ sudo mv blazeds blazedsAMF
- /opt/tomcat6/webapps$ sudo rm blazeds.war
Step7.利用Eclipse開啟java專案 (這個檔案沒有使用servlet)
- 新增一專案,名稱remoteUT
- 新增一package,com.jt.remote
- 新增一檔案,Hello.java
Step7.建立Hello.java程式內容
package com.jt.remote;
public class Hello
{
public Hello()
{
super();
}
public String getHello()
{
return "Hello World";
}
//test private
private String getPackage()
{
return "com.jt.remote";
}
public String echoHello(String value)
{
return value + "Hello World";
}
}
public class Hello
{
public Hello()
{
super();
}
public String getHello()
{
return "Hello World";
}
//test private
private String getPackage()
{
return "com.jt.remote";
}
public String echoHello(String value)
{
return value + "Hello World";
}
}
Step8.將remoteUT裡的src複製到blazedsAMF/WEB-INF/src底下
- ~/workspace$ cp -a -r remoteUT/src/com /opt/tomcat6/webapps/blazedsAMF/WEB-INF/src/
- ubuntu:/opt/tomcat6/webapps/blazedsAMF/WEB-INF/src$
javac -d ../classes com/jt/remote/Hello.java
編譯完成,可以在WEB-INF/classes中看見com/jt/remote/Hello.class
- sudo gedit /opt/tomcat6/webapps/blazedsAMF/WEB-INF/flex/remoting-config.xml
<destination id="Remote_SayHello">
<properties>
<source>com.jt.remote.Hello</source>
</properties>
</destination>
Step11.重新啟動Tomcat
- /opt/tomcat6/bin$ ./startup.sh
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
applicationComplete="completeHandler(event)"
>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.Operation;
import mx.rpc.remoting.RemoteObject;
//Remote Operation
private var _channelSet:ChannelSet;
private var _amfChannel:AMFChannel;
private var _getHelloRemoteObject:RemoteObject;
private var _echoHelloRemoteObject:RemoteObject;
private var _getHelloOperation:Operation;
private var _echoHelloOperation:Operation;
private var _getHelloData:Object;
private var _echoHelloData:Object;
protected function completeHandler(event:FlexEvent):void
{
initRemoteData();
initRemoteOpertion();
initBtnListener();
}
private function initRemoteData():void
{
_getHelloData = createRemoteData("getHello");
_echoHelloData = createRemoteData("echoHello");
}
protected function createRemoteData(methodName:String):Object
{
var data:Object = new Object();
//blazeds的AMF Server Service服務位址
data.uri = "http://192.168.2.103:8400/blazedsAMF/messagebroker/amf";
data.channelSetID = "my-amf";
//服務程式來源path(由classes之後算起)
data.source = "com.jt.remote.Hello";
//操作method名稱
data.name = methodName;
data.destination = "Remote_SayHello";
return data;
}
private function initRemoteOpertion():void
{
initChannelSet();
initAMFChannel();
addChannel();
initRemoteObject();
initOperation();
afterInitOPeration();
}
private function initChannelSet():void
{
_channelSet = new ChannelSet();
}
private function initAMFChannel():void
{
_amfChannel = new AMFChannel(_getHelloData.channelSetID , _getHelloData.uri);
}
private function addChannel():void
{
_channelSet.addChannel(_amfChannel);
}
private function initRemoteObject():void
{
_getHelloRemoteObject = new RemoteObject();
_getHelloRemoteObject.destination = _getHelloData.destination;
_getHelloRemoteObject.channelSet = _channelSet;
_getHelloRemoteObject.source = _getHelloData.source;
_echoHelloRemoteObject = new RemoteObject();
_echoHelloRemoteObject.destination = _echoHelloData.destination;
_echoHelloRemoteObject.channelSet = _channelSet;
_echoHelloRemoteObject.source = _echoHelloData.source;
}
private function initOperation():void
{
_getHelloOperation = new Operation();
_getHelloOperation.name = _getHelloData.name;
_echoHelloOperation = new Operation();
_echoHelloOperation.name = _echoHelloData.name;
}
private function afterInitOPeration():void
{
_getHelloRemoteObject.operations = {getHello:_getHelloOperation};
_echoHelloRemoteObject.operations = {echoHello:_echoHelloOperation};
_getHelloRemoteObject.addEventListener(ResultEvent.RESULT , getHelloResult);
_getHelloRemoteObject.addEventListener(FaultEvent.FAULT , getHelloFault);
_echoHelloRemoteObject.addEventListener(ResultEvent.RESULT , echoHelloResult);
_echoHelloRemoteObject.addEventListener(FaultEvent.FAULT , echotHelloFault);
}
private function getHelloResult(e:ResultEvent):void
{
getHelloOutput.text = e.result.toString();
}
private function getHelloFault(e:FaultEvent):void
{
getHelloOutput.text = "Remote失敗";
}
protected function echoHelloResult(e:ResultEvent):void
{
output.text = e.result.toString();
}
protected function echotHelloFault(e:FaultEvent):void
{
output.text = "Remote失敗";
}
private function initBtnListener():void
{
getHelloBtn.addEventListener(MouseEvent.MOUSE_DOWN , callGetHello);
echoHelloBtn.addEventListener(MouseEvent.MOUSE_DOWN , callEchoHello);
}
protected function callGetHello(event:MouseEvent):void
{
_getHelloRemoteObject.getHello();
}
protected function callEchoHello(event:MouseEvent):void
{
_echoHelloRemoteObject.echoHello(input.text);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Panel width="300" height="200" title="echoHello">
<s:layout>
<s:VerticalLayout gap="2" paddingTop="5"/>
</s:layout>
<s:HGroup width="100%" >
<s:Label text="回傳結果"/>
<s:TextInput id="output"/>
</s:HGroup>
<s:HGroup width="100%">
<s:Label text="輸入數值"/>
<s:TextInput id="input"/>
</s:HGroup>
<s:Button id="echoHelloBtn" label="call echoHello"/>
</s:Panel>
<s:Panel width="300" height="200" title="getHello">
<s:layout>
<s:VerticalLayout gap="2" paddingTop="5"/>
</s:layout>
<s:HGroup width="100%" >
<s:Label text="回傳結果"/>
<s:TextInput id="getHelloOutput"/>
</s:HGroup>
<s:Button id="getHelloBtn" label="call getHello" />
</s:Panel>
</s:Application>
輸出畫面:
下次將來測試一下Servlet與Mapping Value Object
沒有留言:
張貼留言