赞
踩
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxws</artifactId>
- <version>3.1.10</version>
- </dependency>
- <dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-transports-http</artifactId>
- <version>3.1.10</version>
- </dependency>
- <dependency>
- <groupId>javax.xml.ws</groupId>
- <artifactId>jaxws-api</artifactId>
- <version>2.3.1</version>
- </dependency>
- import lombok.extern.slf4j.Slf4j;
- import org.apache.cxf.endpoint.Client;
- import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
- import org.apache.cxf.transport.http.HTTPConduit;
- import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-
- import javax.xml.namespace.QName;
-
- /**
- * WebService 工具类
- * @author lenny
- * @date 20210717
- */
- @Slf4j
- public class WebServiceUtil {
- /**
- * 执行WebService方法
- * @param wsdlUrl
- * @param serviceName
- * @param jsonPara
- * @return
- */
- public static String doWebService(String wsdlUrl,QName serviceName,String jsonPara){
- try{
- // 创建动态客户端
- JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
- Client client = dcf.createClient(wsdlUrl);
- HTTPConduit http = (HTTPConduit)client.getConduit();
- //策略
- HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
- //连接超时(1分钟)
- httpClientPolicy.setConnectionTimeout(1 * 60000);
- httpClientPolicy.setAllowChunking(false);
- //响应超时(1分钟)
- httpClientPolicy.setReceiveTimeout(1 * 60000);
- http.setClient(httpClientPolicy);
- //调用方法传参
- Object[] result = client.invoke(serviceName, jsonPara);
- return result[0].toString();
- }catch (Exception e){
- log.error(e.toString());
- return "";
- }
- }
- }
- String jsonParam= JSON.toJSONString(mapPara);
- QName SERVICE_NAME = new QName("http://service.lock.testWebService.com/", "transferLockLocationData");
- String result=WebServiceUtil.doWebService("接口地址",SERVICE_NAME,jsonParam);
java.lang.ClassNotFoundException: javax.xml.ws.WebServiceContext
解决方法:需要引入jar包
- <dependency>
- <groupId>javax.xml.ws</groupId>
- <artifactId>jaxws-api</artifactId>
- <version>2.3.1</version>
- </dependency>
java.lang.IllegalStateException:Unable to create schema compiler
改问题网上也有很多解释说是缺少tools.jar包,我这边是因为创建项目的时候选择的是IDEA自带的JDK环境,所以里面没有tools.jar包
解决方法:修改SDKs对应的JDK环境,更换成自己安装的JDK环境即可
右键左上角的File,选择Project Structure
在弹框里面点击Platform Settings 下面的“SDKs”,将JDK home path更换成自己安装的JDK环境
org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.server.xxxxx.com/}xxxxx.
说明接口的命名空间与默认的命名空间不一致导致的
解决方法:修改命名空间并传入
在浏览器中输入接口地址,可查看接口信息
找到命名空间为:http://service.lock.testWebService.com/并不是默认的http://impl.service.lock.testWebService.com/
也是为了处理这个问题,所以我再进行接口封装的时候传入的是QName而不是直接的方法名称
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。