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
*/
posted @   Peter.Jones  阅读(705)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
历史上的今天:
2019-11-19 Power Designer设计Mysql数据库表
2019-11-19 简单用户中心
点击右上角即可分享
微信分享提示