我正在寻找一种解决方案,以使用CXF来实现动态SOAP客户端,例如:http://cxf.apache.org/docs/dynamic-clients.html
在我的特定情况下,目标WSDL在其消息部分中存在命名冲突。这会导致使用包装对象的麻烦。到目前为止,我得出的结论是,必须禁用JAX-WS包装器样式才能使用包装器对象,而不是为每个对象属性使用x
实例。
使用maven javax.xml.ws.Holder
生成静态客户端时,使用以下绑定文件可以正常工作:
cxf-codegen-plugin
使用完全相同的文件作为<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings wsdlLocation="incident.wsdl" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" jaxb:version="2.0">
<jaxws:bindings node="wsdl:definitions">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
</jaxws:bindings>
中createClient
方法的参数:
JaxWsDynamicClientFactory
我收到以下异常:
java.lang.RuntimeException: Fatal error compiling schema from WSDL at {https://url?WSDL}: Unexpected appears at line 2 column 247 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.fatalError(DynamicClientFactory.java:778) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:89) at com.sun.proxy.$Proxy35.fatalError(Unknown Source) at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.fatalError(SchemaCompilerImpl.java:307) at com.sun.tools.internal.xjc.util.ErrorReceiverFilter.fatalError(ErrorReceiverFilter.java:72) at com.sun.xml.internal.xsom.impl.parser.ParserContext$2.fatalError(ParserContext.java:196) at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:491) at com.sun.xml.internal.xsom.impl.parser.state.NGCCHandler.unexpectedEnterElement(NGCCHandler.java:180) at com.sun.xml.internal.xsom.impl.parser.state.Schema.enterElement(Schema.java:391) at com.sun.xml.internal.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:244) at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551) at com.sun.tools.internal.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:93) at com.sun.tools.internal.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:135) at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551) at com.sun.tools.internal.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:113) at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551) at com.sun.tools.internal.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:178) at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551) at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:132) at com.sun.xml.internal.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:229) at com.sun.xml.internal.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:112) at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:77) at com.sun.tools.internal.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:85) at com.sun.tools.internal.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:89) at com.sun.tools.internal.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:254) at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:332) at com.sun.xml.internal.xsom.impl.parser.ParserContext.parse(ParserContext.java:113) at com.sun.xml.internal.xsom.parser.XSOMParser.parse(XSOMParser.java:156) at com.sun.xml.internal.xsom.parser.XSOMParser.parse(XSOMParser.java:145) at com.sun.tools.internal.xjc.ModelLoader.createXSOM(ModelLoader.java:519) at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:254) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:89) at com.sun.proxy.$Proxy33.bind(Unknown Source) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:340) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:275) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:210) at com.test.client.DynamicClientTest.main(DynamicClientTest.java:146) Caused by: org.xml.sax.SAXParseExceptionpublicId: file:/home/user/git/test/target/classes/com/test/client/incident_binding.xml; systemId: file:/home/user/git/test/target/classes/com/test/client/incident_binding.xml; lineNumber: 2; columnNumber: 247; Unexpected appears at line 2 column 247 at com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:489) ... 34 more
有人知道如何摆脱异常或如何以编程方式将final JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(bus);
final List<String> bindingFiles = new ArrayList<>();
bindingFiles.add(_BINDING_FILE.getPath());
try (final Client client = dcf.createClient(wsdlUrl, bindingFiles))
{ ... }
设置为enableWrapperStyle
吗?
还是在这种情况下能够解码Web服务响应的任何解决方案?