gpt4 book ai didi

使用 Cxf Web 服务的 Java 示例 ~ 运行时异常

转载 作者:行者123 更新时间:2023-12-02 05:41:34 24 4
gpt4 key购买 nike

我正在尝试使用 apache-cxf 创建客户端。
我需要运行以下网络服务 http://soapclient.com/xml/soapresponder.wsdl
我想要实现的是我将向该服务提供两个参数并返回结果/响应。

下面是我的代码:

JaxWsDynamicClientFactory dfc = JaxWsDynamicClientFactory.newInstance();
Client client = dfc.createClient("http://soapclient.com/xml/soapresponder.wsdl");

Object res[] = client.invoke("echo", "test echo");
System.out.println("Result: " + res[0]);

我收到很多错误,例如:

Exception in thread "main" java.lang.RuntimeException: Fatal error compiling schema from WSDL at {http://soapclient.com/xml/soapresponder.wsdl}: Unexpected <schema> appears at line 9 column 5
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory$InnerErrorListener.fatalError(DynamicClientFactory.java:759)
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:483)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:90)
at com.sun.proxy.$Proxy22.fatalError(Unknown Source)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.fatalError(SchemaCompilerImpl.java:322)
at com.sun.tools.xjc.util.ErrorReceiverFilter.fatalError(ErrorReceiverFilter.java:87)
at com.sun.xml.xsom.impl.parser.ParserContext$2.fatalError(ParserContext.java:211)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:506)
at com.sun.xml.xsom.impl.parser.state.NGCCHandler.unexpectedEnterElement(NGCCHandler.java:194)
at com.sun.xml.xsom.impl.parser.state.Schema.enterElement(Schema.java:443)
at com.sun.xml.xsom.impl.parser.state.NGCCRuntime.startElement(NGCCRuntime.java:258)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.util.SubtreeCutter.startElement(SubtreeCutter.java:108)
at com.sun.tools.xjc.reader.ExtensionBindingChecker.startElement(ExtensionBindingChecker.java:150)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.IncorrectNamespaceURIChecker.startElement(IncorrectNamespaceURIChecker.java:128)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.xmlschema.parser.CustomizationContextChecker.startElement(CustomizationContextChecker.java:193)
at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:147)
at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)
at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:92)
at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:100)
at com.sun.tools.xjc.reader.internalizer.DOMForestParser.parse(DOMForestParser.java:104)
at com.sun.tools.xjc.ModelLoader$XMLSchemaParser.parse(ModelLoader.java:269)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.parseEntity(NGCCRuntimeEx.java:347)
at com.sun.xml.xsom.impl.parser.ParserContext.parse(ParserContext.java:128)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:168)
at com.sun.xml.xsom.parser.XSOMParser.parse(XSOMParser.java:157)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:534)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
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:483)
at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:90)
at com.sun.proxy.$Proxy20.bind(Unknown Source)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:321)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:241)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:234)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
at TestCAse.main(TestCAse.java:8)
Caused by: org.xml.sax.SAXParseExceptionpublicId: http://soapclient.com/xml/soapresponder.wsdl; systemId: http://soapclient.com/xml/soapresponder.wsdl; lineNumber: 9; columnNumber: 5; Unexpected <schema> appears at line 9 column 5
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.unexpectedX(NGCCRuntimeEx.java:499)
... 35 more

最佳答案

它失败是因为在该地址发布的 WSDL 无效。 CXF提示的具体故障点是这样的:

<types>
<schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="http://www.SoapClient.com/xml/SoapResponder.xsd"></schema>
</types>

请注意 <schema> 的不合格使用标签?该标签在 http://www.w3.org/2001/XMLSchema 中提供。命名空间,以前缀 xsd 限定。 WSDL 中应包含的内容是:

<types>
<xsd:schema xmlns="http://www.w3.org/1999/XMLSchema" targetNamespace="http://www.SoapClient.com/xml/SoapResponder.xsd"></xsd:schema>
</types>

我无法理解为什么结果是错误的;毕竟,命名空间和前缀在 wsdl 的顶部正确声明:

 xmlns:xsd="http://www.w3.org/2001/XMLSchema".
<小时/>

要解决此问题,请保存该 wsdl 的本地副本,进行编辑以更正不合格的标记使用,然后在应用程序中使用更正后的本地副本

关于使用 Cxf Web 服务的 Java 示例 ~ 运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24469256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com