CXF的使用(一)introduce

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.

你可能感兴趣的:(java,spring,bean,xml,webservice)