java axis调用cxf 的坑object is not an instance of declaring class while invoking public
2016-11-09 15:30
686 查看
简单说一下出错的场景,项目需要为别人系统开放webservice,于是在springmvc框架下集成cxf开发webservice接口,网上教程一大堆,小有波折,参考的
https://my.oschina.net/long0419/blog/192788,我用的maven工程,cxf依赖如下:
<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-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>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<properties>下加入版本
<cxf.version>2.2.3</cxf.version> ,
web.xml下配置classpath:webservice/webservice.xml,配置servlet,这个按照https://my.oschina.net/long0419/blog/192788的介绍,完全没问题,
值得注意的是,在webservice.xml中
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<!-- 接口的实现类声明 -->
<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl"
address="/testws" />
</beans>
<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl"
address="/testws" />这里我这样定义的接口实现位置,完成接口,项目发布后,没有错误,打开浏览器,输入http://localhost:8880/fs_door/ws/testws?wsdl,页面显示如下:
到此,我以为webservice服务的开发已经ok了,但自己用写客户端测试,用的axis,jar包网上很容易找到,如需要请留言,测试代码如下:
Service service = new Service();
Call call;
String result="";
try {
call = (Call)service.createCall();
call.setTargetEndpointAddress("http://localhost:8880/fs_door/ws/testws");// 远程调用路径
call.setOperationName(new QName("http://webservice.util.fy.com/", "test"));
call.addParameter("name", // 参数名
XMLType.XSD_STRING,// 参数类型:String
ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
result=(String) call.invoke(new Object[]{"asdf"});
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println(result);
测试别的webservice接口都ok,可是测试上面的接口时,一直报错:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
faultSubcode:
faultString: object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.md.test.Main.main(Main.java:63)
{http://xml.apache.org/axis/}hostname:PYQZF70WEDVIKCN
object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.md.test.Main.main(Main.java:63)
反复的检查客户端调用程序无果,最后怀疑服务端有问题,才回到服务端有关于webservice的所有地方。
问题原因:<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl" address="/testws"
/>
这一句换成
<bean id="hello" class="com.fy.util.webservice.TestWebServiceImpl"
/>
<jaxws:endpoint id="testws" implementor="#hello" address="/testws"
/>
问题解决,至于为什么,尚在学习,希望知道的大神能指点留言,非常感谢!
https://my.oschina.net/long0419/blog/192788,我用的maven工程,cxf依赖如下:
<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-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>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<properties>下加入版本
<cxf.version>2.2.3</cxf.version> ,
web.xml下配置classpath:webservice/webservice.xml,配置servlet,这个按照https://my.oschina.net/long0419/blog/192788的介绍,完全没问题,
值得注意的是,在webservice.xml中
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<!-- 接口的实现类声明 -->
<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl"
address="/testws" />
</beans>
<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl"
address="/testws" />这里我这样定义的接口实现位置,完成接口,项目发布后,没有错误,打开浏览器,输入http://localhost:8880/fs_door/ws/testws?wsdl,页面显示如下:
到此,我以为webservice服务的开发已经ok了,但自己用写客户端测试,用的axis,jar包网上很容易找到,如需要请留言,测试代码如下:
Service service = new Service();
Call call;
String result="";
try {
call = (Call)service.createCall();
call.setTargetEndpointAddress("http://localhost:8880/fs_door/ws/testws");// 远程调用路径
call.setOperationName(new QName("http://webservice.util.fy.com/", "test"));
call.addParameter("name", // 参数名
XMLType.XSD_STRING,// 参数类型:String
ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
result=(String) call.invoke(new Object[]{"asdf"});
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println(result);
测试别的webservice接口都ok,可是测试上面的接口时,一直报错:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
faultSubcode:
faultString: object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.md.test.Main.main(Main.java:63)
{http://xml.apache.org/axis/}hostname:PYQZF70WEDVIKCN
object is not an instance of declaring class while invoking public java.lang.String com.fy.util.webservice.TestWebServiceImpl.test(java.lang.String) with params [asdf].
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.md.test.Main.main(Main.java:63)
反复的检查客户端调用程序无果,最后怀疑服务端有问题,才回到服务端有关于webservice的所有地方。
问题原因:<jaxws:endpoint id="testservice"
implementorClass="com.fy.util.webservice.TestWebServiceImpl" address="/testws"
/>
这一句换成
<bean id="hello" class="com.fy.util.webservice.TestWebServiceImpl"
/>
<jaxws:endpoint id="testws" implementor="#hello" address="/testws"
/>
问题解决,至于为什么,尚在学习,希望知道的大神能指点留言,非常感谢!
相关文章推荐
- 异常笔记(2)--object is not an instance of declaring class while invoking public abstract java.lang.Long
- object is not an instance of declaring class while invoking public abstract…的解决
- java.lang.IllegalArgumentException: object is not an instance of declaring class
- HIbernate 3.2 java.lang.IllegalArgumentException: object is not an instance of declaring class
- java反射错误:object is not an instance of declaring class
- java.lang.IllegalArgumentException: object is not an instance of declaring class
- nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
- object is not an instance of declaring class
- object is not an instance of declaring class
- object is not an instance of declaring class 反射异常
- object is not an instance of declaring class&argument type mismatch
- 报错:object is not an instance of declaring class
- 项目启动后,访问报 object is not an instance of declaring class 错误
- 使用反射报异常:object is not an instance of declaring class解决方案
- object is not an instance of declaring class 反射异常
- hibernate 4 object is not an instance of declaring class
- Xfile 错误记录 object is not an instance of declaring class
- Java反射:object is not an instance of declaring c...
- 反射获取方法时:object is not an instance of declaring class
- spring的 object is not an instance of declaring class