CXF aout

关于CXF

SVN from:https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes/distribution/src/main/release/samples

cxf.version 2.7.4

1.CXF 主页: http://cxf.apache.org/
2. CXF中文讨论组: http://groups.google.com/group/cxf-zh
3. Web service: http://www.w3school.com.cn/webservices/index.asp
4. WSDL: http://www.w3school.com.cn/wsdl/index.asp
5. SOAP:http://www.w3school.com.cn/soap/index.asp

pom

<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-rt-frontend-jaxws</artifactId>
	<version>2.7.4</version>
</dependency>
<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-rt-transports-http</artifactId>
	<version>2.7.4</version>
</dependency>
<dependency>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-rt-transports-http-jetty</artifactId>
	<version>2.7.4</version>
</dependency>

JAX-WS

 Java SE 6封装了JAX-WS(Java API for XML-Web Services),而JAX-WS同时支持基于SOAP的Web服务和REST风格的Web服务。
JAX-WS允许开发者可以选择RPC-oriented或者message-oriented 来实现自己的web services。
JAX-WS通常可简写为JWS,当前,JWS的版本为2.x。
基于SOAP的Web服务可用单个Java类的实现,但是最好是用“接口+实现”的方式来实现最佳。
    Web服务的接口称为SEI,即Service Endpoint Interface;
    而Web服务的实现称为SIB,即Service Implementation Bean。
    SIB可以是一个POJO,也可以是无状态的会话EJB。本文的SIB是普通Java类,通过JDK 6的类库即可实现Web服务的发布。

在服务器端,用户只需要通过Java语言定义远程调用所需要实现的接口SEI(service endpoint interface),并提供相关的实现,通过调用JAX-WS的服务发布接口就可以将其发布为WebService接口。
在客户端,用户可以通过JAX-WS的API创建一个代理(用本地对象来替代远程的服务)来实现对于远程服务器端的调用。

JAX-WS与JAX-RPC之间的关系
    Sun最开始的web services的实现是JAX-RPC 1.1 (JSR 101)。
        这个实现是基于Java的RPC,并不完全支持schema规范,同时没有对Binding和Parsing定义标准的实现。
    JAX-WS2.0 (JSR 224)是Sun新的web services协议栈,是一个完全基于标准的实现。
        在binding层,使用的是the Java Architecture for XML Binding (JAXB, JSR 222),
        在parsing层,使用的是the Streaming API for XML (StAX, JSR 173),同时它还完全支持schema规范。

服务发布类Publisher   
// 第一个参数是发布的URL   第二个参数是SIB实现
Endpoint.publish("http://127.0.0.1:10100/myweb", new TimeServerImpl()); 
   
WebParam 定制单个参数到 Web Service 消息部分和 XML 元素的映射关系
WebResult 定制返回值到 WSDL 部分和 XML 元素的映射关系。
WebResult 注释(可选)在方法级别声明,用于   自定义 Web 服务操作的返回值。
WebService 将 Java 类标记为实现 Web Service,或者将 Java 接口标记为定义 Web Service 接口。
   
Apache CXF 是一个Service框架,他简化了Service的创建
 CXF实现了JAX-WS2.0规范,并通过了JAX-WS2.0 TCK;
     Generating WSDL from Java classes and generating Java classes from WSDL
     Provider API which allows you to create simple messaging receiving server endpoints
     Dispatch API which allows you to send raw XML messages to server endpoints
 CXF和Spring无缝集成;
     Spring is a first class citizen with Apache CXF.
 CXF支持多种传输协议(HTTP, JMS, Corba等),
     CXF works with many different transports. Currently CXF includes support for HTTP, JMS, and Local (that is, "in-JVM") transports.
     The local transport is unique in that it will not work across machines, but simply sends messages in memory.
     You can also write your own transport.
 支持多种Binding数据格式(SOAP,XML,JSON等),
     CXF provides facilities to transmit binary data efficiently via a standard called MTOM.
     Normally binary data inside an XML message must be Base64 encoded. T
 支持多种DataBinding数据类型(JAXB, Aegis) ;
CXF基于Interceptor的架构,使得整个框架非常易于扩展。
RESTful services
    CXF enables the development of RESTful services via annotations using the HTTP Binding. 
     @Get @HttpResource("/customers/{id}").
Apache Licensed
CXF 2.7.x no longer supports Java 5.

@WebService 注解表示是要发布的web 服务
name:用于Interface,属映射到wsdl:portType element的name属性。
targetNamespace:用于Interface和implement,如果不指定,缺省会使用包名倒序做为wsdl名空间。
serviceName:用于implement,表示wsdl服务名。
portName:用于implement,表示wsdl:port 的name属性。
endpointInterface:用于implement,指定Interface全名,包括包名。

猜你喜欢

转载自zhengchao123.iteye.com/blog/1872460
CXF