How to specify different schemaLocation for XSDs included in WSDL for different environments?

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 5.0

Issue

  • While maintaining an xsd library which exists externally to the current project. The WSDLs are created by importing necessary xsds from it. In the WSDL <xsd:import> statements, it seems that "schemaLocation" needs to be a file system path at development time but a relative URL (relative to the wsdl file location inside the package) at deployment time.

  • At development time, if it points to the local xsd library, e.g. "/path/to/y/name.xsd", when the application is deployed on JBoss, the path doesn't exist and the application deployment fails.

  • Is there a way that works in both places?

Resolution

  • Rather than hard-coding the schema location into your WSDL, you can provide an XML catalog for the consumers which will allow them to locate it. You can configure the consumers differently when it is in a different location during development.

JBoss Developer Studio (JBDS)

  1. Go to Window->Preferences and then XML->XML Catalog
  2. Add a  mapping between a namespace URI and a file on the filesystem.

JBoss WS

  1. Edit $JBOSS_HOME/server/$PROFILE/conf/jax-ws-catalog.xml

Maven wsconsume plugin

The wscomsume plugin can be configured to use a resolver for entities, but not schemas.

Instead you can tell Maven to copy your WSDL and XSDs to a temporary location whose layout matches that of how it is when deployed on JBoss, and run wsconsume on that.

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <executions>
    <execution>
      <id>copy-wsdl-xsd</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${basedir}/target/temp-wsdl/</outputDirectory>
        <resources>
          <resource>
            <directory>${basedir}/src/main/resources/META-INF/wsdl/</directory>
            <includes>
              <include>PhoneAppend.wsdl</include>
            </includes>
          </resource>
          <resource>
            <directory>/my/external/xsds/</directory>
            <includes>
              <include>*.xsd</include>
            </includes>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.jboss.ws.plugins</groupId>
  <artifactId>maven-jaxws-tools-plugin</artifactId>
  <version>1.0.0.GA</version>
  <configuration>
    <wsdls>
      <wsdl>${basedir}/target/temp-wsdl/PhoneAppend.wsdl</wsdl>
    </wsdls>
    <targetPackage>com.company.sdi.example</targetPackage>
    <extension>true</extension>
    <verbose>true</verbose>
  </configuration>
  <executions>
    <execution>
      <phase>compile</phase>
      <goals>
        <goal>wsconsume</goal>
      </goals>
    </execution>
  </executions>
</plugin>

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments