Generating Java code from WSDL
Generating Jave code from WSDL sounds like a task that is so common that there must be a good tool for it. Yes, there are a few tools. Good tools, probably not.
kSOAP2 J2ME Stub Generator seems to be an abandoned project. Though it can be downloaded, but it may not work due to an error.
Wsdl2Code does not seem to be able to handle complex WSDL files.
wsdl2ksoap does not work for some files without giving any hint.
Using wsimport tool is like dealing with a big bureaucracy.
AXIS2 code generator requires Eclipse EE. It does not seem to be able to handle schema files, especially, nested schema files.
WSDL to Java of Apache CXF can generate Java files from complex WSDL files that use nested imported schemas. The command to to generate a client stub is:
wsdl2java -client -d ClientDir foo.wsdl
where ClientDir is the directory for the output, and foo.wsdl is the WSDL from which the Java files are generated.
The generated files use javax.xml.* extensively and some of them are not supported by Android.
It may show a warning - "WSDL document http:...wsdl does not define any services. This is OK.
To generate Java code from ONVIF WSDL files has become more challenge. Traditionally one could do the following:
E:\Users\Hong\Documents\Hong\RandD\AndroidstudioProjects\apache-cxf-3.1.5\bin\wsdl2java -client -d generated "http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl"
Unfortunately, as of 2016, the above command generates the following error:
WSDLToJava Error: org.apache.cxf.wsdl11.WSDLRuntimeException: Fail to create wsdl definition http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl: WSDLException (at /wsdl:definitions/wsdl:types/xs:schema/xs:schema): faultCode=PARSER_ERROR: Problem parsing 'http://www.w3.org/2003/05/soap-envelope'.: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
The remedy is the following:
Download the following files:
http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl
https://www.w3.org/2009/XMLSchema/XMLSchema.xsd
http://www.w3.org/2003/05/soap-envelope
In imaging.wsdl, changing the following line:
<xs:import namespace="http://www.onvif.org/ver10/schema" schemaLocation="https://www.w3.org/2009/XMLSchema/XMLSchema.xsd"/>
to
<xs:import namespace="http://www.onvif.org/ver10/schema" schemaLocation="onvif.xsd"/>
in XMLSchema.xsd, change the following line:
<xs:import namespace="http://www.w3.org/2003/05/soap-envelope" schemaLocation="http://www.w3.org/2003/05/soap-envelope"/>
to
<xs:import namespace="http://www.w3.org/2003/05/soap-envelope" schemaLocation="soap-envelope.xml"/>
wsdl2java is case sensitive, so one may need to change "xs:String" to "xs:string" in any of the WSDL files if wsdl2java is not happy wity them.
The final command executed from the directory where all of the downloaded are located is:
E:\Users\Hong\Documents\Hong\RandD\AndroidstudioProjects\apache-cxf-3.1.5\bin\wsdl2java -client -d generated ImagingBinding.wsdl