cxf动态调用wsdl的一个冲突以及解决
cxf发布服务,调用服务的博客很多,这里也就简单贴一下代代码。
环境如下:spring+cxf (maven环境)
<cxf.version>2.7.11</cxf.version>
<!-- SOAP begin -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>${cxf.version}</version>
<exclusions>
<!-- use javax.mail.mail instead -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
</exclusion>
<!-- use javax.activation.activation instead -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-activation_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<exclusions>
<!-- see above -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-javamail_1.4_spec</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-activation_1.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- SOAP end -->
服务端(jetty环境):
@WebService
public interface ICommand { /**
* 通用调用
* @param fromApp
* @return
*/
public String isConnection(@WebParam(name="fromApp") String fromApp); public String sendCommand(@WebParam(name="fromApp")String fromApp, @WebParam(name="command")String command); }
@WebService
public class CommandImpl implements ICommand { private final static Logger logger = LoggerFactory.getLogger(CommandImpl.class); @Override
public String isConnection(String fromApp) {
logger.info("from:" + fromApp);
return "ok";
} @Override
public String sendCommand(String fromApp, String command) {
logger.info("from:" + fromApp + ",name:" + command);
// 调用自己生
return "response:[" + command + "]";
}
}
spring配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!--CXF配置-->
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <!--服务端发布的webservice 和下面的配置一样
<jaxws:endpoint id="command" implementor="cn.edu.bupt.service.soa.CommandImpl" address="/Command"/>
-->
<bean id="command" class="cn.edu.bupt.service.soa.CommandImpl"/>
<jaxws:endpoint id="commandWebService" address="/Command" implementorClass="cn.edu.bupt.service.soa.CommandImpl">
<jaxws:implementor ref="command"/>
</jaxws:endpoint>
</beans>
客户端配置:
<jaxws:client id="commandClient" address="http://localhost:8088/virtual-network/webservice/Command" serviceClass="cn.edu.bupt.service.soa.ICommand"/>
采用bean调用:
public static void main(String[] args){ ApplicationContext context = new ClassPathXmlApplicationContext("spring-cxf.xml");
ICommand helloWorld=(ICommand)context.getBean("commandClient");
System.out.println(helloWorld.sendCommand("helloworld","Test"));
}
这边准备用cxf动态调用:
public static void main(String[] args){
JaxWsDynamicClientFactory factory =JaxWsDynamicClientFactory.newInstance();
String url = "http://localhost:8088/virtual-network/webservice/Command?wsdl";
org.apache.cxf.endpoint.Client client =factory.createClient(url);
//url为调用webService的wsdl地址
//QName也可以
//QName name=new QName("http://soa.service.bupt.edu.cn/","isConnection");
try {
// Object[] obj =client.invoke(name, "helloworld");
Object[] obj =client.invoke("isConnection", "helloworld");
System.out.println("resp:"+obj[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
由于我客户端和服务端是一起运行,报出异常:
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.sun.tools.internal.xjc.reader.Ring.get(Ring.java:87)
... 23 more
Caused by: java.lang.NoSuchFieldError: REFLECTION
at com.sun.tools.internal.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:59)
at com.sun.tools.internal.xjc.model.nav.NavigatorImpl.getBaseClass(NavigatorImpl.java:44)
at com.sun.xml.internal.bind.v2.model.core.Adapter.<init>(Adapter.java:73)
这个是为什么,因为项目引入的tools.jar与jaxb-impl.jar冲突了。
用mvn dependency:tree > tree.txt 导入包引用路径,发现是druid引入的tools导致的
[INFO] +- com.alibaba:druid:jar:1.0.9:compile
[INFO] | +- com.alibaba:jconsole:jar:1.8.0:system
[INFO] | \- com.alibaba:tools:jar:1.8.0:system
排除一下
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
就解决了该冲突。
参考:
http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html
http://jishiweili.iteye.com/blog/2086100
http://www.blogjava.net/sxyx2008/archive/2010/09/15/332058.html
http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html
cxf动态调用wsdl的一个冲突以及解决的更多相关文章
- CXF动态调用wsdl接口
1.application.properties文件中配置接口url 2.工具类 package com.vulnverify.core.utils; import java.io.IOExcepti ...
- cxf动态调用webservice设置超时,测试线程安全
Java代码 import java.util.Random; import java.util.concurrent.ArrayBlockingQueue; import java.util.con ...
- 转载 CXF动态调用webservice
/** * * @param wsdlUrl wsdl的地址:http://localhost:8001/demo/HelloServiceDemoUrl?wsdl * @param methodNa ...
- cxf动态调用外部web service 报告异常java.lang.NoSuchFieldErr
原因:cxf 依赖的xmlschema-core 与axis2-kernel依赖的xmlschema冲突. 解决方法:因为在项目中只用cxf即可,所以删除axis2的依赖.
- cxf动态调用外部web service 报告异常java.lang.NoSuchFieldError: QUALIFIED
原因:cxf 依赖的xmlschema-core 与xfire-all依赖的xmlschema冲突.(百度搜索亦得知:cxf 依赖的xmlschema-core 与axis2-kernel依赖的xml ...
- cxf 动态调用.
import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache ...
- H5 input输入限制最大位数,和调用小键盘需求发生冲突的解决办法
首先,限制输入最大位数时,input有自带的属性maxlength. <input type="text" name="email" maxlength= ...
- .net WebServer示例及调用(接口WSDL动态调用 JAVA)
新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- C#动态调用带有SoapHeader验证的WebServices
http://blog.csdn.net/u012995964/article/details/54573143 本文记录C#中通过反射动态的调用带有SoapHeader验证的WebServices服 ...
随机推荐
- 【BZOJ】1014: [JSOI2008]火星人prefix(splay+hash+二分+lcp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1014 题意:支持插入一个字符.修改一个字符,查询lcp.(总长度<=100000, 操作< ...
- Nginx location 匹配规则
1. default_server: 当请求没有匹配到服务器中配置的任何一个server的时候,会默认把请求route到配置了default_server的virtual host中.参考地址:htt ...
- Xshell选中的同时把内容复制到剪贴板(还可以设置设置文本分隔符)
1.设置对话框 工具 -> 选项 -> 键盘和鼠标 -> 将选定的文本自动复制到剪贴板 2.贴图如下 2.1.打开设置对话框 2.2.设置键盘鼠标,左键复制 2.3.右键粘贴 作者: ...
- e.KeyChar用到的键盘对应ASCII码值(转)
十进制编码 (对应)缩写字符(或功能/解释) 0 NUL(null) 空字符 1 SOH(start of headline) 标题开始 2 STX (start of text) 正文开 ...
- php页面之间传值
echo("<script>window.open('2.php?head=".$head."');<script>");
- cmd命令行查看windows版本
1.ver命令不显示sp几 C:\>ver Microsoft Windows XP [Version 5.1.2600] C:\> 08: C:\Users\Administrator& ...
- HDU 2094 产生冠军(半拓扑排序+map)
产生冠军 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- IntelliJ IDEA(社区版)学习记录
一.下载 地址:官网下载地址 二.安装 运行安装程序,一路下一步.注意选择安装路径. 三.基本概念 project:相当于donet下的解决方案 module:相当于donet下的项目工程 四.IDE ...
- 文件上传(springMVC+ckeditor)
1.首先添加springMVC文件上传的jar commons-fileupload-1.2.2.jar和commons-io-2.0.1.jar (maven项目可以使用 <dependenc ...
- 分布式缓存(Cache)
1. 单层分布式cache. 如memcache. 2. 多层分布式cache. 服务端和调用者本地都存放cache, 使用udp组播解决cache同步更新问题,但不可靠. 3. 改进的多层分布式ca ...