use of com.adaptris.core.services.metadata.xpath.XpathObjectQuery in project interlok by adaptris.
the class XpathObjectMetadataServiceTest method testDoService_UsingXpathQuery.
@Test
public void testDoService_UsingXpathQuery() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
XpathObjectMetadataService service = new XpathObjectMetadataService();
service.setXpathQueries(new ArrayList<XpathObjectQuery>(Arrays.asList(new ConfiguredXpathNodeQuery("source", "//source-id"), new ConfiguredXpathNodeQuery("destination", "//destination-id"))));
execute(service, msg);
assertFalse(msg.containsKey("source"));
assertFalse(msg.containsKey("destination"));
assertTrue(msg.getObjectHeaders().containsKey("source"));
assertTrue(msg.getObjectHeaders().containsKey("destination"));
}
use of com.adaptris.core.services.metadata.xpath.XpathObjectQuery in project interlok by adaptris.
the class XpathObjectMetadataServiceTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
XpathObjectMetadataService service = new XpathObjectMetadataService();
service.setXpathQueries(new ArrayList<XpathObjectQuery>(Arrays.asList(new ConfiguredXpathNodeQuery("key1", "//source-id"), new ConfiguredXpathNodeListQuery("key3", "//xpath/that/resolves/to/multiple/items"), new MetadataXpathNodeQuery("key4", "metadata_containing_an_xpath"), new MetadataXpathNodeListQuery("key5", "metadata_containing_a_nodelist_xpath"))));
service.setNamespaceContext(createContextEntries());
return service;
}
use of com.adaptris.core.services.metadata.xpath.XpathObjectQuery in project interlok by adaptris.
the class XpathObjectMetadataServiceTest method testSetXpathQueryList.
@Test
public void testSetXpathQueryList() {
XpathObjectMetadataService service = new XpathObjectMetadataService();
assertEquals(0, service.getXpathQueries().size());
XpathQuery query = new ConfiguredXpathQuery("metadataKey", "//root");
List<XpathObjectQuery> list = new ArrayList<>();
list.add(query);
service.setXpathQueries(list);
assertEquals(list, service.getXpathQueries());
try {
service.setXpathQueries(null);
fail();
} catch (IllegalArgumentException e) {
}
assertEquals(list, service.getXpathQueries());
}
use of com.adaptris.core.services.metadata.xpath.XpathObjectQuery in project interlok by adaptris.
the class XpathObjectMetadataService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
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 (XpathObjectQuery query : queriesToExecute) {
msg.getObjectHeaders().put(query.getMetadataKey(), query.resolveXpath(doc, xpathToUse, query.createXpathQuery(msg)));
log.trace("Added object against [{}]", query.getMetadataKey());
}
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.adaptris.core.services.metadata.xpath.XpathObjectQuery in project interlok by adaptris.
the class XpathObjectMetadataService method initService.
@Override
protected void initService() throws CoreException {
for (XpathObjectQuery query : xpathQueries) {
query.verify();
}
queriesToExecute = new ArrayList<XpathObjectQuery>();
queriesToExecute.addAll(getXpathQueries());
}
Aggregations