关于BlazeDS服务器中的Httpservice代理使用
下面介绍一个简单的实例来引大家入门
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” fontSize=”15″ layout=”absolute” initialize=”init()”>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function init():void{
btn.addEventListener(MouseEvent.CLICK,btn_click);
}
private function btn_click(evt:MouseEvent):void{
//Alert.show(“你好”);
srv.send();
}
private function httpService_fault(evt:ResultEvent):void{
//这是一个XML文档不能这么解析
Alert.show(“”+evt.result);
}
]]>
</mx:Script>
<!– 这种数据绑定还是比较简单的
<mx:HTTPService id=”srv” destination=”catalog” useProxy=”true”/>
<mx:DataGrid dataProvider=”{srv.lastResult.catalog.product}” width=”100%” height=”100%”/>
<mx:Button label=”Get Data” click=”srv.send()”/>
–>
<!– 使用了配置文件来访问服务器端的jsp文件 –>
<mx:HTTPService id=”srv” destination=”catalog” useProxy=”true” result=”httpService_fault(event);”/>
<mx:DataGrid dataProvider=”{srv.lastResult.catalog.product}” width=”100%” height=”100%”/>
<mx:Button label=”Get data” id=”btn”/>
</mx:Application>
在proxy_config.xml文件中的配置如下
<?xml version=”1.0″ encoding=”UTF-8″?>
<service id=”proxy-service”
class=”flex.messaging.services.HTTPProxyService”>
<properties>
<connection-manager>
<max-total-connections>100</max-total-connections>
<default-max-connections-per-host>2</default-max-connections-per-host>
</connection-manager>
<allow-lax-ssl>true</allow-lax-ssl>
</properties>
<adapters>
<adapter-definition id=”http-proxy” class=”flex.messaging.services.http.HTTPProxyAdapter” default=”true”/>
<adapter-definition id=”soap-proxy” class=”flex.messaging.services.http.SOAPProxyAdapter”/>
</adapters>
<default-channels>
<channel ref=”my-amf”/>
</default-channels>
<destination id=”DefaultHTTP”>
</destination>
<destination id=”catalog”>
<properties>
<url>/{context.root}/categet.jsp</url>
</properties>
</destination>
</service>
其中的categet.jsp 文件放在工程目录下 <url>/{context.root}/categet.jsp</url>是用于访问该文件。
categet.jsp
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
<?xml version=”1.0″ encoding=”utf-8″?>
<catalog>
<product productId=”1″>
<name>Good1</name>
<description>itsme</description>
<price>17173</price>
<image>nihao</image>
<category>niasd</category>
<qtyInStock>woasdasd</qtyInStock>
</product>
<product productId=”2″>
<name>Good1</name>
<description>itsme</description>
<price>17173</price>
<image>nihao</image>
<category>niasd</category>
<qtyInStock>woasdasd</qtyInStock>
</product>
<product productId=”3″>
<name>Good1</name>
<description>itsme</description>
<price>17173</price>
<image>nihao</image>
<category>niasd</category>
<qtyInStock>woasdasd</qtyInStock>
</product>
<product productId=”4″>
<name>Good1</name>
<description>itsme</description>
<price>17173</price>
<image>nihao</image>
<category>niasd</category>
<qtyInStock>woasdasd</qtyInStock>
</product>
</catalog>
返回给客户端的是一个xml文件,用于填充datagrid组建