- 浏览: 283359 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
IXHONG:
我买了一本,是英文的,市面上现在有中文的吗
介绍关于Apache ActiveMQ 和 Apache Camel的两本书 -
baso4233:
喔,这几篇是 camel-manual 中的中文版。
Camel中的几个重要概念之 Message和Exchange -
baso4233:
学习了。
Camel中的几个重要概念之Routes, RouteBuilders 和 Java DSL -
sswh:
请教一下,使用camel自带的例子,camel-example ...
Camel 2.8.4 发布了 -
TheMatrix:
最近在学习cxf,楼主有什么可以指点的吗? :)
JAX-WS
最近在cxf-zh中有人问及了有关Spring配置CXF Client以及Server的问题,由于我前段时间也做一部分相关的工作,在这里我简单给大家介绍一下CXF在与Spring集成方面所做的一些工作。
如果大家只是想了解如何写jaxws:endpoint 配置文件,可以直接跳到 3 jaxws:endpoing进行阅读.
0. 预备知识
如果你想了解CXF是如何与Spring进行集成的,首先你需要下载CXF代码,编译,然后生成相关的Eclipse工程文件。
具体的步骤在CXF wiki 上有说明
1. 基本原理
CXF采用的是Spring2.0提供的一个新接口就是扩展的NamespaceHandler。通过注册相关的NamespaceHandler以及xsd,在Spring处理到对应Namespace下的XML元素时将会调用NamespaceHandler中注册的Parser来进行处理。
瞧是不是挺简单的。
具体代码位置 Project: cxf-rt-frontend-jaxws
源代码 src/main/java Package org.apache.cxf.jaxws.spring
测试 src/test/java Package org.apache.cxf.jaxws.spring
schema: jaxws.xsd src/main/resources schemas
2. jaxws namespace
在jaxws.xsd中,你将看到有关 jaxws:endpoint, jaxws:server, jaxws:client的定义。
这里需要说明的内容有三点:- jaxws的target namespace是 http://cxf.apache.org/jaxws,由于目前CXF还处于incubating 的状态,没有cxf.apache.org这个域名。为了能让Spring来进行xml文档校验的时候能够获得jaxws.xsd,Spring提供了一种通过ClassPath中获得jaxws.xsd方法。具体步骤如下就是在META-INF中添加spring.schema的方式将jaxws.xsd与对应的URI进行绑定,同时也需要将NamespaceHandler注册进Spring中。
- jaxws:endpoint 与 jaxws:server是对等的,他们都是对Web Services 服务端的描述。只是在JAXWS RI在最初的实现过程中,对于Server端的配置是通过Endpoint来进行描述的,而且JAXWS API也定义了Endpoint,因此为了保持与JAXWS API的一致性,在这里设置了jaxws:endpoint。
- jaxws front end 与 simple front end之间的关系。 CXF除了提供JAXWS 的实现,也延续Xfire的风格提供了简单POJO Web Services的实现前端 simple front end。Jaxws front end 继承了simple front end的绝大部分方法,它与simple front end 的最大不同就是提供了Web Services Meta data (JSR 181)的支持,提供从Annotation中获取Web Services的能力。对于 jaxws:server 以及 jaxws:client 你可以在 simple front end中找到对应的 simple:server , simple:client。
3. jaxws:endpoint示例
我们知道Spring为我们提供了一个很好的Dependence Injection的容器,我们可以通过XML在不修改任何Java Code的情况下,通过配置改变Spring beans 之间的属性。下面是endpoint的 schema,我们将结合schema向大家介绍有关spring的配置和使用。- <xsd:schema xmlns="http://cxf.apache.org/jaxws"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:cxf-beans="http://cxf.apache.org/configuration/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- targetNamespace="http://cxf.apache.org/jaxws"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified" >
- <xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd"/>
- <xsd:import namespace="http://cxf.apache.org/configuration/beans" schemaLocation="http://cxf.apache.org/schemas/configuration/cxf-beans.xsd"/>
- <xsd:element name="endpoint">
- <xsd:complexType>
- <xsd:complexContent>
- <xsd:extension base="beans:identifiedType">
- <xsd:all>
- <xsd:element name="binding" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="dataBinding" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="executor" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="features" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="implementor" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="inInterceptors" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="inFaultInterceptors" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="invoker" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="outInterceptors" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="outFaultInterceptors" type="xsd:anyType" minOccurs="0" />
- <xsd:element name="properties" type="beans:mapType" minOccurs="0" />
- <xsd:element name="schemaLocations" type="schemasType" minOccurs="0" />
- <xsd:element name="serviceFactory" type="xsd:anyType" minOccurs="0" />
- <!---->xsd:all>
- <xsd:attributeGroup ref="cxf-beans:beanAttributes" />
- <xsd:attribute name="address" type="xsd:string" />
- <xsd:attribute name="bindingUri" type="xsd:string" />
- <xsd:attribute name="bus" type="xsd:string" />
- <xsd:attribute name="implementor" type="xsd:string"/>
- <xsd:attribute name="implementorClass" type="xsd:string"/>
- <xsd:attribute name="publish" type="xsd:boolean" default="true"/>
- <xsd:attribute name="endpointName" type="xsd:QName" />
- <xsd:attribute name="serviceName" type="xsd:QName" />
- <xsd:attribute name="wsdlLocation" type="xsd:string" />
- <!---->xsd:extension>
- <!---->xsd:complexContent>
- <!---->xsd:complexType>
- <!---->xsd:element>
- <!---->xsd:schema>
这里设置的endpoint中的很多子元素都定义成为了 xsd:anyType, 这是为了能通过原有Spring bean的方式来初始化具体的实例。例如: implementor 这个子元素。
xml 代码 - <jaxws:endpoint id="inlineImplementor" address="http://localhost:8080/simpleWithAddress">
- <jaxws:implementor>
- <bean class="org.apache.hello_world_soap_http.GreeterImpl">
- <property name="prefix" value="hello" />
- <!---->bean>
- <!---->jaxws:implementor>
- <!---->jaxws:endpoint>
当然对于properties来说,就是采用了spring中内建的Map类型的支持,具体的使用实例如下:
- <jaxws:endpoint id="withProerties" implementor="org.apache.hello_world_soap_http.GreeterImpl" address="http://localhost:8080/simpleWithAddress">
- <jaxws:properties>
- <entry key="Content-Type" value="text/plain" />
- <entry>
- <key>
- <value>javax.xml.stream.XMLInputFactory<!---->value>
- <!---->key>
- <ref bean="mappedXMLInputFactory"/">
- <!---->entry>
- <entry>
- <key>
- <value>javax.xml.stream.XMLOutputFactory<!---->value>
- <!---->key>
- <ref bean="mappedXMLOutputFactory"/">
- <!---->entry>
- <!---->jaxws:properties>
- <!---->jaxws:endpoint>
好现在看一下如何配置属性(attribute) jaxws:endpoint 也提供了对 implementor描述的属性, 当我们将 implementor定义成为一个java class时我们可以这样写
- <jaxws:endpoint id="implementor" implementor="org.apache.hello_world_soap_http.GreeterImpl" address="http://localhost:8080/simpleWithAddress"/>
<jaxws></jaxws>
当我们考虑将implementor定义成为一个bean的引用,就应该写成
<jaxws></jaxws>xml 代码 - <jaxws:endpoint id="implementor" implementor="#GreeterImpl" address="http://localhost:8080/simpleWithAddress"/>
这里再讲一下endpointName和serviceName的写法,大家可以看到这两个属性的类型都是Qname
- <jaxws:endpoint id="withEndpiontName" implementor="org.apache.cxf.jaxws.service.Hello" endpointname="e:HelloEndpointCustomized" servicename="s:HelloServiceCustomized" address="http://localhost:8080/test" />
<jaxws></jaxws>
4. EndpointDefinitionParser
看了上面的jaxws:endpoint 示例,大家可能会向CXF是如何将这些XML文件映射成为具体的 Jaxws Endpoint 呢? 有心的朋友只要看一下 EndpointDefinitionParser 就能略知一二了。
请注意 EndpointDefinitionParser的构造函数,里面调用了setBeanClass(EndpointImpl.class);当当我们的要设置的主角终于登场了。 再则就是 protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean),如果你要配置自己的Bean对象,就需要花点功夫在这个函数上面了。
今天的介绍先到这,有兴趣的朋友可以用同样的方法来研究有关 jaxws:server以及jaxws:client的具体实现,还有我会在后面的文章中介绍在CXF中有关doParser的更为复杂的实现。
评论
spring.schema
spring.handlers
https://svn.apache.org/repos/asf/cxf/trunk/rt/frontend/jaxws/src/main/resources/META-INF
在META-INF中添加spring.schema的方式将jaxws.xsd与对应的URI进行绑定,同时也需要将NamespaceHandler注册进Spring中
发表评论
-
Camel中的几个重要概念之 Endpoint
2009-01-22 22:43 8066前段时间和一些朋友聊 ... -
CXF 2.0.5 发布了
2008-04-01 22:34 2145这个版本应该是CXF 在Apache incubator下面的 ... -
CXF 2.0.4 Released
2008-01-30 10:29 1934CXF 2.0.4 已经正式发布了,大家可以通过下面的地址下载 ... -
How to configure CXF HTTP Client
2007-12-03 18:41 3994前段时间看到邮件列表中提到很多有关设置CXF HTTP Cli ... -
我眼中的CXF之Configuration
2007-10-05 10:11 5006对于一个成熟的软件产品来说,都会涉及到配置这块的内容。对于CX ... -
CXF 2.0.2 发布了
2007-09-26 09:40 5345经过快一个月的投票,CXF2.0.2 终于发布了。 下面是从C ... -
Web Services Client & Server message invocation steps
2007-09-02 07:00 2533自从JavaEye将CXF2.0发布的消息置顶之后,我一下收到 ... -
Study Resources of Web Services with Java
2007-09-02 07:14 3401最近收到几个朋友得来信都聊到了学习Web Services的 ... -
CXF 2.0.1 发布
2007-08-21 11:17 3378The Apache Incubator CXF team i ... -
CXF 2.0 发布了
2007-07-10 16:55 14247虽然这篇帖子写得有的晚了,但是还是想把CXF 2.0 发布的消 ... -
我眼中的CXF之 Interceptor (上)
2007-06-30 11:36 3769Interceptor是CXF架构中一 ... -
我眼中的CXF之 Interceptor (下)
2007-06-30 11:39 2801下面给大家介绍一下Inte ... -
我眼中的CXF之Bus
2007-06-24 13:03 5908CXF在设计之初就提供了对多种的Binding,Transpo ... -
我眼中的CXF 之 ServiceModel
2007-06-05 09:44 4015在前面的文章中给大家简单介绍了CXF是如何和将一个POJO变成 ... -
JBI与SCA的区别
2006-03-05 08:00 3622最近我在做有关ESB的开发工作,发现我们的产品(开 ... -
REST 相关
2006-10-19 13:20 2266最近由于工作需要,研 ... -
JAX-WS
2006-10-22 06:03 18608CXF 支持的JAX-WS 的API,那什么是JAX-WS ... -
何为CXF?
2007-05-20 09:54 5861前几天碰见同学问我在忙什么, 我说我在做开源软件CXF。随后的 ...
相关推荐
webserivce.、cxf整合spring,用的是spring3和cxf3。欢迎大家下载尝试
cxf+spring实现webservice
WebService的CXF整合Spring有源码和jar包
CXF和Spring搭建webservice代码
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
利用CXF和Spring结合搭建的SOA例子,内容包含服务端配置和一个客户端测试配置,服务器端服务配置在beans.xml中,web.xml文件需要修改;客户端测试配置地址是demo.spring.client下的client-beans.xml,测试类为...
CXF+spring+struts实现WebService
cxf+spring开发所必备的jar包压缩包
CXF源码:CXF_Spring源码 CXF源码:CXF_Spring源码
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
cxf+spring整合,只要把项目导入到myeclipse中,就可以运行。
基于maven的cxf+spring简单demo,spring版本为4.1.6,cxf版本为3.0.8
cxf与spring集成 需要最少的jar如下: cxf-2.3.3.jar geronimo-annotation_1.0_spec-1.1.1.jar geronimo-jaxws_2.2_spec-1.0.jar geronimo-stax-api_1.0_spec-1.0.1.jar geronimo-ws-metadata_2.0_spec-1.1.3.jar ...
cxf+spring+client+springmvc
CXF整合Spring需要用到的JAR包
cxf与Spring一个简单的小例子,希望多初学者有所帮助。不明白的联系我
cxf spring maven 实例 webservice
最完整的的cxf与spring整合需要的jar文件
第一天: 什么是webservice? 从案例(便民查询网站)分析如何实现? 使用socket实现。 使用jaxws开发webservice。... Spring+cxf整合(重点) CXF发布rest的webservice。(重点) 综合案例: 实现便民查询网站
CXF集成Spring发布WebService代码实例