How to use JAXB bindings with WSDL to separate schemas into different packages

Headshot of Alistair

Multi Schema WSDL and separate packages

WSDL

As discussed in my previous blog, WSDL is an XML format that describes network services. It defines endpoints and their request and response formats.

WSDL files contain schemas to describe those request and response objects. A single WSDL file could contain multiple schemas. This is commonly used to share some objects between different network services. Such as to define some common types.

Example

You may have two WSDL files.

One describes a shopping service, and the other defines a checkout service. In the checkout service, you might buy things you shopped for. So it's easy to see why you'd want to share some objects.

Packages

You can create your client library with these WSDL files as-is. But you might want to put files from the different schemas into separate packages.

To achieve this you need to use the JAXB bindings feature. For each WSDL file create a new bindings file.

For example:

- src/main/resources/META-INF/bindings-shopping.jaxb

- src/main/resources/META-INF/bindings-checkout.jaxb

Within these files, we define the base package which our Services will go into. Then we also define a package for each of the schemas.

Now all that's left is to tell our wsimport task about these bindings files.

Now run the wsimport task. It will generate a HTTP client using the separate packages you specified.


Looking for something else?

Search over 400 blog posts from our team

Want to hear more?

Subscribe to our monthly digest of blogs to stay in the loop and come with us on our journey to make things better!