CXF的使用(一)introduce

本文介绍了一种利用CXF框架实现Java Web服务的方法。该方法将整个系统分为API、服务器和服务客户端三部分,通过定义Java接口和DTO来处理参数和结果,避免了直接处理XML和WSDL文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CXF的使用(一)introduce

reference BLOG
http://wiki.springside.org.cn/display/SpringSide3/CXF

We just do the webservice serverside and clientside in a java object way, not wsdl and xml way. First we have the whole system devided into 3 parts.

1. api part
api part defined the methods and functions we need, we put all these in java interfaces, we defined the DTO(data transfer object) to hold all the information in parameters and results.

we have the whole api stucture like this:
com.sillycat.webservice.api.constants hold the constants that define the namespace of webservice
com.sillycat.webservice.api.interfaces define the java interfaces
com.sillycat.webservice.api.models define the parameters in java pojo format
com.sillycat.webservice.api.results define the response in java pojo format

the api part will be made to be a jar file to use in both side serverside and clientside. The serverside use this to be a standard and interface to implementation
The clientside use this to be a java api to call the web service.

2. server part
we just implement the api above the implements of our manager.
we have the whole server structure like this:
com.sillycat.core we just put the business logic codes here and implement our bussiness bean AccountManagerImpl here.
com.sillycat.webservice.ws we call AccountManagerImp0l to implement the ws interface here

the server part will be made to be a war file to deploy in web container and we can see the wsdl file here:
http://localhost:8080/easycxfserver/ws/userservice?wsdl

3. client part
we just treat the webservice api as a normal spring bean use spring configuration, we must get the api.jar and the url of webservice.

The only thing we need to do is to put this in our configuration file easycxfclient/conf/ws-client-context.xml:
<jaxws:client id="userService" serviceClass="com.sillycat.webservice.api.interfaces.UserService"
address="http://localhost:8080/easycxfserver/ws/userservice" />

And then ,call userService in easycxfclient/test/com/sillycat/webservice/api/interfaces/UserServiceTest.java like this:
@Test
public void authUser() {
AuthUserResult result = userService.authUser("admin", "admin");
assertEquals(true, result.isValid());
}

In this way, we do not care about xml or wsdl, all that we are dealing with are java objects. But the shortcoming is that every time when we want to change the api.jar, the client side and server side need to changes there jars and change their codes.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值