CXF应用程序开发 WS 采用Simple Frontend 方式简单方便
?
关于CXF中的Simple Frontend? 的官方网站如下:
http://cxf.apache.org/docs/simple-frontend.html
?
CXF includes a simple frontend which builds services from reflection. This is in contrast to the JAX-WS frontend which requires you to annotate your web service classes or create a WSDL first. The simple frontend will use reflection to intelligently map your classes to a WSDL model.
By default CXF uses the JAXB databinding. If you are interested in a databinding which does not require annotations, please see the documentation on the Aegis Databinding (2.0.x).
上面的意思如下:
?}
?public String sayHi(User user) {
???????? users.put(users.size() + 1, user);
???????? return "Hello "? + user.getUsername();
?}
?public String[] getAllUseNames(List<User> userList) {
??String[] userListArr=new String[userList.size()];
??for (int i=0;i<userList.size();i++) {
???userListArr[i]=userList.get(i).getUsername();
??}
??return userListArr;
?}
}
package com.easyway.cxf.test.client;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.test.server.ApacheCFXServer;
/**
?*
?*
?* @author longgangbai
?*
?*/
public class ApacheCFXClient {
?public static void main(String[] args) {
??ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
???? factory.setServiceClass(HelloService.class);
???? factory.setAddress(ApacheCFXServer.WS_ADDRESS);
???? HelloService client = (HelloService) factory.create();
???? System.out.println("Invoke sayHi()....");
???? System.out.println(client.hello(System.getProperty("user.name")));
?
?}
}
package com.easyway.cxf.test.server;
import org.apache.cxf.frontend.ServerFactoryBean;
import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.service.HelloServiceImpl;
public class ApacheCFXServer {
?public static final String WS_ADDRESS="http://localhost:8080/cxf/services/helloService";
public static void main(String[] args) {
?HelloServiceImpl helloWorldImpl = new HelloServiceImpl();
?// Create our Server
?ServerFactoryBean svrFactory = new ServerFactoryBean();
?svrFactory.setServiceClass(HelloService.class);
?svrFactory.setAddress(WS_ADDRESS);
?svrFactory.setServiceBean(helloWorldImpl);
?svrFactory.create();
}
}
?