A good Web service has to have a well defined and enforceable contract. Typically, the contract is expressed using XML Schema language. Unfortunately, up until recently, enforcing the contact was very problematic because of the huge performance overhead associated with running schema validation. XML parsers used to load and parse the schema for every validation request, which was clearly expensive. This has changed with the release JAXP 1.3 which comes with the schema validation framework which allows to first load and compile a schema and then reuse the compiled version for all subsequent validation requests. This may finally make it feasible to use the schema validation for Web services in production environment. I decided to prototype the use of the validation framework for my Web services implemented in XFire (you may also want to explore a schema validation component implemented in ServiceMix ESB). All it took is a fairly simple handler:
Unfortunately, the validation framework does not currently support StAX, so an XML document has to be parsed using SAX or DOM (or JDom with subsequent SAX conversion which is what I chose to do since it was quicker to develop that way). I‘m sure this conversion (and the validation process itself) adds some performance overhead, but I‘m hoping that it won‘t be too bad, especially for simple schemas (and from my experience 90% of all Web services have very simple messages). JAX-RPC-compliant Web services engines should see even less of performance penalty since everything is loaded into DOM from the get-go. Perhaps I‘ll try to run some performance tests and see what happens. |
|
来自: liwp_Stephen > 《XFire》