Possible parser reuse issue
John Landers
john.landers at thrasys.com
Fri Mar 13 18:31:06 EDT 2015
We ran into an issue that the first call to BasicParserPool.parse fails but
the second call with the same xml doesn't fail.
I looked through the code and method on BasicParserPool: public void
returnBuilder(DocumentBuilder builder)
calls
unwrappedBuilder.reset();
which resets the entityResolver and errorHandler back to the default
constructor versions.
So next time when using a parser from the pool it isn't using the
BasicParserPool errorHandler
LoggingErrorHandler so parsing doesn't fail.
Example code set xml to an invalid xml string like missing a namespace.
// smallest xml to force error.
String xmlString = "<xtest
xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" "
+ "xmlns:XMLSchema-instance=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "</xtest>";
Configuration.getBuilderFactory();
BasicParserPool parser = new BasicParserPool();
parser.setNamespaceAware(true);
parser.setIgnoreElementContentWhitespace(true);
parser.setSchema(SAMLSchemaBuilder.getSAML11Schema());
try
{
Document doc = parser.parse(new StringReader(xmlString));
System.out.println("Won't get here:" + doc);
}
catch (Exception ex)
{
System.out.println("Expected:"+ex.getMessage());
// ex.printStackTrace();
}
try { Document doc = parser.parse(new StringReader(xmlString));
System.out.println("Shouldn't get here:" + doc); } catch (Exception ex) {
ex.printStackTrace(); }
If I added setting entityResolver/errorHandler after result it tosses an
exception on second call:
unwrappedBuilder.reset();
// add these 2 lines to get error on second call.
unwrappedBuilder.setEntityResolver(entityResolver);
unwrappedBuilder.setErrorHandler(errorHandler);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20150313/78667a82/attachment.html
More information about the dev
mailing list