首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >CXF 发布 Web Service

CXF 发布 Web Service

作者头像
汤高
发布于 2018-01-11 17:27:07
发布于 2018-01-11 17:27:07
1.3K0
举报
文章被收录于专栏:积累沉淀积累沉淀

使用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 .. 见我的上一篇博客https://cloud.tencent.com/developer/article/1018769    图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);

        }

    }

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-09-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • @WebService
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档