OSGI整合FLEX

http://blog.sina.com.cn/s/blog_50af6d3801009pms.html
本文内容我没有验证过,仅仅是转过来,备用
一、目标
1、可以将flex编译产生的*.swf、*.as、*.css、图片等资源文件按模块分开打包,最后将这些资源发布成web服务
2、可以将实现按模块分bundle
二、普通方式下的flex实现
此处,采用flex的amf协议
1、web.xml文件
从web.xml中的servlet可以看出,由flex.messaging.MessageBrokerServlet来处理amf协议请求,同时分别需要提供services-config.xml的配置文件及flex目录来读取诸如remoting-config.xml等配置文件
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>
flex.messaging.MessageBrokerServlet
</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<init-param>
<param-name>flex.write.path</param-name>
<param-value>/WEB-INF/flex</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
2、
三、osgi整合
1、发布servlet及资源
在Activator implements BundleActivator的start()方法中添加
下面相关的引用自己先搞定,可以参考后面会发布的一篇文章
待发:《使用org.osgi.service.http.HttpService发布web资源》

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpService;
import flex.messaging.MessageBrokerServlet;

ServiceReference sr = context.getServiceReference(HttpService.class
.getName());
httpService = (HttpService) context.getService(sr);
// 保存全局的资源发布对象
Constant.httpService = httpService;
// 原web.xml中的MessageBrokerServlet的初始化参数
Dictionary<String, String> initparams = new Hashtable<String, String>();
initparams.put("services.configuration.file",
Constant.FLEX_PROJECT_CATALOG
+ Constant.SERVICES_CONFIGURATION_FILE);//设置找到路径即可
initparams.put("flex.write.path", Constant.FLEX_PROJECT_CATALOG
+ Constant.FLEX_WRITE_PATH);
initparams.put("load-on-startup", "1");
// 发布MessageBrokerServlet
httpService.registerServlet("/messagebroker",
new MessageBrokerServlet(), initparams, null);

扩展org.eclipse.equinox.http.registry的扩展点发布资源

httpService.registerResources("/base", "net/oupu/drp/base/client/flex/webapp", null);
上面这段代码,将net/oupu/drp/base/client/flex/webapp发布为路径base的资源,如访问
http://ip:port/base/index.swf
即是访问net/oupu/drp/base/client/flex/webapp下的index.swf文件

2、在remoting-config.xml中添加对应的destination
<destination id="*Service">
<properties>
<source>you_package.*Service</source>
</properties>
</destination>
you_package.*Service为提供方法的实现类

flex中通过endpoit,destination 的方式通过amf协议调用java类

3、动态扩展

部分代码设密,只说明一下思路

由于对于每一个service,都要去配置remoting-config.xml
所以,这里,我们可以只写一个destination,通过as文件来全局调用这一个
只需要将方法名,类全名,参数。传递过来
在you_package.*Service类中通过反射的方法来调用对应的类来处理或返回给flex前端
同时,为了as与java之间的传值比较方便,
可以在将as的object通过jasn转成java的object
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值