[
https://jira.jboss.org/jira/browse/JBESB-3036?page=com.atlassian.jira.plu...
]
David Ward commented on JBESB-3036:
-----------------------------------
This one was fun. ;) For whatever reason, the "powers that be" in java-land
decided that malformed xml documents as input to an XSL transformation should log an
error, but continue processing without throwing an exception.
What I found was that the only way to reliably intercept malformed input XML was to parse
it. But before you yell, "Hey, that will cause parsing to be done twice (once for
the malformed checking, and once for the transformation)!" - hold on. I figured out
there's a way to stream them together in one pass. To do this, instead of passing a
simple StreamSource to the Transformer, use a SAXSource, which takes a SAXParser's
XMLReader and an InputSource in the constructor. The XMLReader should also be set up with
a custom ErrorHandler, which I did.
But next was a problem where even though my ErrorHandler threw the SAXParseExceptions
(when a malformed document was created), it was still being swallowed! So, what I had to
do is hold onto the SAXParseException, then check for its existence in my ErrorHandler
after the transformer.transform(Source,Result) had completed, and throw it then. Whew!
The good news is that the mechanism as described above is 90% of the way there to also do
one-pass XML input DTD or XSD validation. But before you yell, "Hey, we already have
a SchemaValidationAction" - hold on. It is *considerably* more performant to do the
XML input validation at the same time as the well-formed check at the same time as the XSL
transformation (3 for the price of 1!). Adding SchemaValidationAction in the chain would
mean : 1) more code to execute, 2) parsing the document twice, 3) building up a DOM tree
which uses more memory than SAX (that's what SchemaValidationAction does), 4)
doesn't let us validate against DTDs, just XSDs.
Note: I think we should at least change SchemaValidationAction to use SAX instead of DOM.
So, I will be attaching an XsltAction Validation Configuration chart to this jira
momentarily. It describes the configuration in detail, then shows what will be the
processing outcome of various input (malformed, well-formed & valid, well-formed and
invalid). In addition to the test case attached to SOA-1573, I modified it locally and
tested all the different permutations as described in the chart. In addition to making
sure the current XsltActionUnitTests, SourceFactoryUnitTests and ResultFactoryUnitTests
worked *unchanged*, I also added 5 new junit tests to XsltActionUnitTests to cover the
scenarios as described in the chart. Last, I updated the Programmer's Guide.
XsltAction - non-well formed XML message is silently transformed to
empty string
--------------------------------------------------------------------------------
Key: JBESB-3036
URL:
https://jira.jboss.org/jira/browse/JBESB-3036
Project: JBoss ESB
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Transformation Service
Affects Versions: 4.7
Reporter: Kevin Conner
Assignee: David Ward
Fix For: 4.7 CP1
Attachments: XsltAction-ValidationConfiguration.pdf
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira