use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathQueryHelperTest method testResolveMultipleNode.
@Test
public void testResolveMultipleNode() throws Exception {
DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
XPath xpathToUse = XPath.newXPathInstance(builder, null);
NodeList nodelist = XpathQueryHelper.resolveNodeList(doc, xpathToUse, "//extra", false);
assertNotNull(nodelist);
assertEquals(3, nodelist.getLength());
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XpathQueryHelperTest method testResolveSingleTextItem.
@Test
public void testResolveSingleTextItem() throws Exception {
DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
XPath xpathToUse = XPath.newXPathInstance(builder, null);
assertNotNull(XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//source-id", false));
assertEquals("partnera", XpathQueryHelper.resolveSingleTextItem(doc, xpathToUse, "//source-id", false));
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class JdbcIteratingDataCaptureServiceImpl method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
log.trace("Beginning doService in {}", LoggingHelper.friendlyName(this));
Connection conn = null;
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
try {
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
XPath xpath = XPath.newXPathInstance(builder, namespaceCtx);
conn = configureActor(msg).getSqlConnection();
Document doc = createDocument(namespaceCtx, msg);
NodeList nodes = nodesToProcess(doc, xpath);
log.debug("Iterating {} times for statement [{}]", nodes.getLength(), getStatement());
PreparedStatement insert = actor.getInsertStatement(msg);
insert.clearParameters();
long rowsUpdated = 0;
for (int i = 0; i < nodes.getLength(); i++) {
log.trace("---Start Iteration {}", i);
Node n = nodes.item(i);
getParameterApplicator().applyStatementParameters(msg, insert, createActualParams(xpath, n), getStatement());
rowsUpdated += executeUpdate(insert);
log.trace("---End Iteration {}", i);
}
rowsUpdated += finishUpdate(insert);
// Will only store the generated keys from the last query
saveKeys(msg, insert);
JdbcUtil.commit(conn, msg);
updateMetadata(msg, rowsUpdated);
} catch (Exception e) {
JdbcUtil.rollback(conn, msg);
throw ExceptionHelper.wrapServiceException(e);
} finally {
JdbcUtil.closeQuietly(conn);
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class JdbcDataQueryService method initXmlHelper.
private void initXmlHelper(AdaptrisMessage msg) throws CoreException {
NamespaceContext namespaceCtx = SimpleNamespaceContext.create(getNamespaceContext(), msg);
DocumentBuilderFactoryBuilder builder = documentFactoryBuilder();
if (namespaceCtx != null) {
builder = builder.withNamespaceAware(true);
}
msg.getObjectHeaders().put(KEY_DOCBUILDER_FAC, builder);
if (containsXpath(getStatementParameters())) {
msg.getObjectHeaders().put(KEY_XML_UTILS, XmlHelper.createXmlUtils(msg, namespaceCtx, builder));
}
if (namespaceCtx != null) {
msg.getObjectHeaders().put(KEY_NAMESPACE_CTX, namespaceCtx);
}
}
use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.
the class XmlValidationServiceTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
ValidationStage vs = new ValidationStage();
vs.setIterationXpath("/document/names");
vs.setElementXpath("fullName");
vs.addRule(new NotNullContentValidation());
KeyValuePair disableExternalEntities = new KeyValuePair("http://xml.org/sax/features/external-general-entities", "false");
KeyValuePair disableDoctypeDecl = new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true");
return new XmlValidationService(new XmlBasicValidator(new DocumentBuilderFactoryBuilder().withNamespaceAware(true).withFeatures(new KeyValuePairSet(Arrays.asList(disableExternalEntities, disableDoctypeDecl)))), new BasicXmlSchemaValidator().withSchema("http://host/schema.xsd or %message{metadatKey}"), new XmlRuleValidator(vs));
}
Aggregations