spring WebServiceTemplate 调用 axis1.4 发布的webservice
前言:
最近在开发中需要调用对方的 webservice服务,按照现有的技术,本应该是一件很简单的事情,只需要拿到wsdl文件,生成客户端代码即可,但是,对方的webservice服务是06年用axis1.4生成发布的,wsdl文件只能用axis1.4生成客户端代码,而axis的jar包和程序部署环境WebSphere8.5冲突,导致程序无法启动。之前的测试中,spring的WebServiceTemplate可以在was环境下使用,所以,写一下spring如何手动编写客户端代码,调用axis1.4的服务端。
解决方案:
不管用什么工具生成的webservice客户端代码,最终都工具根据生产的代码组装为符合soap协议的xml文件发送给服务端,接收服务端返回的xml文件,解析成我们需要的对象。虽然spring无法根据axis1.4的wsdl文件生成客户端javaBean对象,但是可以先根据wsdl解析到要发送给服务端的 xml文件的格式,由xml文件反向推导出spring组装此xml文件的javaBean对象,所以重点就是如何根据wsdl解析出服务端需要的xml文件,和 spring javaBean和xml文件的对应规则。
根据wsdl拿到要发送给服务端的xml文件,
这里根据wsdl的语法和soap协议规范,可以自己解析,但是比较费时,所以推荐一个工具:soapUI,可以根据wsdl文件生成要发送给服务端的xml文件以及对应服务端返回的xml文件(只是这个工具的一个小功能),本文用的soapUI版本是5.2.1
请求的xml文件实例:
1 <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" > 2 <soapenv:Header/> 3 <soapenv:Body> 4 <sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 5 <message xsi:type="xsd:string">?</message> 6 </sayHello> 7 </soapenv:Body> 8 </soapenv:Envelope>
应答xml文件实例:
1 <soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 2 <soapenv:Header/> 3 <soapenv:Body> 4 <sayHelloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 5 <sayHelloReturn xsi:type="xsd:string">?</sayHelloReturn > 6 </sayHelloResponse> 7 </soapenv:Body> 8 </soapenv:Envelope>
2. 根据xml编写javaBean
对应关系:请求报文中 Body标签内的 标签就是服务端方法的描述,
sayHello --> 服务端的方法名 --> javaBean类 --> @XmlRootElement 中的name的值
sayHello的子标签是方法的参数,后面定义了参数的类型
message --> 方法参数 --> javaBean的字段 --> @XmlElement 中的name的值
请求javaBean实例
1 import javax.xml.bind.annotation.XmlAccessType; 2 import javax.xml.bind.annotation.XmlAccessorType; 3 import javax.xml.bind.annotation.XmlElement; 4 import javax.xml.bind.annotation.XmlRootElement; 5 6 @XmlAccessorType(XmlAccessType.FIELD) 7 @XmlRootElement(name = "sayHello") 8 public class SayHelloRequest { 9 10 @XmlElement(name = "message") 11 private String message; 12 13 public String getMessage() { 14 return message; 15 } 16 17 public void setMessage(String message) { 18 this.message = message; 19 } 20 }
应答javaBean实例
1 import javax.xml.bind.annotation.XmlAccessType; 2 import javax.xml.bind.annotation.XmlAccessorType; 3 import javax.xml.bind.annotation.XmlElement; 4 import javax.xml.bind.annotation.XmlRootElement; 5 6 @XmlAccessorType(XmlAccessType.FIELD) 7 @XmlRootElement(name = "sayHelloResponse") 8 public class SayHelloResponse { 9 10 @XmlElement(name = "sayHelloReturn") 11 private String sayHelloReturn; 12 13 public String getSayHelloReturn() { 14 return sayHelloReturn; 15 } 16 17 public void setSayHelloReturn(String sayHelloReturn) { 18 this.sayHelloReturn = sayHelloReturn; 19 } 20 }
3. spring WebserviceTemplate调用
spring的WebserviceTemplate使用这里不做详解了,需要配置WebserviceTemplate的bean和解析xml文件的 Marshaller bean
1 import javax.annotation.Resource; 2 3 public class WsTest { 4 5 @Resource 6 private WebServiceTemplate webServiceTemplate; 7 8 public SayHelloResponse sayHello (SayHelloRequest request) { 9 10 String url = "http://www.xxxx.com/xxx"; 11 12 return (SayHelloResponse)webServiceTemplate.marshalSendAndReceive (url, request); 13 } 14 15 }
转载于:https://www.cnblogs.com/liu-s/p/5677521.html
spring WebServiceTemplate 调用 axis1.4 发布的webservice相关推荐
- WebService大讲堂之Axis2(7):将Spring的装配JavaBean发布成WebService
在现今的Web 应用中经常使用Spring 框架来装载JavaBean .如果要想将某些在Spring 中装配的JavaBean 发布成WebService ,使用Axis2 的Spring 感知功能 ...
- Spring4.x整合Axis1.4发布WebService服务
Spring4.x整合Axis1.4发布WebService服务 文章目录 一.服务端部署 1. 在web.xml文件中添加映射路径和spring监听 2. 添加spring-axis.xml配置文件 ...
- java使用axis调用.net发布的webservice接口返回对象类型
本人在java中axis-1.4 调用 .net发布的webService接口 有问题欢迎各路大神讨论 !!! 1.1 基本类型 1.2 对象类型 1.3复杂对象类型(对象类中嵌套对象类) 返回基本类 ...
- Axis1.4发布WebService
本章节主要介绍Axis1.4发布WebService.这里只说明发布相关内容,调用方法后续会说明. 1.下载安装 下载地址:http://archive.apache.org/dist/axis/ 本 ...
- CXF发布RestFul WebService和SOAP WebService
CXF发布RestFul WebService和SOAP WebService Apache CXF可以发布多种协议的WebService,Spring支持整合cxf到项目中,可以简化后台构架,以下是 ...
- 基于Spring Boot应用Apache CXF发布Web Services服务
记录:298 场景:使用Spring Boot应用Apache CXF发布Web Services服务,实现跨系统之间交互接口. 版本: JDK 1.8 Spring Boot 2.6.3 Apach ...
- php之webservice限制ip,PHP语言之WSF/PHP调用带有WS-Security支持的WebService时的注意事项...
本文主要向大家介绍了PHP语言之WSF/PHP调用带有WS-Security支持的WebService时的注意事项,通过具体的内容向大家展示,希望对大家学习php语言有所帮助. 目前在PHP中调用带有 ...
- SAP系统中在发布了webservice,获得了WSDN地址后,外部系统怎么传数据到SAP?
SAP系统中在发布了webservice,获得了WSDN地址后,外部系统怎么传数据到SAP? 你是先创建了rfc,然后根据rfc发布的webservice吧? rfc里不是订了传入传出参数,那生成的w ...
- Spring Integration 4.3.10 发布,Spring 消息通信
Spring Integration 4.3.10 发布了.Spring Integration 能在基于 Spring 的应用中进行简单的消息通信,并通过简单的适配器与外部系统集成.这些适配器提供了 ...
最新文章
- Java Setamp;HashSet
- 威纶通触摸屏与mysql_威纶通 与 信捷XC\XD系列PLC 通讯
- 协方差矩阵的实例与意义
- sql三表连接查询 - 使用sqlite 演示
- kdir测试软件,[OK210开发板体验]入门篇(4)编程入门(NFS登录、驱动入门)
- 冒号运算 java_java 8 双冒号运算符
- 4.3 计算机网络之IPv4(IPv4分组、IPv4地址、NAT、子网划分与子网掩码、CIDR、ARP协议、DHCP、ICMP)
- 集群批量管理工具parallel ssh的安装及使用
- Oracle数据库监听配置|转|
- [重要!] SAP Spartacus加载网络请求的entity状态切换,统一在loader.reducer.ts里完成
- Ubuntu下安装使用Monaco字体
- 098-rsshub-radar-2021-03-02
- python网课培训班学费一般多少
- 我们将迎来另一个 VR 寒冬吗?
- 决策树——预测泰坦尼克号幸存者
- (10.2.1)15款优秀移动APP产品原型设计工具
- library Interpositioning 库(内插)干预技术
- 9_用户的登录和登出
- 清理qmail邮件队列
- 2022 年诺贝尔化学奖公布,有学者两度获得诺奖
热门文章
- 基于HTML5的Google水下搜索
- 华南理工网络计算机基础知识,2019年华南理工大学网络教育计算机基础随堂练习第一章...
- 如何在JavaScript中实现链接列表
- mac gource_如何使用Gource显示项目的时间表
- next.js_Next.js手册
- autowired java_Java 基础之Autowired 是否是自动注入
- eplise怎么连接数据库_基于手机信令的大数据分析教程(一)数据导入数据库
- Python工程师求职必知的经典面试题
- java http head 请求_http请求头header、请求体body、请求行介绍
- [雪峰磁针石博客]kotlin书籍汇总