WebService Client端
pom
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.5.0</version> <exclusions> <exclusion> <artifactId>asm</artifactId> <groupId>org.ow2.asm</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>javax.xml</groupId> <artifactId>jaxb-impl</artifactId> <version>2.1</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-xjc</artifactId> <version>2.3.0</version> </dependency>
java是核心包,javax的x是extension的意思,也就是扩展包。
client
package com.test; import org.apache.cxf.endpoint.Client; import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; public class Test { public static void main(String[] args) throws Exception { JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(); Client client = factory.createClient("http://localhost:8000/order/api?wsdl"); //打印发出的消息 client.getInInterceptors().add(new LoggingInInterceptor()); //打印进入的消息 client.getOutInterceptors().add(new LoggingOutInterceptor()); Object[] res = client.invoke("yxxczyNoticeWorkOrder", "test"); System.out.println("Echo response: " + res[0]); } }
如果时https请求,cxf需要加
//https //System.setProperty("javax.net.ssl.trustStore","D:\\develop\\ssl\\xy.keystore"); System.setProperty("javax.net.ssl.trustStore","/opt/xy.keystore"); System.setProperty("javax.net.ssl.trustStorePassword","123456"); System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
cxf不支持jdk11, 目前只支持jdk1.8, 官网有说明
使用hutool更方便
/**
* webservice
*
* apache-cxf框架的两种调用方式:
* 1.静态调用 org.apache.cxf.jaxws.JaxWsProxyFactoryBean 需要依赖服务端接口
* 2.动态调用 org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory 无需服务端接口
*
* webservice spring boot框架的调用方式 :WebServiceTemplate
* https://docs.spring.io/spring-boot/docs/current/reference/html/io.html#io.webservices
*
* hutool调用方式
* https://hutool.cn/docs/#/http/WebService/Soap%E5%AE%A2%E6%88%B7%E7%AB%AF-SoapClient
*/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
2019-11-19 Power Designer设计Mysql数据库表
2019-11-19 简单用户中心