Search in sources :

Example 1 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class StoredProcedureProducerTest method resolveXPath.

private String resolveXPath(AdaptrisMessage message, String xpath) throws XPathExpressionException, IOException {
    XmlUtils xmlUtility = new XmlUtils();
    xmlUtility.setSource(message.getInputStream());
    String textItem = new XPath().selectSingleTextItem(xmlUtility.getCurrentDoc(), xpath);
    if (isEmpty(textItem)) {
        return null;
    } else {
        return textItem;
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) XmlUtils(com.adaptris.util.XmlUtils)

Example 2 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XmlAggregatorTest method testAggregate_WithFilter.

@Test
public void testAggregate_WithFilter() throws Exception {
    XmlDocumentAggregator aggr = createAggregatorForTests();
    aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
    aggr.setFilterCondition(new EvenOddCondition());
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage original = fac.newMessage("<envelope/>");
    AdaptrisMessage splitMsg1 = fac.newMessage("<document>hello</document>");
    AdaptrisMessage splitMsg2 = fac.newMessage("<document>world</document>");
    aggr.aggregate(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
    XPath xpath = new XPath();
    Document d = XmlHelper.createDocument(original, DocumentBuilderFactoryBuilder.newInstance());
    assertEquals(1, xpath.selectNodeList(d, ENVELOPE_DOCUMENT).getLength());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) XPath(com.adaptris.util.text.xml.XPath) EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Document(org.w3c.dom.Document) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 3 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XmlAggregatorTest method testSplitJoinService_WithExplicitDocumentEnoding.

@Test
public void testSplitJoinService_WithExplicitDocumentEnoding() throws Exception {
    // This is a XML doc with 3 iterable elements...
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(SplitterCase.XML_MESSAGE);
    PooledSplitJoinService service = new PooledSplitJoinService();
    // The service doesn't actually matter right now.
    service.setService(asCollection(new NullService()));
    service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
    service.setSplitter(new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8));
    XmlDocumentAggregator aggr = new XmlDocumentAggregator(new InsertNode(XPATH_ENVELOPE));
    aggr.setDocumentEncoding("UTF-8");
    service.setAggregator(aggr);
    execute(service, msg);
    // Should now be 6 document nodes
    XPath xpath = new XPath();
    assertEquals(6, xpath.selectNodeList(XmlHelper.createDocument(msg, true), ENVELOPE_DOCUMENT).getLength());
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) XPath(com.adaptris.util.text.xml.XPath) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) XpathMessageSplitter(com.adaptris.core.services.splitter.XpathMessageSplitter) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 4 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class IgnoreOriginalXmlAggregatorTest method testSplitJoinService_WithExplicitDocumentEnoding.

@Test
public void testSplitJoinService_WithExplicitDocumentEnoding() throws Exception {
    // This is a XML doc with 3 iterable elements...
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(SplitterCase.XML_MESSAGE);
    PooledSplitJoinService service = new PooledSplitJoinService();
    // The service doesn't actually matter right now.
    service.setService(asCollection(new NullService()));
    service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
    service.setSplitter(new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8));
    IgnoreOriginalXmlDocumentAggregator aggr = new IgnoreOriginalXmlDocumentAggregator("<new/>", new InsertNode("/new"));
    aggr.setDocumentEncoding("UTF-8");
    service.setAggregator(aggr);
    execute(service, msg);
    // Should now be 3 document nodes
    // because we ignore the original
    XPath xpath = new XPath();
    assertEquals(3, xpath.selectNodeList(XmlHelper.createDocument(msg, true), "/new/document").getLength());
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) XPath(com.adaptris.util.text.xml.XPath) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) XpathMessageSplitter(com.adaptris.core.services.splitter.XpathMessageSplitter) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 5 with XPath

use of com.adaptris.util.text.xml.XPath in project interlok by adaptris.

the class XmlPayloadTranslatorTest method testService_XpathParam_WithAutoConvert.

// This should effectively give the same results as testService_WithTranslators...
@Test
public void testService_XpathParam_WithAutoConvert() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createXmlService();
    s.setResultSetTranslator(new XmlPayloadTranslator().withAttemptAutoConvert(true).withColumnNameStyle(ColumnStyle.NoStyle));
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    XPath xp = new XPath();
    Document xmlDoc = XmlHelper.createDocument(msg, DocumentBuilderFactoryBuilder.newInstance());
    assertNull(xp.selectSingleNode(xmlDoc, "/Results/OriginalMessage"));
    assertNotNull(xp.selectSingleNode(xmlDoc, "/Results/Row"));
    assertEquals(entry.getVersion(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/ADAPTER_VERSION"));
    assertEquals(String.valueOf(entry.getCounter()), xp.selectSingleTextItem(xmlDoc, "/Results/Row/COUNTER"));
    assertEquals(entry.getTranslatorType(), xp.selectSingleTextItem(xmlDoc, "/Results/Row/MESSAGE_TRANSLATOR_TYPE"));
    // This should have been done by a TimestampColumnTranslator...
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    assertEquals(df.format(entry.getDate()), xp.selectSingleTextItem(xmlDoc, "/Results/Row/INSERTED_ON"));
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Document(org.w3c.dom.Document) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Aggregations

XPath (com.adaptris.util.text.xml.XPath)75 Document (org.w3c.dom.Document)64 Test (org.junit.Test)63 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)45 MetadataElement (com.adaptris.core.MetadataElement)23 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)21 CoreException (com.adaptris.core.CoreException)12 Node (org.w3c.dom.Node)11 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)9 NamespaceContext (javax.xml.namespace.NamespaceContext)9 ServiceException (com.adaptris.core.ServiceException)7 InsertNode (com.adaptris.util.text.xml.InsertNode)6 NodeList (org.w3c.dom.NodeList)6 NullService (com.adaptris.core.NullService)5 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)5 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)5 TimeInterval (com.adaptris.util.TimeInterval)5 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)2