使用cxf发布webservice总结
来源:互联网 发布:ubuntu安装deb包打开 编辑:程序博客网 时间:2024/06/05 04:36
一、概念
1、什么是webservice
Web service是一个平台独立的,低耦合的,自包含的、基于可编程的web的应用程序,可使用开放的XML标准来描述、发布、发现、协调和配置这些应用程序,用于开发分布式的互操作的应用程序。
2、wsdl
网络服务描述语言是一个用来描述Web服务和说明如何与Web服务通信的XML(标准通用标记语言的子集)语言。为用户提供详细的接口说明书。
3、soap
简单对象访问协议是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。
4、JAX-WS
一种 Java 规范,名为 JAX-WS(JSR-224),全称 Java API for XML-Based Web Services,可以将规范理解为官方定义的一系列接口。
5、JAX-RS
为了让 WS 的开发与使用变得更加简单、更加轻量级,于是出现了另一种风格的 WS,名为 JAX-RS(JSR-339),全称 Java API for RESTful Web Services,同样也是一种规范,同样也有若干实现,cxf是其中比较著名的一种。
二、使用cxf发布基于soap的webservice
1、cxf与webservice的关系
刚入行的时候一直把cxf当做webservice,其实cxf只是发布调用webservice的工具而已。
2、最低maven配置
由于webservice有基于soap的实现和rest的实现,这使得cxf的maven配置比较混乱。
1
2
3
4
5
6
7
8
9
10
11
12
<!-- cxf config begin -->
<
dependency
>
<
groupId
>org.apache.cxf</
groupId
>
<
artifactId
>cxf-rt-frontend-jaxws</
artifactId
>
<
version
>2.7.3</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.apache.cxf</
groupId
>
<
artifactId
>cxf-rt-transports-http-jetty</
artifactId
>
<
version
>2.7.3</
version
>
</
dependency
>
<!-- cxf config end -->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!-- JSON begin -->
<
dependency
>
<
groupId
>com.fasterxml.jackson.core</
groupId
>
<
artifactId
>jackson-core</
artifactId
>
<
version
>${jackson.version}</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.fasterxml.jackson.core</
groupId
>
<
artifactId
>jackson-databind</
artifactId
>
<
version
>${jackson.version}</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.fasterxml.jackson.core</
groupId
>
<
artifactId
>jackson-annotations</
artifactId
>
<
version
>${jackson.version}</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.fasterxml.jackson.module</
groupId
>
<
artifactId
>jackson-module-jaxb-annotations</
artifactId
>
<
version
>${jackson.version}</
version
>
</
dependency
>
<
dependency
>
<
groupId
>com.fasterxml.jackson.jaxrs</
groupId
>
<
artifactId
>jackson-jaxrs-json-provider</
artifactId
>
<
version
>${jackson.version}</
version
>
<!-- Jackson2.2.0 版本对于 CXF2.7.3 不支持 -->
<!-- http://www.marshut.com/krrqx/fasterxml-jackson-2-2-provider-no-longer-works-with-cxf-jax-rs.pdf -->
<!-- http://cxf.547215.n5.nabble.com/Creating-input-values-on-WADL-td5728910.html -->
</
dependency
>
<!-- Spring WebMVC 3.1.2 用到 -->
<
dependency
>
<
groupId
>org.codehaus.jackson</
groupId
>
<
artifactId
>jackson-mapper-asl</
artifactId
>
<
version
>1.9.0</
version
>
</
dependency
>
<
dependency
>
<
groupId
>org.codehaus.jackson</
groupId
>
<
artifactId
>jackson-core-asl</
artifactId
>
<
version
>1.9.0</
version
>
</
dependency
>
<!-- JSON end -->
后面两个依赖视你的spring版本情况而定。
3、webservice接口
1
2
3
4
5
6
7
8
9
10
11
package
com.winssage.winssagebpm.application;
import
javax.jws.WebService;
import
com.winssage.winssagebpm.baseapplication.IBaseApplication;
import
com.winsssage.winssagebpm.domain.User;
@WebService
public
interface
UserApplication
extends
IBaseApplication<User> {
public
String sayHello( String name);
}
4、接口实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package
com.winssage.winssagebpm.applicationImpl;
import
javax.inject.Named;
import
javax.jws.WebService;
import
org.springframework.transaction.annotation.Transactional;
import
com.winssage.winssagebpm.application.UserApplication;
import
com.winssage.winssagebpm.baseapplicationImpl.BaseApplicationImpl;
import
com.winsssage.winssagebpm.domain.User;
@WebService
(endpointInterface =
"com.winssage.winssagebpm.application.UserApplication"
)
@Named
(
"userApplication"
)
@Transactional
public
class
UserApplicationImpl
extends
BaseApplicationImpl<User>
implements
UserApplication {
public
String sayHello(String name) {
name =
"hello"
+ name;
return
name;
}
}
5、spring整合cxf
#userApplication为实现中注解进来的bean.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version=
"1.0"
encoding=
"UTF-8"
?>
<beans xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:jee=
"http://www.springframework.org/schema/jee"
xmlns:jaxws=
"http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http:
//www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http:
//www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http:
//www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http:
//www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http:
//cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<
import
resource=
"classpath*:META-INF/cxf/cxf.xml"
/>
<
import
resource=
"classpath*:META-INF/cxf/cxf-servlet.xml"
/>
<jaxws:endpoint id=
"security"
implementor=
"#userApplication"
address=
"/user"
/>
</beans>
6、客户端调用已发布的webservice
1
2
3
4
5
6
7
8
9
<
bean
id
=
"userServiceClient"
class
=
"com.winssage.winssagebpm.application.UserApplication"
factory-bean
=
"userServiceClientFactory"
factory-method
=
"create"
/>
<
bean
id
=
"userServiceClientFactory"
class
=
"org.apache.cxf.jaxws.JaxWsProxyFactoryBean"
>
<
property
name
=
"serviceClass"
value
=
"com.winssage.winssagebpm.application.UserApplication"
/>
<
property
name
=
"address"
>
<
value
>http://localhost:9080/winssagebpm-web/api/user</
value
>
</
property
>
</
bean
>
7、查看已发布的webservice
三、使用cxf发布基于REST的webservice
详见http://my.oschina.net/fengshuzi/blog/280408
四、总结
0 0
- 使用cxf发布webservice总结
- CXF发布WebService总结
- 使用CXF发布webService
- 使用CXF发布WebService
- 使用CXF框架发布webservice
- WebService学习笔记-使用CXF发布Webservice
- webService总结(一)——使用CXF发布和调用webService(不使用Spring)
- webService总结(二)——使用CXF手动发布webService(不使用Spring)
- CXF整合Spring发布WebService学习总结
- webService总结(三)——使用CXF + Spring发布webService
- 使用cxf发布webservice(JavaApplication)
- 使用cxf发布WebService(Spring)
- CXF发布WebService使用SoapUI测试
- cxf发布webservice,使用maven工程
- 使用CXF发布WebService服务简单实例
- cxf发布webservice 简单使用步骤备忘
- 使用Spring + CXF 发布WebService服务
- 使用Apache的CXF框架发布Webservice四种方法总结
- 状态压缩dp入门[HDU1074][HDU1065][POJ3254][POJ1185][HDU4359][POJ3311][POJ2411]
- hdu 5384 Danganronpa
- BLE 天线容易忽略的小知识
- python 之 解决输出中文字符乱码
- PHP的内存泄露问题与垃圾回收
- 使用cxf发布webservice总结
- 如何实现多线程下载文件
- Markdown
- c#异步调用和回调
- 系统调用简析————open一个设备
- Android国际化
- excel 补全所有空格
- 《转》QT界面怎么使控件随窗口大小变化一直居中显示
- 关于蓝牙