在osgi规范R4.2版本中,定义了分布式的osgi。distribution-cxf是这个规范的一个实现。利用d-cxf可以在osgi环境发布出标准的web service,同样在osgi环境中,也可以引用标准的web service。在distribution-cxf的官方网站中,有几个这样的例子。这里,对于利用spring dm实现的dosgi进行分析
这个demo中,包含了三个bundle:cxf-dosgi-ri-samples-spring-dm-interface,cxf-dosgi-ri-samples-spring-dm-impl,cxf-dosgi-ri-samples-spring-dm-client。
在第一个bundle中定义了要发布的web service的接口,将被export出来,供其他两个bundle应用。DinnerService interface的定义如下:
import java.util.List;
public interface DinnerService {
List<Restaurant> findRestaurants(String searchQuery);
public String testService();
}
在第二个bundle中,一是实现了第一个bundle中定义的接口,更重要的是利用springdm把这个实现发布为一个web service。和利用springdm定义发布出osgi注册服务的定义相同,都是利用osgi:service标签,完成service的发布。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:service interface="org.apache.cxf.dosgi.samples.springdm.DinnerService">
<osgi:service-properties>
<entry key="service.exported.interfaces" value="*" />
<entry key="endpoint.id" value="http://localhost:9000/org/apache/cxf/dosgi/samples/springdm/DinnerService"/>
</osgi:service-properties>
<bean class="org.apache.cxf.dosgi.samples.springdm.impl.DinnerServiceImpl" />
</osgi:service>
</beans>
这个配置文件,同样放在META-INF/spring的目录下,之所以它能够被发布成为一个标准的WebService,是因为在osgi的环境中,除了启动了springdm的bundle,还启动了d-cxf的bundle,这些bundle在springdm的基础上,把这个service发布出来。d-cxf的bundle有两种组织形式,一是单一bundle形式,d-cxf把所有有关的bundle整合成一个bundle,供具体的应用加载;另一种方式是按照d-cxf的依赖,分成多个bundle,两种方式没有本职的区别。
cxf-dosgi-ri-samples-spring-dm-client是在osgi的环境中对上一个实现中发布的web service进行引用,在META-INF/spring目录下,有一个利用springdm引用bundle服务的标准的配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<osgi:reference id="dinnerServiceRef" interface="org.apache.cxf.dosgi.samples.springdm.DinnerService"/>
<bean class="org.apache.cxf.dosgi.samples.springdm.client.DinnerServiceConsumer"
init-method="test">
<property name="dinnerService" ref="dinnerServiceRef"/>
</bean>
</beans>
为了在分布的环境中引用WebService,就需要知道另外的一个进程中的service的发布情况和如何应用它,于是,在client bundle中,加入了一个目录OSGI-INF,在其中的remote-service目录,定义了对于远程服务的应用配置:
<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
<endpoint-description>
<property name="objectClass">
<array>
<value>org.apache.cxf.dosgi.samples.springdm.DinnerService</value>
</array>
</property>
<property name="endpoint.id">http://169.254.78.194:9000/org/apache/cxf/dosgi/samples/springdm/DinnerService</property>
<property name="service.imported.configs">org.apache.cxf.ws</property>
</endpoint-description>
</endpoint-descriptions>
对于熟悉ServiceMix的人,endpoint一定是一个非常熟悉的概念,事实上d-cxf中ServiceMix的一些bundle来管理在dosgi环境中WebService发布和应用的。
分享到:
相关推荐
cxf-dosgi-ri-singlebundle-distribution-1.4.0.jar
cxf-dosgi-ri-multibundle-distribution-1.5.0-dir
apache-cxf-2.7.6.rar webservice
apache-cxf-2.2.4 工具类
apache-cxf 2.2.8 支持webservice 反正生成服务端代码,附带一个文本文件。希望有需要的小伙伴可以下载来看。
apache-cxf-3.1.6官方版,其中有spring包。2016-4-14最新版。
apache-cxf-2.6.1.zip cxf转化wsdl文件,生成javaBean实体类 附上使用文章:http://blog.csdn.net/sinat_34979884/article/details/78776305
Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构。
apache-cxf-2.5.2
apache-cxf-2.2.10所有的jar,无需在一个一个的去找了。cxf.jar commons-logging.jar neethi.jar jaxb-api.jar jaxb-impl.jar stax-api.jar 由于上传大小有限无法一次性传全部,在这分为2次上传。 apache-cxf-2.2.10...
apache-cxf-3.0.13官方完整jar包,包含bin目录和api文档,还有完整的simple来参考。可与spring3.2.0完美整合。
cxf自动生成webservice客户端,apache-cxf-2.7.18最稳定的版本 apache cxf 框架wsdl2java命令的使用。 -encoding是指定编码类型; -p 指定包名 -d 指定生成目录 -all生成服务端和客户端代码 -...
apache-cxf-2.3.5(2)-src.zipapache-cxf-2.3.5(2)-src.zip
apache-cxf-2.2.1可下载 apache-cxf-2.2.1可下载
apache-cxf 2.7.6 包含apache-cxf所有jar包,用于cxf开发,可能用于生成webservice 客户端和服务端
tools的工具包,axis2,apache-cxf
apche-cxf-2.7.11完整包,apche-cxf-2.7.11完整包apche-cxf-2.7.11完整包
apache-cxf-2.7.18-src.zip
apache-cxf-2.7.11是cxf较新的版本,支持jdk1.7
WebService接口开发,apache-cxf的压缩包,Apache-cxf资源