This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Web Services and the fly likes validating SOAP Message along with the contents of SOAP Body Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "validating SOAP Message along with the contents of SOAP Body" Watch "validating SOAP Message along with the contents of SOAP Body" New topic
Author

validating SOAP Message along with the contents of SOAP Body

S Kumar
Greenhorn

Joined: Nov 14, 2003
Posts: 9
What is the best approach to validate an incoming SOAP message in its entirety in a client? I am more concerned about validating the SOAP Body content and Header entries which are defined in a vendor's namespace by schemas created by Vendor/WebService provider.
The WebService provider may not provide an "xsi:schemaLocation" attribute for these user defined nodes in the SOAP message. So if we have content in a SOAP message that are defined in different namespaces, do we need to strip those individual nodes and validate them separately. Is there a way in any of the parsers (either thro' JAXP/SAAJ API or in a non-portable way) to say,
"validate nodes in the namespace 'A' with schema 'schemaA.xsd'"
and
"validate nodes in the namespace 'B'with schema 'schemaB.xsd'".
I hope I made it clear. I know that the JAXP API provide a way to specify "one" XML Schema for validating an XML. But more than one based on a namespace...?
Appreciate your help.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You could try writing an aggregate .xsd document, which would import the other schema definitions (one for each namespace).


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
S Kumar
Greenhorn

Joined: Nov 14, 2003
Posts: 9
Lasse, that is a good idea. Thanks for the tip.
What is the best practice though in the Web Service world? Getting the content nodes separately and validating or validating the whole SOAP message as is?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by S K K Kumar:
What is the best practice though in the Web Service world? Getting the content nodes separately and validating or validating the whole SOAP message as is?
Well, there's no need to validate the whole SOAP message as the envelope is guaranteed to be well-formed by the fact that the SOAP engine passes it on to your service implementation. Mostly I've skipped the "real" validation and just relied on my (application-specific) message parser to report an error if it doesn't find what it expects to find. I really don't know what is the best practice, though.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I like "if it doesn't find what it expects to find". Validation also checks that there's nothing there you didn't expect. I prefer to consider that harmless if possible.
Validating with your copy of the schema checks that the provider sent nothing you didn't expect. Prevents them from adding a field for some other consumer. Validating with their copy of the schema checks that they sent you what they said they would, but does not protect you from them removing a field you really need so long as they keep the schema in sync. Neither of those sound all that good, do they?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: validating SOAP Message along with the contents of SOAP Body
 
Similar Threads
WSDL Style?
My two bits
validating xml file against a specific schema using jaxp sax parser
Reading node values in specified datatype in schema( .XSD)
Richard, A Question on validating SOAP messages.