axis wsdl2java fails reading schema with special characters - java

I'm trying to generate a Java Client with the axis using wsdl2java (wrapped by the maven axistools).
I downloaded the wsdl and the corresponding schema.
The wsdl has the following schema definitions:
<wsdl:types>
<xsd:schema
targetNamespace="http://example.com/CM_IntegrationService/"
xmlns:pref="http://example.com/CM_IntegrationService"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://example.com//CM_IntegrationService"
schemaLocation="CM_IntegrationService?xsd=ServiceModel_CM_IntegrationService.xsd"/>
In short:
schemaLocation="CM_IntegrationService?xsd=ServiceModel_CM_IntegrationService.xsd"
The error shows as:
[ERROR] Failed to execute goal org.codehaus.mojo:axistools-maven-plugin:1.4:wsdl2java
(default) on project wsclient-cm: Error generating Java code from WSDL. error running
file:/C:/workspace/ws/wsclient-reactor/wsclient-wsdl/src/main/wsdl/CM_IntegrationService.wsdl:
WSDLException (at /wsdl:definitions/wsdl:types/xsd:schema): faultCode=OTHER_ERROR:
An error occurred trying to resolve schema referenced
at 'CM_IntegrationService?xsd=ServiceModel_CM_IntegrationService.xsd', relative to
'file:/C:/workspace/ws/wsclient-reactor/shop-wsclient-wsdl/src/main/wsdl/CM_IntegrationService.wsdl'.:
This file was not found:
file:/C:/workspace/ws/wsclient-reactor/wsclient-wsdl/src/main/wsdl/CM_IntegrationService?xsd=ServiceModel_CM_IntegrationService.xsd -> [Help 1]
In short file not found for:
/C:/workspace/ws/wsclient-reactor/wsclient-wsdl/src/main/wsdl/CM_IntegrationService?xsd=ServiceModel_CM_IntegrationService.xsd
Is there a way to specify which schema to use? I saved the schema as ServiceModel_CM_IntegrationService.xsd. However its searching for the full path including = and ? which I cannot emulate on the file system.
I don't want to modify the wsdl as suggested in: WSDL to Java -client creation error
Why is axistools-maven-plugin trying to access this relative schema location? looks similar however using the useEmitter=true option didn't help.

This is currently not possible without modifying the WSDL. Doing this without modifying the WSDL (BTW, why don't you want to do that?) would require support for XML catalogs, as described in AXIS-1984.

Related

jaxb xjc -wsdl command unknown location

I am trying to generate the schema classes from wsdl using the JAXB xjc tool and I am facing the below message:
xjc -verbose -wsdl https://xyz/wsdl.aspx
parsing a schema...
compiling a schema...
[INFO] generating code
unknown location
However, I have tried to with a different wsdl url as below:
xjc -verbose -wsdl http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl
parsing a schema...
compiling a schema...
[INFO] generating code
unknown location
com\cdyne\ws\weatherws\ArrayOfForecast.java
com\cdyne\ws\weatherws\ArrayOfWeatherDescription.java
com\cdyne\ws\weatherws\Forecast.java
etc....
For this 'Weather' wsdl, though I have noticed that there is 'unknown location', the command could successfully generate the schema classes.
I have tried to google and refer the below site, but could not find anything helpful on this subject.
https://jaxb.java.net/2.2.4/docs/xjc.html
I did not understand clearly from xjc log (which says 'unknown location') on what is the exact issue ?
If it is an issue then how could it generate the schema classes for the second 'Weather' wsdl url ?
How do I fix the issue and generate schema files for the first url (https://xyz/wsdl.aspx) ?
I tried to use 'jaxb2-maven-plugin' inside the eclipse, but did not generate any files without any errors. Is it also for the same reason ?
It's most likely complaining about the url <wsdlsoap:address location="..." /> and can't reach the service. This element is within the wsdl:port element which is found within wsdl:service element.

"Use <jaxb:property> to resolve this conflict" error while converting xsd to java objects using jaxb

I am trying to unmarshall elements of xds file to java oblects. I am using Jaxb mavan plugin and Eclipse IDE.
My .xsd file is can be found from
EiPayload
EiEnrollment
EiClasses
Here is my file structure and error,
Need some help to debug this error..!
Disclaimer: I am a lead dev of the ogc-schemas and the w3c-schemas projects.
You have problems with GML 3.2.1 and XLink 1.0. I've implemented bindings for these schemas in the ogc-schemas and the w3c-schemas project. Here you go:
gml-v_3_2_1.xjb
xlink-v_1_0.xjb
But better use the provided JAR artifacts as episodes.

Error using XJC with xml.xsd import: "Failed to read schema document 'xml.xsd'"

I'm trying to run xjc on a Third-party's schema files (it's Amazon.com's product API). Well I'm running into trouble because with one of the files, default.xsd, xjc is borking on the following import (it's the first one right after the schema declaration):
<import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd" />
I'm not an expert on XML, but I thought xml.xsd was part of the "core" XML/XSD library and that XJC would know the details of this library by default. But when I run the task I get this error:
[WARNING] schema_reference.4: Failed to read schema document
'xml.xsd', because 1) could not find the document; 2) the document
could not be read; 3) the root element of the document is not
. line 9 of file:/C:/temp/amazon/default.xsd
[ERROR] src-resolve: Cannot resolve the name 'xml:lang' to a(n)
'attribute declaration' component. line 119 of
file:/C:/temp/amazon/default.xsd
I tried downloading the xml.xsd file from http://www.w3.org/2001/03/xml.xsd to the directory with these schema files and running the command again, but xml.xsd doesn't validate:
[ERROR] schema_reference.4: Failed to read schema document
'file:/C:/temp/amazon/xml.xsd', because 1) could not find the
document; 2) the document could not be read; 3) the root element of
the document is not . unknown location
I was about to start going down the rabbit hole of why this wouldn't be validated, but decided to hold off since I think I'm missing something really simple or small. Do I need to manually include the xml.xsd import or am I missing something else?
The urls for the schema I am working with are currently here:
http://g-ecx.images-amazon.com/images/G/01/mwsportal/doc/en_US/products/default.xsd
and here
http://g-ecx.images-amazon.com/images/G/01/mwsportal/doc/en_US/products/ProductsAPI_Response.xsd
And I'm simply using:
xjc dirname
together at once or
xjc filename
to try to parse them one-by-one
I downloaded your XSD files to mimic the error and indeed, when downloaded as is they give exactly the error you reported.
It wasn't immediately obvious what was happening. Yes, the XML namespace http://www.w3.org/XML/1998/namespace is special and reserved. You do not have to declare it for it to be in existence, but the xml.xsd file is used for Schema compliance, so that these predefined types are also defined in the XSD Schema, so that the types can be used in using schemas.
So my first thoughts were with the XML namespace needing to be declared as xmlns:xml="http://www.w3.org/XML/1998/namespace" (normally this is never needed) for XJC to behave normally, but that didn't change much.
After a bit going back and forth, I decided to run xjc with the option -nv, which turns of certain strict validation rules. This time, the error I received was a bit clearer and immediately pointed to the cause, and the obvious solution:
[ERROR] failed to retrieve 'file:/D:/Projects/xyz/XMLSchema.dtd': java.io.FileNotFoundException: D:\Projects\xyz\XMLSchema.dtd (The system cannot find the file specified)
line 2 of file:/D:/Projects/xyz/xml.xsd
Apparently, XJC tries to download the DTD referenced by the DOCTYPE declaration:
<!DOCTYPE xs:schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "XMLSchema.dtd" >
Actually, this isn't XJC, but the XML parser that precedes XSD validation. The XML parser used is a validating parser, which means it tries to find the DTD and if it cannot, it breaks. The error you received is not very helpful, but correct, as in XML terms, an XML file that points to a DTD is not a valid XML file (but it can be a well-formed XML file and non-validating XML processors, not to be confused with XSD schema validation, will simply load the XML).
Solution
However, the DTD is not required for the XML to be considered correct. You can either download the XMLSchma DTD, or, easier, simply remove that line and the processing will succeed, with or without the -nv switch.
You can use catalogs to fix this type of errors:
Assume one or more of your schemas reference a resource via invalid URL.
Find this resource (is probably available from some alternative location) and save it locally.
Create a catalog file to rewrite the URL. You can rewrite via namespace or via file location:
PUBLIC "http://www.w3.org/XML/1998/namespace" "w3c/2001/03/xml.xsd"
REWRITE_SYSTEM "http://www.w3.org/2001/03/xml.xsd" "w3c/2001/03/xml.xsd"
(Local file location is w3c/2001/03/xml.xsd.)
Use it as xjc -catalog mycatalog.cat ...
You can do the same fo DTDs as well. I normally rewrite just "http://www.w3.org" -> "w3c" and keep the folder structure the same as on the server.
Using -nv is a good idea, works better with catalogs in any case:
https://github.com/highsource/maven-jaxb2-plugin/wiki/Catalogs-in-Strict-Mode
Links:
https://github.com/highsource/maven-jaxb2-plugin/wiki/Using-Catalogs
https://jaxb.java.net/guide/Fixing_broken_references_in_schema.html
http://blog.bdoughan.com/2011/10/jaxb-xjc-imported-schemas-and-xml.html
https://github.com/highsource/w3c-schemas (I'm the author of this one.)

Parsing WSDL generated using Axis1.1 with JAX WS wsimport (Generating Client stub using wsimport with Axis wsdl)

The current web services is exposed using Axis 1.1 and JDK 1.3, I need to generate Client code using wsimport using JDK1.6.
I am using below command to generate the Client stub using JAX-WS and JDK1.6
wsimport -keep CustomerFinder.wsdl
Error:
D:\StockQuote>wsimport -keep CustomerFinder.wsdl
parsing WSDL...
[WARNING] src-resolve: Cannot resolve the name 'soapenc:Array' to a(n) 'type definition' component.
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl#types?schema2
[WARNING] src-resolve.4.2: Error resolving component 'tns1:CenttricException'. It was detected that 'tns1:CenttricException' is in namespace 'http://centtric.com', but components from this namespace are not referenceable from schema document 'file:/D:/StockQuote/CustomerFinder.wsdl#types?schema2'. If this is the incorrect namespace, perhaps the prefix of 'tns1:CenttricException' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/D:/StockQuote/CustomerFinder.wsdl#types?schema2'.
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl#types?schema2
[ERROR] undefined simple or complex type 'soapenc:Array'
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl
[ERROR] undefined attribute 'soapenc:arrayType'
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl
[ERROR] undefined simple or complex type 'soapenc:Array'
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl
[ERROR] undefined attribute 'soapenc:arrayType'
line 2 of file:/D:/StockQuote/CustomerFinder.wsdl
The specification/implemetation of Axis 1.1 and JAX-ws are completely different, The WSDL file generated using Axis 1.x cannot be parsed by JAX-WS.

SugarCRM, WSDL and RPC

There are many url for SugarCRM CE Web Service API like:
http://localhost/soap.php?wsdl
AND
http://localhost/service/v2/soap.php?wsdl
http://localhost/service/v3/soap.php?wsdl
http://localhost/service/v4/soap.php?wsdl
http://localhost/service/v4_1/soap.php?wsdl
They all produce WSDL for RPC/Encoded
When I consume the WSDL using wscompile Java tool with command line
wscompile -gen:client config.xml -keep
and config.xml contains
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="http://localhost/service/v4_1/soap.php?wsdl" packageName="com.crm.imported"/>
</configuration>
I could get the generated classes.
But all the URLs have different structure in the generated classes.
Moreover, only the classes generated by http://localhost/soap.php?wsdl is working and the rest of them give error:
java.rmi.RemoteException: Runtime exception; nested exception is:
unexpected element type: expected={http://www.w3.org/2001/XMLSchema}QName, actual={http://www.w3.org/2001/XMLSchema}int
My Questions:
What is the difference in the API versions?
What is this XMLSchema QName error? How to solve it.
I got the answers:
All the API version have different implementations.
For example: Later versions expect password to be MD5 coded.
XMLSchema Error is raised by providing wrong information to the parameters.
java.rmi.RemoteException will simply give the error message irrelevantly.

Categories