org.apache.cxf.interceptor.Fault: Unmarshalling Error错误解决方案

以前一直用AXIS开发WebService,近期的项目中采用了CXF来开发WebService,结果DELPHI客户端调用时出现了问题,错误提示:

org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"http://xxx.com/", local:"arg0")。所需元素为<{}arg1>,<{}arg0>
 at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:823)
 at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:644)
 at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157)
 at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:108)
 at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
 at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
 at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:211)
 at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
 at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:193)
 at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:129)
 at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:187)
 at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:110)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:166)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.bind.UnmarshalException: 意外的元素 (uri:"http://xxx.com/", local:"arg0")。所需元素为<{}arg1>,<{}arg0>]
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:435)
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:372)
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:349)
 at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:784)
 at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:97)
 at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:812)
 at java.security.AccessController.doPrivileged(Native Method)
 at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:810)
 ... 34 more
Caused by: javax.xml.bind.UnmarshalException: 意外的元素 (uri:"http://xxx.com/", local:"arg0")。所需元素为<{}arg1>,<{}arg0>
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:662)
 at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258)
 at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:253)
 at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:120)
 at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:105)
 at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:262)
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:498)
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:480)
 at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:246)
 at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:180)
 at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:370)
 ... 40 more
Caused by: javax.xml.bind.UnmarshalException: 意外的元素 (uri:"http://xxx.com/", local:"arg0")。所需元素为<{}arg1>,<{}arg0>
 ... 51 more

百度谷歌半天,终于找到原因,摘录如下:

在一些WebServices客户端的实现中(比如Delphi7),可能是由于实现的细节问题(没有实现对wsdl的完全支持),输入输出的参数名称必须是在namespace中限定的。CXF发布的WebServices,默认情况下却是unquailiied的参数名,造成WebServices访问错误。

 

解决办法,是在CXF发布的服务接口中涉及到的类所在的java package文件夹下,加入package-info.java,例子:

d:\projects\example1\src\demo\dao\package-info.java:

@javax.xml.bind.annotation.XmlSchema(//namespace = "http://dao.demo",
attributeFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED,
elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package demo.dao;

 这样,CXF发布出来的wsdl,默认设置就变成了qualified,客户端就能够正常访问WebServices了。

说明:由于ECLIPSE创建CLASS时不允许文件名出现“-”,所以可以用记事本创建该文件,且package-info.java没有类的定义代码,只需要将最后一行的package修改为自己的包名即可。

 

  软件产品网http://www.soft78.com是为广大软件企业提供的一个软件产品、解决方案与成功案例的网络展示、宣传、推广平台,是为软件需求企业或个人提供的一个综合性的软件选型平台。
  软件产品网提供国内最全的软件产品、解决方案信息,如果您的产品还没有加入到我们的产品库中,请立即与我们联系。
  软件产品网为您提供专业、客观的软件评测信息,为您购买软件提供最专业的参考。

你可能感兴趣的:(org.apache.cxf.interceptor.Fault: Unmarshalling Error错误解决方案)