use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathMetadataService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
Set<MetadataElement> metadataElements = new HashSet<MetadataElement>();
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
try {
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
if (namespaceCtx != null) {
builder.setNamespaceAware(true);
}
XPath xpathToUse = XPath.newXPathInstance(builder, namespaceCtx);
Document doc = XmlHelper.createDocument(msg, builder);
for (XpathQuery query : queriesToExecute) {
metadataElements.add(query.resolveXpath(doc, xpathToUse, query.createXpathQuery(msg)));
}
logMetadata("Xpath Metadata resolved {}", metadataElements);
msg.setMetadata(metadataElements);
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathMetadataServiceTest method testDoService_UsingXpathQuery_WithNamespaceContext_NotNamespaceAware.
@Test
public void testDoService_UsingXpathQuery_WithNamespaceContext_NotNamespaceAware() throws CoreException {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_NAMESPACE);
XpathMetadataService service = new XpathMetadataService();
service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("failureCount", "count(/schematron-output/failed-assert)"))));
execute(service, msg);
// count(/schematron-output/failed-assert) will return 0; becaue Saxon failed
// like the mostly amusing thing that it is.
assertEquals("0", msg.getMetadataValue("failureCount"));
service.setXmlDocumentFactoryConfig(new DocumentBuilderFactoryBuilder().withNamespaceAware(false));
execute(service, msg);
assertTrue(msg.containsKey("failureCount"));
assertEquals("2", msg.getMetadataValue("failureCount"));
}
Aggregations