Search code examples
javaweb-serviceswsdlcxf

wsdl2java error: "Fail to create wsdl definition" while generating java code


I'm trying to generate java service code with apache-cxf wsdl2java tool for wsdl: 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 WARNING: Default key managers cannot be initialized: /Users/asmirnov/.keystore (No such file or directory) [Fatal Error] addressing:2:2: The markup in the document following the root element must be well-formed.

WSDLToJava Error: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://schemas.xmlsoap.org/ws/2004/08/addressing'.: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.

Why is it trying to create wsdl definition instead of generating java code? How can i fix it?

Verbose log:

MBA-Anton:bin asmirnov$ ./wsdl2java -V "https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl" Loading FrontEnd jaxws ... Loading 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 WARNING: Default key managers cannot be initialized: /Users/asmirnov/.keystore (No such file or directory) [Fatal Error] addressing:2:2: The markup in the document following the root element must be well-formed.

WSDLToJava Error: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://schemas.xmlsoap.org/ws/2004/08/addressing'.: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.

org.apache.cxf.tools.common.ToolException: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://schemas.xmlsoap.org/ws/2004/08/addressing'.: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:420) at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103) at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113) at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86) at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184) Caused by: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition https://raw.githubusercontent.com/mpromonet/spring-onvif/master/src/main/resources/wsdl/remotediscovery.wsdl: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://schemas.xmlsoap.org/ws/2004/08/addressing'.: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:97) at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.build(WSDLDefinitionBuilder.java:69) at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:83) at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:60) at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:198) at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164) at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412) ... 4 more Caused by: javax.wsdl.WSDLException: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://schemas.xmlsoap.org/ws/2004/08/addressing'.: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2198) at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:830) at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:864) at com.ibm.wsdl.xml.WSDLReaderImpl.parseSchema(WSDLReaderImpl.java:654) at com.ibm.wsdl.xml.WSDLReaderImpl.parseTypes(WSDLReaderImpl.java:610) at com.ibm.wsdl.xml.WSDLReaderImpl.parseDefinitions(WSDLReaderImpl.java:320) at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2352) at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(WSDLReaderImpl.java:2338) at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:261) at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:206) at org.apache.cxf.wsdl11.WSDLDefinitionBuilder.parseWSDL(WSDLDefinitionBuilder.java:78) ... 10 more Caused by: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:247) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:287) at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(WSDLReaderImpl.java:2188) ... 20 more


Solution

  • My guess is that this has to do with the following import in ws-discovery.xsd:

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

    To my surprise, the link http://schemas.xmlsoap.org/ws/2004/08/addressing works but it redirects (HTTP 301) to http://schemas.xmlsoap.org/ws/2004/08/addressing/ first (mind the trailing /).

    I think wsdl2java does not follow the redirect. You could monitor/sniff network connections to find out exactly.

    Anyway, how to solve it.

    You can use a catalog file with wsdl2java:

    Make a local copy of the remote schema and use a catalog file like this one:

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

    (addressing.xsd is your local copy).