`
nlslzf
  • 浏览: 1026518 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics