CXF 发布 Web Service

简介:

使用CXF框架开发

①.CXF : xfire–>xfire + celtrix
做web service开发的开源框架

②.开发Server端:
加入cxf的Jar包即可,其它不需要动

测试CXF支持的数据类型
1.基本类型
–int,float,boolean等
2.引用类型
–String
–集合:数组,List, Set, Map
–自定义类型 Student




@WebService
public class DataTypesImpl implements DataTypeWS {  //SEI接口实现类

    public boolean addStudent(Student s) {
        System.out.println("server addStudent()" +s);
        return true;
    }

    public Student getStudentById(int id) {
        System.out.println("server  getStudentById()" +id);
        return new Student(id,"CAT",1000);
    }

    public List<Student> getStudentByPrice(float price) {
        System.out.println("server  getStudentByPrice()" +price);
        List<Student> list=new ArrayList<Student>();
        list.add(new Student(1,"tg1",price+1));
        list.add(new Student(2,"tg2",price+2));
        list.add(new Student(3,"tg3",price+3));
        return list;
        
        
    }

    public Map<Integer, Student> getAllStudentMap() {
        System.out.println("server getAllStudentMap()" );
        Map<Integer,Student> map=new HashMap<Integer, Student>();
        map.put(1,new Student(1,"TG1",123));
        map.put(2,new Student(2,"TG2",143));
        map.put(3,new Student(3,"TG3",153));
        
        return map;
    }


public class serviceTest2 {  //发布服务

    /**
     * @param args
     */
    public static void main(String[] args) {
        //客户端发送web service请求的url
        String address="http://127.0.0.1:8888/tg_ws_cxf/datatypews";
        //处理请求的SEI对象
        DataTypeWS dataTypesImpl=new DataTypesImpl();
        //发布web service
        //Endpoint.publish("http://127.0.0.1/person_ws/HelloWS", hellows);
    Endpoint.publish(address, dataTypesImpl);
    
        
        
        System.out.println("web service 发布成功");

    }

--------------------------------------------------------------------------

(中间必须先生成客户端代码   打开cmd .. 见我的上一篇博客http://blog.csdn.net/tanggao1314/article/details/48393205    图2


public class ClientTest {   //客户端测试

    /**
     * @param args
     */
    public static void main(String[] args) {
        DataTypesImplService factory=new DataTypesImplService();
        DataTypeWS dataTypeWS=factory.getDataTypesImplPort();
        
        boolean s=dataTypeWS.addStudent(new Student());
        System.out.println(s);
        
        List<Student> list=dataTypeWS.getStudentByPrice(12);
        System.out.println(list);
        
        Return r=dataTypeWS.getAllStudentMap();
        
        List<com.tg.web.service.GetAllStudentMapResponse.Return.Entry> entrys=r.getEntry();
        
        for(com.tg.web.service.GetAllStudentMapResponse.Return.Entry entry:entrys){
            Integer id=entry.getKey();
            Student student=entry.getValue();
            System.out.println(id+"-"+student);
        }
        
        

    }

目录
相关文章
|
9月前
phpstorm插件应用:Test RESTful WEB Service 控制台接口调试工具
phpstorm插件应用:Test RESTful WEB Service 控制台接口调试工具
117 0
|
1月前
|
存储 缓存 算法
关于 Service Worker 和 Web 应用对应关系的讨论
关于 Service Worker 和 Web 应用对应关系的讨论
12 0
|
2月前
|
Java API Apache
Apache CXF生成WebService的客户端
Apache CXF生成WebService的客户端
|
6月前
|
JSON 安全 API
使用 ABAP sproxy 事务码生成的 Proxy 消费 Web Service
使用 ABAP sproxy 事务码生成的 Proxy 消费 Web Service
54 0
|
2月前
|
XML 网络架构 数据格式
Ruby 教程 之 Ruby Web Service 应用 - SOAP4R 2
Ruby Web Service 应用 - SOAP4R
24 5
|
2月前
|
XML Linux 网络架构
Ruby 教程 之 Ruby Web Service 应用 - SOAP4R 1
Ruby Web Service 应用 - SOAP4R
23 3
|
8月前
|
XML Java API
Java Web Service Get请求使用指南
Java Web Service Get请求使用指南 在当今互联网时代,Web Service已经成为了现代软件开发中不可或缺的一部分。而Java作为一种广泛使用的编程语言,自然也提供了丰富的工具和库来支持Web Service的开发。本文将为大家介绍如何使用Java编程语言进行Web Service的Get请求。
86 0
|
4月前
|
Java 数据库连接 Apache
SpringBoot整合CXF实现WebService
SpringBoot整合CXF实现WebService
123 0
|
7月前
ABAP Web Service 调用的一个例子
ABAP Web Service 调用的一个例子
28 0
|
11月前
boot+cxf,实现webservice
boot+cxf,实现webservice