Using wsdl2java
from Apache CXF 4.0.3 I'm running into an error when trying to import XSD into my WSDL file. The files come from a 3rd party and with earlier versions of CXF the imports were working.
I've simplified the files down to the bare minimum to reproduce the problem. Here's the WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="https://webservices.sabre.com/websvc">
<types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://schemas.xmlsoap.org/ws/2002/12/secext" schemaLocation="wsse.xsd"/>
</xsd:schema>
</types>
</definitions>
And this is the content of wsse.xsd
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:xs="http://www.w3.org/2001/XMLSchema">
</xs:schema>
When I run wsdl2java
:
./wsdl2java -encoding UTF-8 -d /project/src/main/java -b "file:/project/src/main/resources/schema/custom-bindings/globalbinding.xjb" -p "=org.a.b.c" -suppress-generated-date -wsdlLocation classpath:schema/wsdl/sample.wsdl -verbose file:/project/src/main/resources/schema/wsdl/sample.wsdl
I get an error:
org.apache.cxf.tools.common.ToolException: file:///apache-cxf-4.0.3/bin/ [1,132]: the target namespace of the imported schema "" doesn't agree with the expected value "http://schemas.xmlsoap.org/ws/2002/12/secext
The targetNamespace
of wsse.xsd
matches the namespace
of the xsd:import
. I don't see why the targetNamespace
in the definitions
element is relevant and I've seen plenty of examples of xsd imports where the xsd:schema
element is missing a targetNamespace
.
I've tried setting targetNamespace
on definitions
and schema
but it doesn't change the error. If I change targetNamespace
in the wsse.xsd
file being imported I get a different error about a namespace mismatch between xsd:import
and the file being imported.
What is the cause of this?
The problem came from the -p "=org.a.b.c"
command line option.
From documentation :
-p [ wsdl-namespace= ] PackageName
Specifies zero, or more, package names to use for the generated code. Optionally specifies the WSDL namespace to package name mapping.
If you want to output generated code in org.a.b.c
package, only set -p "org.a.b.c"
, without =
before packageName.