webservice apache CXF 框架
Apache CXF 则是由 Celtix 和 XFire 项目整合而生,并且刚刚发布了 2.0.2 的最新版本,不过仍是 Apache 的一个孵化项目。一、与Axis2的不同之处
1、Apache CXF 支持 WS-Addressing、WS-Policy、WS-RM、WS-Security和WS-I BasicProfile
2、Axis2 支持 WS-Addressing、WS-RM、WS-Security和WS-I BasicProfile,WS-Policy将在新版本里得到支持
3、Apache CXF 是根据Spring哲学来进行编写的,即可以无缝地与Spring进行整合
4、Axis2 不是
5、Axis2 支持更多的 data bindings,包括 XMLBeans、JiBX、JaxMe 和 JaxBRI,以及它原生的 data binding(ADB)。
6、Apache CXF 目前仅支持 JAXB 和 Aegis,并且默认是 JAXB 2.0,与 XFire 默认是支持 Aegis 不同,XMLBeans、JiBX 和 Castor 将在 CXF 2.1 版本中得到支持,目前版本是 2.0.2
7、Axis2 支持多种语言,它有 C/C++ 版本。
8、Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services
二、A simple JAX-WS service
原文见http://cwiki.apache.org/CXF20DOC/a-simple-jax-ws-service.html
a). 设置构建路径,将下列jar包放到项目中
the CXF distribution
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
jetty-6.1.5.jar
jetty-util-6.1.5.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
Spring jars
aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
CXF jar
cxf-2.0-incubator.jar
b). 编写Service代码
接口HelloService.java
package demo.cxf.server;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloService {
public String sayHello(@WebParam(name="text")String text);
}
实现类HelloServiceImpl
package demo.cxf.server;
import javax.jws.WebService;
@WebService(endpointInterface="demo.cxf.server.HelloService",serviceName="helloService")
public class HelloServiceImpl implements HelloService {
public String sayHello(String text) {
return "Hello ".concat(text);
}
}
c). 发布服务
System.out.println("Starting Server");
HelloServiceImpl impl = new HelloServiceImpl();
String addr = "http://localhost:80/helloService";
Endpoint.publish(addr,impl);
d). 客户端调用
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(HelloService.class);
factory.setAddress("http://localhost:9000/helloService");
HelloService service = (HelloService)factory.create();
String reply = service.sayHello("cxf.");
System.out.println(reply);
System.exit(0);
页:
[1]