How do I link to XSD files using the Apache CXF Maven plugin?

Duncan Jones picture Duncan Jones · Apr 30, 2014 · Viewed 7.6k times · Source

I'm using the Apache cxf-codegen-plugin Maven plugin to try and generate Java classes from a WSDL file. I get the following error:

Part <parameters> in Message <{http://www.foo.com/bar}PushCommandSoapIn> referenced Type <{http://www.foo.com/bar}CommandMessage> can not be found in the schemas

The type in question (CommandMessage) is defined in an XSD file that I've attempted to reference using the following POM file:

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <version>2.7.11</version>
  <executions>
    <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration>
        <wsdlOptions>
          <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/SomeService.wsdl</wsdl>
            <dependencies>
              <!-- Here I try to reference the XSD -->
              <dependency>${basedir}/src/main/resources/wsdl/SomeTypes.xsd</dependency>
            </dependencies>
          </wsdlOption>
        </wsdlOptions>
      </configuration>
      <goals>
        <goal>wsdl2java</goal>
      </goals>
    </execution>
  </executions>
</plugin>  

Any suggestions of why I'm getting an error? I'm not sure adding a <dependency> is the correct way, but I struggled to find documentation that describes how to reference XSD files.

Here is the snippet from the WSDL file that refers to the missing type:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:bar="http://www.foo.com/bar" 
      targetNamespace="http://www.foo.com/bar">
  <wsdl:message name="PushCommandSoapIn">
    <wsdl:part name="parameters" element="bar:CommandMessage" />
  </wsdl:message>

Here is the header and a snippet from the XSD file:

<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.foo.com/bar" 
      xmlns:bar="http://www.foo.com/bar" 
      xmlns="http://www.w3.org/2001/XMLSchema" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
      elementFormDefault="qualified" attributeFormDefault="unqualified">
  <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" />
  ...
  <element name="CommandMessage" type="bar:CommandMessageType" substitutionGroup="bar:Message" final="#all" />

Answer

Daniel Kulp picture Daniel Kulp · May 1, 2014

Your wsdl would need a wsdl:types element in it that has a schema with an import in it. Basically, the wsdl needs to know about the schema.

 <wsdl:types>
    <xsd:schema>
        <xsd:import namespace="http://www.foo.com/bar" schemaLocation="bar.xsd"/>
    </xsd:schema>
</wsdl:types>