Search in sources :

Example 6 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathQueryHelperTest method testResolveMultipleTextItems.

@Test
public void testResolveMultipleTextItems() throws Exception {
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance();
    Document doc = XmlHelper.createDocument(XpathQueryCase.XML, builder);
    XPath xpathToUse = XPath.newXPathInstance(builder, null);
    assertNotNull(XpathQueryHelper.resolveMultipleTextItems(doc, xpathToUse, "//extra", false, "|"));
    assertEquals("one|two|three", XpathQueryHelper.resolveMultipleTextItems(doc, xpathToUse, "//extra", false, "|"));
}
Also used : XPath(com.adaptris.util.text.xml.XPath) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 7 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathDocumentCopierTest method testSplit_DocTypeNotAllowed.

@Test
public void testSplit_DocTypeNotAllowed() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.setContent(XML_WITH_DOCTYPE, msg.getContentEncoding());
    XpathDocumentCopier splitter = new XpathDocumentCopier(XPATH_DOCUMENT_COUNT);
    DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
    builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
    splitter.setXmlDocumentFactoryConfig(builder);
    try {
        List<AdaptrisMessage> result = splitToList(splitter, msg);
        fail();
    } catch (CoreException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Example 8 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathSplitterTest method testSplit_DocTypeNotAllowed.

@Test
public void testSplit_DocTypeNotAllowed() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.setContent(XML_WITH_DOCTYPE, msg.getContentEncoding());
    XpathMessageSplitter splitter = new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8);
    DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
    builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
    splitter.setXmlDocumentFactoryConfig(builder);
    try {
        splitter.splitMessage(msg);
        fail();
    } catch (CoreException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : KeyValuePair(com.adaptris.util.KeyValuePair) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test) XpathMetadataServiceTest(com.adaptris.core.services.metadata.XpathMetadataServiceTest)

Example 9 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XpathSplitterTest method testXmlSplitter_Namespace.

@Test
public void testXmlSplitter_Namespace() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XpathMetadataServiceTest.XML_WITH_NAMESPACE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/svrl:schematron-output/svrl:failed-assert", "UTF-8");
    splitter.setNamespaceContext(XpathMetadataServiceTest.createContextEntries());
    NamespaceContext namespaceCtx = SimpleNamespaceContext.create(XpathMetadataServiceTest.createContextEntries());
    DocumentBuilderFactoryBuilder builder = DocumentBuilderFactoryBuilder.newInstance().withNamespaceAware(namespaceCtx);
    // Should be 2 splits
    int count = 0;
    XPath xpath = XPath.newXPathInstance(builder, namespaceCtx);
    try (CloseableIterable<AdaptrisMessage> closeable = splitter.splitMessage(msg)) {
        for (AdaptrisMessage m : closeable) {
            count++;
            assertNotNull(xpath.selectSingleNode(XmlHelper.createDocument(m, builder), "/svrl:failed-assert"));
        }
    }
    assertEquals("Number of messages", 2, count);
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test) XpathMetadataServiceTest(com.adaptris.core.services.metadata.XpathMetadataServiceTest)

Example 10 with DocumentBuilderFactoryBuilder

use of com.adaptris.core.util.DocumentBuilderFactoryBuilder in project interlok by adaptris.

the class XmlValidationServiceTest method testSimpleValidator_IsInvalidXml_LessThan.

@Test
public void testSimpleValidator_IsInvalidXml_LessThan() throws Exception {
    XmlBasicValidator validator = new XmlBasicValidator(new DocumentBuilderFactoryBuilder());
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("<?xml version=\"1.0\"?><Root><</Root>");
    XmlValidationService service = new XmlValidationService(validator);
    try {
        execute(service, msg);
        fail("Success with invalid XML");
    } catch (ServiceException e) {
        ;
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Aggregations

DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)32 XPath (com.adaptris.util.text.xml.XPath)21 Document (org.w3c.dom.Document)21 Test (org.junit.Test)18 NamespaceContext (javax.xml.namespace.NamespaceContext)12 CoreException (com.adaptris.core.CoreException)10 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)10 ServiceException (com.adaptris.core.ServiceException)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 KeyValuePair (com.adaptris.util.KeyValuePair)4 NodeList (org.w3c.dom.NodeList)4 XpathQuery (com.adaptris.core.services.metadata.xpath.XpathQuery)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Node (org.w3c.dom.Node)3 XpathMetadataServiceTest (com.adaptris.core.services.metadata.XpathMetadataServiceTest)2 ConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery)2 MetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MetadataXpathQuery)2 MultiItemConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)2 MultiItemMetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery)2 XmlHelper.createDocument (com.adaptris.core.util.XmlHelper.createDocument)2