web service cxf demo
来源:互联网 发布:学习c语言编程 编辑:程序博客网 时间:2024/05/19 16:32
服务器端
接口
接口类@WebService 修饰
方法 ws不能处理的类Map
@XmlJavaTypeAdapter(MapAdapter.class)修饰 MapAdapter为处理类
实现
实现类
@WebService(endpointInterface=”com.sun.ws.cxf.HelloWorld”,serviceName=”HelloWorld”)修饰 serviceName为wsdl definitions的name
发布web service服务
public static void main(String[] args) { HelloWorld hw = new HelloWorldWs(); EndpointImpl ep = (EndpointImpl)Endpoint.publish("http://127.0.0.1/hello_ws", hw); ep.getInInterceptors().add(new AuthInterceptor());//权限控制 System.out.println("Web Service 发布成功。"); }
解决ws不能处理的类型
使用@XmlJavaTypeAdapter(MapAdapter.class)修饰 MapAdapter为处理类
其中自定义的MapAdapter需继承XmlAdapter<>并实现unmarshal和marshal方法
查看wsdl
http://127.0.0.1/hello_ws?wsdl
客户端
生成客户端代码
cmd 切到工程目录src下 命令
wsdl2java http://127.0.0.1/hello_ws?wsdl
客户端调用
public static void main(String[] args) { //继承Service的类,该类的实例可当成工厂来使用 调用getXxxPort方法,返回远程Web Service代理 HelloWorld factory = new HelloWorld(); com.sun.ws.cxf.HelloWorld hw = factory.getHelloWorldWsPort(); //权限控制 Client client = ClientProxy.getClient(hw); client.getOutInterceptors().add(new LoggingOutInterceptor()); client.getOutInterceptors().add(new AddHeaderInterceptor("admin","123")); System.out.println(hw.sayHi("Mr Sun")); User user = new User(); user.setName("admin"); user.setPass("root"); List<Cat> list = hw.getCatsByUser(user); for (Cat cat : list) { System.out.println(cat.toString()); } StringCat sc = hw.getAllCats(); for(Entry entry : sc.getEntries()){ System.out.println(entry.getKey()+":"+entry.getValue().getName()); }}
权限控制
自定义的权限控制类需继承AbstractPhaseInterceptor< SoapMessage>并实现handleMessage方法
0 0
- web service cxf demo
- Web Service学习-CXF开发Web Service实例demo(一)
- Web Service学习-CXF开发Web Service实例demo(一)
- CXF 发布 Web Service
- CXF Web Service Tutorial
- CXF调用web service
- Java Web Service-CXF
- Cxf Web Service
- cxf+web service(四)cxf+spring集成
- 实战Web Service with CXF
- CXF 发布Web Service - JaxWsWebServicePublisherBeanPostProcessor
- 使用cxf发布Web Service
- cxf+web service(三)HelloWorld
- 使用CXF创建WEB SERVICE
- CXF Web Service简单应用
- cxf web service简单配置
- web service demo
- Web Service 入门Demo
- lower_bound用法
- 杭电 HDU ACM 2045 不容易系列之(3)—— LELE的RPG难题
- C#连接mysql数据库
- WIN7系统IIS配置与问题处理之二
- python 学习笔记之内置函数
- web service cxf demo
- 算法设计:排序
- Poj 3090 Visible Lattice Points(欧拉函数)
- 网络硬件三剑客:集线器、交换机与路由器
- Duilib技巧:背景图片平铺
- Python 学习笔记之列表(List)
- UVA 101 The Blocks Problem
- IntelliJ IDEA 配置MAVEN后从网上GIT项目仓库路径修改方法
- mac 下统计代码行数