Hessian 与 OSGi ( spring dm server )
的整合
一、 目录结构:
remote
import :用来导入 hessian 服务
export :用来导出 hessian 服务
二、 导出( export )
Bundle 名: remote.export
hessian 服务器设置: (以 operator 为例)
1. 需要导入的外部 bundle (在 MANIFEST.MF 文件中)
Import-Bundle: com.springsource.com.caucho;version="[3.1.5,3.1.5]"
2. 需要导入的 package (在 MANIFEST.MF 文件中)
Import-Package: com.**.**.**.operator.service,
com.**.**.**.operator.domain
3. 需要引入的服务(在 osgi-context.xml 文件中)
<reference id="operatorService" interface="com .**.**.**. operator.service.IOperatorService" />
4. 在 META-INF/spring/remote-servlet.xml 中将需要导出的服务发布为 hessian 服务
<!-- 操作员 -->
< bean name = "/remoteOperatorService" class = "org.springframework.remoting.caucho.HessianServiceExporter" >
< property name = "service" >
< ref bean = "operatorService" />
</ property >
< property name = "serviceInterface" >
< value > com.**.**.**.operator.service.IOperatorService </ value >
</ property >
</ bean >
5. 在 MANIFEST.MF 中添加设置:
Web-DispatcherServletUrlPatterns: /remoting/*
设置 hessian 请求的格式
6. 完成 hessian 服务器端的设置
三、 导入( import )
Bundle 名: remote.imports
导入的处理有两种方式:
1. 只导入 hessian 服务并发布
import 中只需要两个包: domain 和 interface
Domain 中放远程服务用的到对象
Interface 存放远程服务接口
步骤:
A. 导入 bundle : com.springsource.com.caucho;version="[3.1.5,3.1.5]"
B. 在 module-context.xml 中建 bean
< bean id = "operatorServiceImpl"
class = "org.springframework.remoting.caucho.HessianProxyFactoryBean" >
< property name = "serviceUrl " >
< value > http://**.**.**.com:8080/**/remote/remoting/remoteOperatorService </ value >
</ property >
< property name = "serviceInterface " >
< value > com.**.**.**.remote.imports.interfaces.IOperatorService </ value >
</ property >
</ bean >
C. 在 osgi-context.xml 中发布服务
< service id = "operatorService" ref = " operatorServiceImpl "
interface = " com.**.**.**.remote.imports.interfaces.IOperatorService " />
D. 完成 hessian 客户端
2. 导入 hessian 服务并进行封装,然后发布封装好的服务
Import 中需要四个包: domain, interface, service, service.impl
在 service 和 service.impl 中对远程接口进行封装。
步骤:
A. 需要导入 bundle :
com.springsource.com.caucho;version="[3.1.5,3.1.5]"
B. module-context.xml 中建 bean :
< bean id = "operatorService"
class = "org.springframework.remoting.caucho.HessianProxyFactoryBean" >
< property name = "serviceUrl " >
< value > http://**.**.**.com:8080/**/remote/remoting/remoteOperatorService </ value >
</ property >
< property name = "serviceInterface " >
< value > com.**.**.**.remote.imports.interfaces.IOperatorService </ value >
</ property >
</ bean >
C. 在包 service.impl 中调用 operatorService ,对其进行封装,然后将封装后的服务发布出去
D. 完成 hessian 服务的客户端。