wsdl2java错误:"无法创建wsdl定义"同时生成java代码

时间:2014-11-25 11:20:44

标签: java web-services wsdl cxf

我尝试使用适用于wsdl的apache-cxf wsdl2java工具生成java服务代码: https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl

  

MBA-Anton:bin asmirnov $ ./wsdl2java   " https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl"   25.11.2014 16:16:49 org.apache.cxf.configuration.jsse.SSLUtils getDefaultKeyStoreManagers警告:默认密钥管理器不能   初始化:/Users/asmirnov/.keystore(没有这样的文件或目录)   [致命错误]寻址:2:2:文档中的标记   根元素必须格式良好。

     

WSDLToJava错误:org.apache.cxf.wsdl11.WSDLRuntimeException:无法   创建wsdl定义   https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl:   WSDLException(在/ wsdl:definitions / wsdl:types / xs:schema / xs:schema):   faultCode = PARSER_ERROR:解析问题   ' http://schemas.xmlsoap.org/ws/2004/08/addressing':   org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。

为什么要尝试创建wsdl定义而不是生成java代码?我该如何解决?

详细日志:

  

MBA-Anton:bin asmirnov $ ./wsdl2java -V   " https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl"   加载FrontEnd jaxws ...加载DataBinding jaxb ... wsdl2java -V   https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl   wsdl2java - Apache CXF 2.7.13

     

25.11.2014 16:18:39 org.apache.cxf.configuration.jsse.SSLUtils getDefaultKeyStoreManagers警告:默认密钥管理器不能   初始化:/Users/asmirnov/.keystore(没有这样的文件或目录)   [致命错误]寻址:2:2:文档中的标记   根元素必须格式良好。

     

WSDLToJava错误:org.apache.cxf.wsdl11.WSDLRuntimeException:无法   创建wsdl定义   https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl:   WSDLException(在/ wsdl:definitions / wsdl:types / xs:schema / xs:schema):   faultCode = PARSER_ERROR:解析问题   ' http://schemas.xmlsoap.org/ws/2004/08/addressing':   org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。

     

org.apache.cxf.tools.common.ToolException:   org.apache.cxf.wsdl11.WSDLRuntimeException:无法创建wsdl   定义   https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl:   WSDLException(在/ wsdl:definitions / wsdl:types / xs:schema / xs:schema):   faultCode = PARSER_ERROR:解析问题   ' http://schemas.xmlsoap.org/ws/2004/08/addressing':   org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。在   org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:420)     在   org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)     在org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)     在org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)at   org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184)   引起:org.apache.cxf.wsdl11.WSDLRuntimeException:无法创建   wsdl定义   https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl:   WSDLException(在/ wsdl:definitions / wsdl:types / xs:schema / xs:schema):   faultCode = PARSER_ERROR:解析问题   ' http://schemas.xmlsoap.org/ws/2004/08/addressing':   org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。在   org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:97)     在   org.apache.cxf.wsdl11.WSDLDefinitionBuilder.build(WSDLDefinitionBuilder.java:69)     在   org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:83)     在   org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:60)     在   org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:198)     在   org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)     在   org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)     ... 4更多引起:javax.wsdl.WSDLException:WSDLException(at   / WSDL:定义/ WSDL:类型/ XS:架构/ XS:模式):   faultCode = PARSER_ERROR:解析问题   ' http://schemas.xmlsoap.org/ws/2004/08/addressing':   org.xml.sax.SAXParseException:以下文档中的标记   根元素必须格式良好。在   com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2198)     在   com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:830)     在   com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:864)     在   com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:654)     在   com.ibm.wsdl.xml.WSDLReaderImpl.parseTypes(WSDLReaderImpl.java:610)     在   com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(WSDLReaderImpl.java:320)     在com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2352)     在com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2338)     在   org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:261)     在   org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:206)     在   org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:78)     ... 10更多引起:org.xml.sax.SAXParseException:中的标记   根元素后面的文档必须格式正确。在   com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:247)     在   com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:287)     在   com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2188)     ......还有20个

3 个答案:

答案 0 :(得分:3)

我的猜测是,这与ws-discovery.xsd中的以下导入有关:

<xs:import namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing" schemaLocation="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>

令我惊讶的是,链接http://schemas.xmlsoap.org/ws/2004/08/addressing有效,但它首先将(HTTP 301)重定向到http://schemas.xmlsoap.org/ws/2004/08/addressing/(请注意尾随/)。

我认为wsdl2java不遵循重定向。您可以监控/嗅探网络连接以找出确切的信息。

无论如何,如何解决它。

您可以将catalog file与wsdl2java一起使用:

制作远程模式的本地副本并使用类似这样的目录文件:

SYSTEM "http://schemas.xmlsoap.org/ws/2004/08/addressing" "src/main/resources/addressing.xsd"

addressing.xsd是您的本地副本)。

答案 1 :(得分:0)

访问wsdl文件时出现SSL问题。您可以先下载wsdl文件,然后使用wsdl2java生成java代码。

答案 2 :(得分:0)

从wsdl中删除样式表条目<?xml-stylesheet type="text/xsl" href="http://www.onvif.org/onvif/ver20/util/onvif-wsdl-viewer.xsl"?>,然后重新尝试重新生成。