java - 使用 CXF 生成的客户端时意外的包装器元素

标签 java soap wsdl cxf

我已经使用 CXF 的 wsdl2java 为网络服务生成了一个客户端。

客户端连接正常,但抛出一个期望,提示发现的响应与预期的响应不匹配。

May 22, 2013 3:44:46 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://www.service-now.com/cmdb_ci_comm}ServiceNow_cmdb_ci_comm from WSDL: file:/C:/Dev/Workspaces/Eclipse/clim20130508/ServiceNowCXFClient/bin/service-now.wsdl
Invoking getRecords...
May 22, 2013 3:44:51 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {http://www.service-now.com/foo}ServiceNow_foo#{http://www.service-now.com/foo}getRecords has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unexpected wrapper element getRecordsResponse found.   Expected {http://www.service-now.com/foo}getRecordsResponse.
at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:100)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1592)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1490)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1309)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133)
at com.sun.proxy.$Proxy29.getRecords(Unknown Source)
at com.service_now.cmdb_ci_comm.ServiceNowSoap_ServiceNowSoap_Client.main(ServiceNowSoap_ServiceNowSoap_Client.java:178)

显然,收到的响应与预期的响应不同,因为后者包含命名空间。

getRecordsResponse found.   Expected {http://www.service-now.com/foo}getRecordsResponse

我的服务客户端打开如下...

@WebServiceClient(name = "ServiceNow_foo", 
              wsdlLocation = "service-now.wsdl",
              targetNamespace = "http://www.service-now.com/foo") 
public class ServiceNowFoo extends Service {

    public final static URL WSDL_LOCATION;

    public final static QName SERVICE = new QName("http://www.service-now.com/foo", "ServiceNow_foo");
    public final static QName ServiceNowSoap = new QName("http://www.service-now.com/foom", "ServiceNowSoap");

可以在问题How does one configure CXF generated client for preemptive HTTP auth?中看到客户端代码

关于错误配置的任何想法?

最佳答案

可在此处找到解释 https://issues.apache.org/jira/browse/CXF-1460尽管这是一个长期关闭的错误。

当 ServiceNow 公开的 WSDL 具有 elementFormDefault="unqualified" 时,我正在努力解决 CXF 和 ServiceNow 的相同问题。我注意到生成的 package-info.java 没有正确的 @javax.xml.bind.annotation.XmlSchema 注释,因为它缺少 elementFormDefault=XmlNsForm .UNQUALIFIED 我正在使用 CXF 3.2.4 和 Glassfish Java XML Binding 2.3.0

使客户端工作的解决方法是将 ServiceNow 中的 glide.wsdl.schema.UnqualifiedElementFormDefault 参数设置为 false

关于java - 使用 CXF 生成的客户端时意外的包装器元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16700900/

相关文章:

java - 加载时出错 [http ://localhost:8888/testWS]: java. lang.Exception : Failed to load url; http://localhost:8888/testWS, 0

java - 如何用java从客户端系统读取文件?我必须使用 wsdl 吗?

java - String.h 中是否有返回子字符串的内置函数?

java - 如何从嵌套 XML 子元素中删除命名空间值?

java - 不同环境下的 Spring Properties 文件配置和 Maven 集成

maven - apache cxf-codegen-plugin wsdl2java 相对 wsdlLocation

java - 在接口(interface)默认方法中使用 spring 托管 beans?

soap - Onvif wsdl 的 wsimport - 无服务定义

javascript - 如何使用谷歌应用程序脚本调用 SOAP 网络服务