|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Using ValidateExceptionList to get list of exceptions |
« View previous topic :: View next topic » |
Author |
Message
|
hmistry |
Posted: Tue Jul 16, 2013 11:41 pm Post subject: Using ValidateExceptionList to get list of exceptions |
|
|
Newbie
Joined: 16 Jul 2013 Posts: 3
|
Hi All
This is my first post, so apologies in advance if I have missed anything off! I have searched the mqseries forums and read the documentation, I am wondering whether anyone has got this working....
I'm using Message Broker version 8.0.0.1, and we're trying to validate an incoming XML message against a message set containing the XSD schemas using the CREATE with PARSE statement. The desired behaviour is to get all schema validation errors so I'm using the ValidateExceptionList option in my statement, and then returning all the validation error back to the calling client.
However, the behaviour that I am getting is that the exception is being thrown on the first validation error is encounters.
I have set up a simple example of the message to validate using an XML schema:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/NewXMLSchema"
xmlns:tns="http://www.example.org/NewXMLSchema" elementFormDefault="qualified">
<element name="Message" type="tns:MessageType" />
<complexType name="MessageType">
<sequence>
<element name="Field1" />
</sequence>
</complexType>
</schema>]
|
Example of a valid message generated from the schema:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<tns:Message xmlns:tns="http://www.example.org/NewXMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/NewXMLSchema NewXMLSchema.xsd ">
<tns:Field1 />
</tns:Message>]
|
Example of the invalid message:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<tns:Message xmlns:tns="http://www.example.org/NewXMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/NewXMLSchema NewXMLSchema.xsd ">
<test>asdasd</test>
<tns:Field1 />
<test3>sdada</test3>
</tns:Message>]
|
My message flow consists of:
MQInput -> Compute -> MQOutput
MQInput is set to receive message under BLOB domain
My ESQL code:
Code: |
DECLARE intOptions INTEGER BITOR (ValidateComplete, ValidateContentAndValue, ValidateExceptionList);
CREATE LASTCHILD OF OutputRoot DOMAIN ('XMLNSC') PARSE (InputRoot.BLOB.BLOB,
InputRoot.Properties.Encoding,
InputRoot.Properties.CodedCharSetId,
'XSD_Test',
'Message',
,
intOptions);
|
I expected to see 2 error reported for the invalid message:
1. <test> field as this is not defined in schema
2. <test3> field as this is not defined in the schema
In my exception list tree I see:
Code: |
ExceptionList
RecoverableException
File:CHARACTER:F:\build\slot1\S800_P\src\DataFlowEngine\ImbDataFlowNode.cpp
Line:INTEGER:1154
Function:CHARACTER:ImbDataFlowNode::createExceptionList
Type:CHARACTER:ComIbmMQInputNode
Name:CHARACTER:Validation_Check#FCMComposite_1_1
Label:CHARACTER:Validation_Check.MQ Input
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2230
Text:CHARACTER:Node throwing exception
RecoverableException
File:CHARACTER:F:\build\slot1\S800_P\src\DataFlowEngine\ImbComputeNode.cpp
Line:INTEGER:497
Function:CHARACTER:ImbComputeNode::evaluate
Type:CHARACTER:ComIbmComputeNode
Name:CHARACTER:Validation_Check#FCMComposite_1_3
Label:CHARACTER:Validation_Check.Compute
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2230
Text:CHARACTER:Caught exception and rethrowing
RecoverableException
File:CHARACTER:F:\build\slot1\S800_P\src\DataFlowEngine\ImbRdl\ImbRdlStatementGroup.cpp
Line:INTEGER:666
Function:CHARACTER:SqlStatementGroup::execute
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2488
Text:CHARACTER:Error detected, rethrowing
Insert
Type:INTEGER:5
Text:CHARACTER:.Validation_Check_Compute.Main
Insert
Type:INTEGER:5
Text:CHARACTER:15.3
Insert
Type:INTEGER:5
Text:CHARACTER:CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC' PARSE(InputRoot.BLOB.BLOB, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId, 'XSD_Test', 'Message');
RecoverableException
File:CHARACTER:F:\build\slot1\S800_P\src\DataFlowEngine\ImbRdl\ImbRdlTreeStatements.cpp
Line:INTEGER:402
Function:CHARACTER:SqlCreateFieldStatement::execute
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2909
Text:CHARACTER:Exception creating element
Insert
Type:INTEGER:5
Text:CHARACTER:.Validation_Check_Compute.Main
Insert
Type:INTEGER:5
Text:CHARACTER:15.3
Insert
Type:INTEGER:5
Text:CHARACTER:CREATE LASTCHILD OF OutputRoot DOMAIN 'XMLNSC' PARSE(InputRoot.BLOB.BLOB, InputRoot.Properties.Encoding, InputRoot.Properties.CodedCharSetId, 'XSD_Test', 'Message');
ParserException
File:CHARACTER:F:\build\slot1\S800_P\src\MTI\MTIforBroker\GenXmlParser4\ImbXMLNSCParser.cpp
Line:INTEGER:1038
Function:CHARACTER:ImbXMLNSCParser::parseLastChild
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:5009
Text:CHARACTER:XML Parsing Errors have occurred
ParserException
File:CHARACTER:F:\build\slot1\S800_P\src\MTI\MTIforBroker\GenXmlParser4\ImbXMLNSCDocHandler.cpp
Line:INTEGER:702
Function:CHARACTER:ImbXMLNSCDocHandler::handleParseErrors
Type:CHARACTER:ComIbmMQInputNode
Name:CHARACTER:Validation_Check#FCMComposite_1_1
Label:CHARACTER:Validation_Check.MQ Input
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:5025
Text:CHARACTER:A schema validation error has occurred while parsing the XML document
Insert
Type:INTEGER:2
Text:CHARACTER:5004
Insert
Type:INTEGER:2
Text:CHARACTER:2
Insert
Type:INTEGER:2
Text:CHARACTER:1
Insert
Type:INTEGER:2
Text:CHARACTER:235
Insert
Type:INTEGER:5
Text:CHARACTER:cvc-complex-type.2.4.a: Expecting element with local name "Field1" but saw "test".
Insert
Type:INTEGER:5
Text:CHARACTER:/Root/XMLNSC/http://www.example.org/NewXMLSchema:Message
|
The only error report is for the 'test' element.
Many Thanks for your help in advance! |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jul 16, 2013 11:57 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
It's usually not valid to attempt to parse a document after the first validation failure has occurred.
Because it's usually extremely likely that the first validation failure indicates that the rest of the message is invalid.
Except in those cases where the parser in question is a backtracking parser, where an error that occurs merely indicates that another parsing branch needs to be explored.
Do your expectations of what the XMLNSC parser "should do" come from experience with some other XML parser? Or do they come from some other notion entirely, like a poorly written business requirement based on no technical understanding?
If the second, then you need to make sure that the technical documentation indicates that the business requirement is being met by the implementation decisions made by the developer, rather than trying to force the implementation to meet technical requirements improperly written by non-technical people. |
|
Back to top |
|
 |
goffinf |
Posted: Wed Jul 17, 2013 12:23 am Post subject: Re: Using ValidateExceptionList to get list of exceptions |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
hmistry wrote: |
The desired behaviour is to get all schema validation errors ...
However, the behaviour that I am getting is that the exception is being thrown on the first validation error is encounters.
|
AFAIK Broker will stop at the first validation failure.
I agree though that this is often sub-optimal and you want to inform your caller of all of the validation failures that have occurred rather than have them fix one and re-submit only to find another which was also present in the first request.
You can do this in Java (i.e. in a JCN), by setting the validating parser to output the 'exhaustive' list. That's what we do in some cases.
Sometimes you can combine transformation processing with 'selective' validation', which can have benefits insofar as not being reliant on XSD (which is a pretty blunt tool for this purpose - see below) and ignoring stuff you don't care about. But of course not all messages require transformation.
As an aside (so feel free to ignore all that follows), we tend to find that XSD validation is often an inadequate approach on it own. This is mostly because it is not possible to express whole classes of validation constraint. The XSD grammer is just not expressive enough (at least under v1.0 which is all Broker supports natively). We tend to favour a 'selective' validation approach where we *might* use XSDs for some broad 'structure checking' and then ESQL or Java for very specific constraints, especially those which XSD is not capable of (or leads you into its dangerous outer reaches !). This also allows us to ignore aspects of the data received that are not of interest in a specific business context (sometimes referred to as the 'must ignore unknown' pattern).
The ultimate validation 'backstop' is your business application rules and of course you should be careful about duplicating any of these in Broker unless you *really* need them as an optimisation or because the consumer experience demands it (e.g. receiving message 24x7x365 even when your business apps are not available).
HTHs
Fraser. |
|
Back to top |
|
 |
hmistry |
Posted: Wed Jul 17, 2013 12:26 am Post subject: |
|
|
Newbie
Joined: 16 Jul 2013 Posts: 3
|
In all my experience of using the XMLNS and XMLNSC parsers I've always expected it to fail on the first validation error, standard behaviour as you have described above.
There's no business requirements, just that we are required to get all validation failures before sending a message back to the client. Currently this is done without using message sets and programmatically using ESQL checking each mandatory field is not null or blank and building up a list of failures (in an ideal world the clients should be validating the messages!), so was wondering if there was a better way, also I've tried out supportpac IA9A in the past this this seemed to report all schema errors (we can't use that in this case as the end client wouldn't accept this).
The only reason why I thought this could work differently is based on the documentation and using the ValidateExceptionList option or setting this directly on the node under the Validation tab on nodes where this is available
http://publib.boulder.ibm.com/infocenter/wmbhelp/v8r0m0/index.jsp
- See the ExceptionList section where is states:
Quote: |
Exception List
Throws an exception if validation failures are encountered, but only when the current parsing or writing operation has completed. The resulting exception list is shown below. Each failure is also logged in the user trace if you have asked for user tracing of the message flow, and validation stops. Use this setting if you want processing of the message to halt if a validation failure occurs, but you want to see the full list of failures encountered. This property is affected by the Parse Timing property; when partial parsing is selected the current parsing operation parses only a portion of an input message, so only the validation failures in that portion of the message are reported. |
Maybe I am misinterpreting what is being stated in the documentation? |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jul 17, 2013 12:35 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I didn't see the bit about ValidateExceptionList in the code you posted...
I suspect that what you're seeing is that the parser decides that the containing complex type is not valid, so it does not further parse children of that structure for further errors.
Since, in this case, your containing complex type is the entire message, that means it completes parsing the entire message, and so never sees the next element.
Presumably someone who knows something about the XMLNSC parser will be along to correct me shortly. |
|
Back to top |
|
 |
hmistry |
Posted: Wed Jul 17, 2013 1:25 am Post subject: |
|
|
Newbie
Joined: 16 Jul 2013 Posts: 3
|
Thanks mqjeff!
The ValidateExceptionList is in the DECLARE statement where I'm declaring the options to use  |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jul 17, 2013 1:29 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
hmistry wrote: |
Thanks mqjeff!
The ValidateExceptionList is in the DECLARE statement where I'm declaring the options to use  |
Yes, I agree it's there.
I didn't see it.
 |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|