Spring WS and Java Web Service Standards

I will be giving a talk at The Spring Experience comparing Spring Web Services to Apache Axis2 and CXF and expect the question about Java WS standards to come up. Why doesn’t Spring WS support Java standards? One way to look at this is to understand there are two types of Web Services: code-first and contract-first. Both use the same underlying mechanism (WSDL, SOAP, XML) but conceptually they are far apart. Code-first is really a form of remoting in which XML is merely a wire format. Contract-first on the other hand means much more focus on designing an effective contract independent of the implementation.

Consider standard XML schemas used in various industries such as Health Level 7 (HL7), Univeral Business Language (UBL), or even the Global Justice XML Data Model. These contracts are designed so that disparate business entities who need to exchange data can agree on common type definitions (sometimes that’s easier said than done). This involves a loosely coupled source and destination who need to have a stable contract and be able to evolve independent from each other.

Code-first on the other hand is easier to imagine in situations in which a source and a destination are closely related. For example a .NET client and Java service of the same application are really not that concerned with loose coupling but more with interoperability. What’s confusing is that while this is really a form of remoting it is also considered a Web Service. This terminology is fine but just because WSDL is involved in the exchange don’t expect that same WSDL to be an effective Web Service contract. That is to say one that will remain stable over time.

Going back to the question about Java Web Service standards. The standards are beginning to reflect the importance of the contract-first approach. For example JSR-181 defines annotations to influence the generation of WSDL from a Java endpoint. There is also the Provider interface that allows dealing with a message as a DOM tree. While this is an improvement over previous versions, contract-first remains a secondary topic. This is perhaps reflected in the fact JSR-181 defines the Start with Java development model as required while the Start with WSDL is left as optional.

Lastly to think that Spring Web Services is somehow against Java standards would be incorrect. They’re simply focused on different things. In fact Spring Web Services relies on a number of existing Java standards such as a simple servlet deployment model, JAXP, JAXB, XPath along with many other Java XML API’s and data binding toolkits.

For a good treatment of the Java Web Service standards I highly recommend Mark Hansen’s “SOA Using Java Web Services”. It is a fair, in-depth assessment that will give you a good idea about just how “simple” Web Services are. You can also read about some of his personal travails with the standards online in this blog entry.

Leave a Reply