博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CXF 发布 Web Service
阅读量:4180 次
发布时间:2019-05-26

本文共 2295 字,大约阅读时间需要 7 分钟。

使用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);
        }
        
        
    }

你可能感兴趣的文章
21. Merge Two Sorted Lists(链表)
查看>>
2. Add Two Numbers(链表)
查看>>
637. Average of Levels in Binary Tree(Tree)
查看>>
226. Invert Binary Tree(Tree)
查看>>
328. Odd Even Linked List(链表)
查看>>
199. Binary Tree Right Side View(Tree)
查看>>
230. Kth Smallest Element in a BST(Tree)
查看>>
求字符串的最长回文串-----Manacher's Algorithm 马拉车算法
查看>>
回溯法常用的解题模板和常见题型
查看>>
深入分析Java I/O 的工作机制
查看>>
动态规划的套路----左神
查看>>
KMP算法简解
查看>>
左神算法课进阶版总结
查看>>
左神算法基础班总结
查看>>
Linux性能优化
查看>>
进程间的通信---UNIX高级环境编程
查看>>
基于SSH开发的城市公交管理系统 JAVA MySQL
查看>>
基于SSH开发的勤工助学管理系统 JAVA MySQL
查看>>
基于SSH开发的宠物销售商城系统 JAVA MySQL
查看>>
基于springboot的宠物领养管理系统 java
查看>>