WebService学习笔记-CXF支持的数据类型
来源:互联网 发布:淘宝的君羊令页 编辑:程序博客网 时间:2024/05/22 04:30
此实例测试CXF支持的数据类型
Student.java实体类
public class Student {private int id;private String name;private float price;//...省略getter setter方法public Student() {//无参构造方法super();}}
DataTypeWS.java接口
@WebServicepublic interface DataTypeWS {@WebMethodpublic boolean add(Student student);@WebMethodpublic Student getStudentById(int id);@WebMethodpublic List<Student> getStudentsByPrice(float price);@WebMethodpublic Map<Integer, Student> getAllStudentsMap();}
DataTypeWSImpl.java实现接口
@WebServicepublic class DataTypeWSImpl implements DataTypeWS{@Overridepublic boolean add(Student student) {System.out.println("Server add " + student);return false;}@Overridepublic Student getStudentById(int id) {System.out.println("Server getStudentById " + id);return new Student(id, "umgsai", 15000);}@Overridepublic List<Student> getStudentsByPrice(float price) {System.out.println("Server getStudentsByPrice " + price);List<Student>students = new ArrayList<Student>();students.add(new Student(1, "Tom", price + 1));students.add(new Student(2, "Tom", price + 2));students.add(new Student(3, "Tom", price + 3));return students;}//测试中Map的使用出现异常,暂未解决。可能是由于JDK的版本造成的,测试的时候使用了JDK8@Overridepublic Map<Integer, Student> getAllStudentsMap() {System.out.println("Server getAllStudentsMap ");Map<Integer, Student>map = new HashMap<Integer, Student>();map.put(1, new Student(1, "umgsai", 15000));map.put(2, new Student(2, "umgsai2", 16000));map.put(3, new Student(3, "umgsai3", 17000));return map;}}
发布服务
public class WSServer {public static void main(String[] args) {String address = "http://192.168.13.232:8084/ws_cxf/datatype";Endpoint.publish(address, new DataTypeWSImpl());System.out.println("服务发布成功");}}
可以在浏览器中通过 http://192.168.13.232:8084/ws_cxf/datatype?wsdl来查看发布的服务
使用CXF自带的工具来生成客户端代码
apache-cxf-3.0.1\bin wadl2java http://192.168.13.232:8084/ws_cxf/datatype?wsdl
生成客户端代码后即可编写客户端代码
package com.umgsai.datatype.client;import java.util.List;import java.util.Map;import com.umgsai.datatype.DataTypeWS;//工具来生成客户端代码import com.umgsai.datatype.DataTypeWSImplService;//工具来生成客户端代码import com.umgsai.datatype.Student;//工具来生成客户端代码public class ClientTest {public static void main(String[] args) {DataTypeWSImplService factory = new DataTypeWSImplService();DataTypeWS dataTypeWSImplPort = factory.getDataTypeWSImplPort();Map<Integer, Student> allStudentsMap = (Map<Integer, Student>) dataTypeWSImplPort.getAllStudentsMap();//Map暂时有问题。等换了JDK版本再做测试。System.out.println(allStudentsMap);Object studentById = dataTypeWSImplPort.getStudentById(1);System.out.println(studentById);List<Student> studentsByPrice = dataTypeWSImplPort.getStudentsByPrice(1000);System.out.println(studentsByPrice);}}
本文出自 “优赛工作室” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1563195
0 0
- WebService学习笔记-CXF支持的数据类型
- WebService-05-WebService(CXF)对Map数据类型的支持
- WebService CXF学习笔记
- WebService学习笔记-使用CXF编写基于Spring的Webservice
- 测试CXF支持的数据类型
- WebService学习笔记--CXF基础
- WebService学习笔记-使用CXF发布Webservice
- (九) CXF 支持的数据类型
- Phoenix学习笔记 --- phoenix支持的数据类型
- CXF学习笔记(1)-HelloWorld!-发布webservice
- Apache CXF Webservice学习笔记(一)
- CXF学习笔记(1)-HelloWorld!-发布webservice
- CXF学习笔记(1)-HelloWorld!-发布webservice .
- CXF学习笔记(1)-HelloWorld!-发布webservice
- CXF学习笔记(1)-HelloWorld!-发布webservice
- WebService学习笔记-CXF添加拦截器
- webservice学习笔记 --- day03 CXF+Spring+REST
- Apache-CXF开发Webservice学习笔记
- WebService学习笔记-XML&Schema&HTTP
- WebService学习笔记-Hello world
- WebService学习笔记-读取webxml.com.cn的天气服务信息
- WebService学习笔记-使用CXF发布Webservice
- WebService学习笔记-WSDL文档分析
- WebService学习笔记-CXF支持的数据类型
- WebService学习笔记-CXF添加拦截器
- WebService学习笔记-CXF添加自定义拦截器
- WebService学习笔记-使用CXF编写基于Spring的Webservice
- symbol lookup error: undefined symbol
- WebService学习笔记-添加拦截器到基于Spring的Webservice
- WebService学习笔记-Ajax请求Webservice
- WebService学习笔记-Ajax通过servlet请求跨域Webservice
- JUnit学习笔记-入门介绍