---
title: "Apache CXF notes"
author: "卡拉阿风"
date: "2010-12-14T14:44:54Z"
tags: ["Apache", "SOAP", "Spring", "XML", "编程"]
categories: ["企业架构"]
slug: "apache-cxf-notes"
draft: false
lastmod: "2010-12-14T14:55:02Z"
id: 841807
url: "https://alimama.iteye.com/blog/841807"
---

**关于Apache CXF**

Apache CXF = Celtix + XFire，Apache CXF 的前身叫 Apache CeltiXfire，现在已经正式更名为 Apache CXF 了，以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华，提供了对 JAX-WS 全面的支持，并且提供了多种 Binding 、DataBinding、Transport 以及各种 Format 的支持，并且可以根据实际项目的需要，采用代码优先（Code First）或者 WSDL 优先（WSDL First）来轻松地实现 Web Services 的发布和使用。

Apache CXF 是一个开源的 Services 框架，CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ，像 JAX-WS 。这些 Services 可以支持多种协议，比如：SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ，并且可以在多种传输协议上运行，比如：HTTP、JMS 或者 JBI，CXF 大大简化了 Services 的创建，同时它继承了 XFire 传统，一样可以天然地和 Spring 进行无缝集成。

**核心处理模块**  
 * [Bus](http://www.iteye.com/wiki/Apache-CXF/1259-%E6%88%91%E7%9C%BC%E4%B8%AD%E7%9A%84CXF%E4%B9%8BBus) -- CXF容器，基于Spring的Container与Configuration。([Configuring the Bus](http://cxf.apache.org/docs/bus-configuration.html) ）  
 * [ServiceModel](http://www.iteye.com/wiki/Apache-CXF/1260-%E6%88%91%E7%9C%BC%E4%B8%AD%E7%9A%84CXF%20%E4%B9%8B%20ServiceModel) -- 服务元数据，其中ServiceInfo类似WSDL，而其他部分描述了DataBinding，Interceptors等CXF属性。  
 * Message -- 在框架内流动的通用信息单元。  
 * [Interceptor](http://www.iteye.com/wiki/Apache-CXF/1257-%E6%88%91%E7%9C%BC%E4%B8%AD%E7%9A%84CXF%E4%B9%8B%20Interceptor%20%28%E4%B8%8A%29) -- 在管道内处理信息的功能单元，由Interceptor Chain控制，分属不同的阶段(Phase)。

**扩展模块**

 * FrontEnd：用户编程API，如[Annotations](http://cxf.apache.org/docs/annotations.html "Annotations") 、[Dynamic Clients](http://cxf.apache.org/docs/dynamic-clients.html "Dynamic Clients") 、[JAX-WS](http://cxf.apache.org/docs/jax-ws.html "JAX-WS") 、[Simple](http://cxf.apache.org/docs/simple.html "Simple")

 * Trainsport：可扩展的传输层，如[Apache Camel Transport](http://cxf.apache.org/docs/apache-camel-transport.html "Apache Camel Transport") 、[HTTP Transport](http://cxf.apache.org/docs/http-transport.html "HTTP Transport") 、[JMS Transport](http://cxf.apache.org/docs/jms-transport.html "JMS Transport") 、[Local Transport](http://cxf.apache.org/docs/local-transport.html "Local Transport")

 * Binding：可扩展的协议解释层，如soap,http,xml,object ( The SOAP binding, which is the default)

 * Data Binding：可扩展的的XML与Java Object映射层，如

- [Aegis (2.1)](http://cxf.apache.org/docs/aegis-21.html "Aegis (2.1)") — For CXF 2.1 or newer
- [Aegis Databinding (2.0.x)](http://cxf.apache.org/docs/aegis-databinding-20x.html "Aegis Databinding (2.0.x)") — For CXF up to 2.0.x
- [JAXB](http://cxf.apache.org/docs/jaxb.html "JAXB")
- [MTOM Attachments with JAXB](http://cxf.apache.org/docs/mtom-attachments-with-jaxb.html "MTOM Attachments with JAXB")
- [SDO](http://cxf.apache.org/docs/sdo.html "SDO")
- [XMLBeans](http://cxf.apache.org/docs/xmlbeans.html "XMLBeans")

[**WSDL绑定样式各种组合优劣势比较**](http://blog.csdn.net/sfdev/archive/2008/06/12/2540703.aspx)

\* 编码样式：encoded与literal，SOAP协议是XML Schema之前的产物，因此自定义了encode协议。WS-I Basic Profile已将其排除在外。在wsdl的wsdl:binding-&gt;wsdl:operation-&gt;wsdl:input/output-&gt;soap:body中定义。  
\* 绑定样式：RPC与Document。面向方法与面向消息的区别。RPC以方法及其参数组织XML，而Document可以任意的形式。  
\* wrapped 与unWrapped(Bare)：在Document样式下，wrapped会将所有的参数包装成body下的一个节点，而Bare则可以有多个Body下的节点。

三种可选的样式  
    * RPC/encoded：古老而传统样式。以方法名节点-&gt;参数节点组织XML。  
    * Document/literal：只以文档形式传递参数。  
    * Document/literal/wrapped：目前最流行的、默认的方式。定义一个以方法名为名称的type，作为body下的唯一节点，包裹所有参数。此时的XML既是一次方法调用，也可以看作是一条消息。结合了前两种的优势。

CXF SOAP消息的默认样式为document/literal/wrapped

 [(The default is document. The default is literal. )](http://cxf.apache.org/docs/soap-12.html)

 

了解相关知识之后，如何开发？请查看这里 [【Apache CXF 简介(IBM DW)】](http://www.ibm.com/developerworks/cn/education/java/j-cxf/index.html)

 

参考：

CXF用户手册: [http://cxf.apache.org/docs/index.html](http://cxf.apache.org/docs/index.html)

CXF-SpringSide wiki: [http://wiki.springside.org.cn/display/calvin/CXF](http://wiki.springside.org.cn/display/calvin/CXF)

Web Service不知道请看 [Web Service百度百科](http://baike.baidu.com/view/837392.html) 或 [Web Service Wiki](http://en.wikipedia.org/wiki/Web_service)