• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
平衡适可而止
博客园    首页    新随笔    联系   管理    订阅  订阅

关于BlazeDS服务器中的Httpservice代理使用

BlazeDS 是一个基于服务器的 Java 远程控制 (remoting) 和 Web 消息传递 (messaging) 技术,它能够使得后端的 Java 应用程序和运行在浏览器上的 Adobe Flex 应用程序相互通信。这篇文章中,我讲述一种方法(也许不是最好的)使得我能够成功地利用 BlazeDS 和 Flex 建立一个简单的程序。使用的 IDE 是 eclipse, 而并非 Flex Builder.
    下面介绍一个简单的实例来引大家入门
    <?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组建
posted @ 2010-01-18 14:21  平衡适可而止  阅读(818)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3