CXF 调用方式——动态创建客户端(调用稳定版本号为2.7.18)
今天用动态创建客户端的方式调用webservice,报了这样一个错:
2017-01-05 20:51:46,029 DEBUG main org.apache.cxf.common.logging.LogUtils - Using org.apache.cxf.common.logging.Log4jLogger for logging.
2017-01-05 20:51:46,168 DEBUG main org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Creating client from WSDL http://localhost/sdas/webService/TestWebservice?wsdl
2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http.
2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'
2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'
2017-01-05 20:51:46,274 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http.
2017-01-05 20:51:46,277 DEBUG main org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@6165e7a5
2017-01-05 20:51:46,292 DEBUG main org.apache.cxf.transport.http.Headers - Accept: */*
2017-01-05 20:51:46,294 DEBUG main org.apache.cxf.transport.http.TrustDecisionUtil - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An afirmative Trust Decision is assumed.
2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Response Code: 200 Conduit: {http://cxf.apache.org}TransportURIResolver.http-conduit
2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Content length: -1
2017-01-05 20:51:46,481 DEBUG main org.apache.cxf.transport.http.HTTPConduit - Header fields:
null: [HTTP/1.1 200 OK]
Date: [Thu, 05 Jan 2017 12:51:46 GMT]
Transfer-Encoding: [chunked]
Content-Type: [text/xml]
Server: [Apache-Coyote/1.1] Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy15.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:318)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at platform.AnotherWSTest.main(AnotherWSTest.java:12)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:53)
... 6 more
Caused by: java.lang.NoSuchFieldError: theInstance
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.<init>(BGMBuilder.java:165)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:112)
at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:415)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:246)
... 11 more
服务端是没有问题的,用url调用可以正常执行。
最后通过更改我们的CXF版本解决了这个问题:
之前的版本:2.6.2
修改后的版本:2.7.18,试了用3.X.X表示不行
因为是用的maven所以该版本比较方便,如下:
常量
<properties>
<cxf.version>2.7.18</cxf.version>
</properties>
dependency
<!-- CXF WEBSERVICE -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- CXF WEBSERVICE END -->
服务端和客户端最好统一,如果只改客户端(cxf-rt-frontend-jaxws)为2.7.18也是可以的
最后附一个动态调用示例写法:
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; import com.alibaba.fastjson.JSON; import javax.xml.bind.*; /**
* @ClassName: WebServiceTest
* @Description: TODO
* @author: liuyx
* @date: 2015年9月27日下午5:22:15
*/
public class WebServiceTest {
private static final String testUrl = "http://172.16.10.87/platform3.0/webService/TestWebservice?wsdl";
public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(testUrl); Object[] objects=client.invoke("testOut", "test");
//输出调用结果
System.out.println(JSON.toJSONString(objects));
}
}
CXF 调用方式——动态创建客户端(调用稳定版本号为2.7.18)的更多相关文章
- CXF 动态创建客户端调用稳定版本号为2.7.18
今天用动态创建客户端的方式调用webservice,报了这样一个错: 2017-01-05 20:51:46,029 DEBUG main org.apache.cxf.common.logging. ...
- CXF发布webService服务以及客户端调用
这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...
- WebService—CXF—实现接口发布和客户端调用
(一)接口发布的几种方式 定义接口: @WebService(targetNamespace="http://www.itfad.net/queryUser") public in ...
- Spring集成CXF发布WebService并在客户端调用
Spring集成CXF发布WebService 1.导入jar包 因为官方下载的包里面有其他版本的sprring包,全导入会产生版本冲突,所以去掉spring的部分,然后在项目根目录下新建了一个CXF ...
- WCF 动态调用(动态创建实例接口)
很多时候,服务地址都不止一个的,这个时候就要动态去配置地址.配置Web.config,很麻烦 下面就看看怎样实现动态调用WCF. 首先看看动态创建服务对象的代码: using System; usin ...
- firedac的TFDStoredProc动态创建并调用存储过程
1)中间件执行存储过程 sp.Close; sp.StoredProcName := procName; sp.Prepare; // 生成存储过程的参数列表,无任何OUTPUT的存储过程,也会自动 ...
- cxf 动态创建客户端,局域网能正常调用服务端,外网不能访问
- Live555 中的客户端动态库.so的调用方式之一 程序中调用
1. 打开动态链接库: #include <dlfcn.h> void *dlopen(const char *filename, int flag); 该函数返回操作 ...
- Web Service基础——四种客户端调用方式
通过访问公网服务地址 http://www.webxml.com.cn/zh_cn/index.aspx 来演示四种不同的客户端调用方式 1. 生成客户端调用方式 1.1 Wsimport命令介绍 首 ...
随机推荐
- ActiveMQ 认证(一)
新搭建的ActiveMQ服务,在发布和读取消息时,连接的权限为ActiveMQConnection.DEFAULT_USER和ActiveMQConnection.DEFAULT_PASSWORD. ...
- Python中sorted函数的用法(转)
[Python] sorted函数 我们需要对List.Dict进行排序,Python提供了两个方法 对给定的List L进行排序, 方法1.用List的成员函数sort进行排序,在本地进行排序,不返 ...
- BZOJ 1711:[Usaco2007 Open]Dining吃饭(最大流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1711 [题目大意] 每头牛都有一些喜欢的饮料和食物, 现在有一些食物和饮料,但是每样只 ...
- 企鹅----sap+裂点
企鹅 题目描述 在靠近南极的某处,一些企鹅站在许多漂浮的冰块上.由于企鹅是群居动物,所以它们想要聚集到一起,在同一个冰块上.企鹅们不想把自己的身体弄湿,所以它们在冰块之间跳跃,但是它们的跳跃距离,有一 ...
- hdu 5236 Article 概率dp
Article Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5236 ...
- mqtt 协议之 PINGREQ, PINGRESP
mqtt 协议里最简单的是 ping 协议吧 (心跳包), ping 协议是已连接的客户端发往服务端, 告诉服务端,我还"活着" PINGREQ - PING request fi ...
- nor flash 和nand flash 的区别
ROM和RAM指的都是半导体存储器,ROM是Read Only Memory的缩写,RAM是Random Access Memory的缩写.ROM在系统停止供电的时候仍然可以保持数据,而RAM通常都是 ...
- 通过JSONP实现完美跨域
通过JSONP实现完美跨域 三水清 2010-06-11 20:17:47 以前我经常在博客说JSONP,例如我的WordPress天气插件就是通过JSONP来调用的天气数据,今天就说说通过JSONP ...
- OTL调用存储过程/函数及注意事项
OTL 是 Oracle, Odbc and DB2-CLI Template Library 的缩写,是一个 C++ 编译中操控关系数据库的模板库,它目前几乎支持所有的当前各种主流数据库. OTL ...
- xss bypass
重要的4个规则: 1 &符号不应该出现在HTML的大部分节点中. 2 尖括号<>是不应该出现在标签内的,除非为引号引用. 3 在text节点里面,<左尖括号有很大的危害. 4 ...