Search in sources :

Example 1 with XpathQuery

use of com.adaptris.core.services.metadata.xpath.XpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    XpathMetadataService service = new XpathMetadataService();
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("key1", "//source-id"), new ConfiguredXpathQuery("key2", "//destination-id"), new MetadataXpathQuery("key3", "metadataKey_containing_an_XPath"), new MultiItemConfiguredXpathQuery("key4", "//xpath/that/resolves/to/multiple/items"), new MultiItemMetadataXpathQuery("key5", "metadata_containing_an_Xpath_that_resolves_to_multiple_items"), new ConfiguredXpathQuery("key6", "/svrl:output/svrl:value"))));
    service.setNamespaceContext(createContextEntries());
    return service;
}
Also used : MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)

Example 2 with XpathQuery

use of com.adaptris.core.services.metadata.xpath.XpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_DocType_DefaultBehaviour.

@Test
public void testDoService_DocType_DefaultBehaviour() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_DOCTYPE);
    // Default document factory should disable doctyps.
    XpathMetadataService service = new XpathMetadataService();
    // Shouldn't matter what the query actually is.
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("source", "//source-id"), new ConfiguredXpathQuery("destination", "//destination-id"))));
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) Test(org.junit.Test)

Example 3 with XpathQuery

use of com.adaptris.core.services.metadata.xpath.XpathQuery in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_DisableDocType.

@Test
public void testDoService_DisableDocType() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_DOCTYPE);
    XpathMetadataService service = new XpathMetadataService();
    // Shouldn't matter what the query actually is.
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("source", "//source-id"), new ConfiguredXpathQuery("destination", "//destination-id"))));
    DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
    builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
    service.setXmlDocumentFactoryConfig(builder);
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) KeyValuePair(com.adaptris.util.KeyValuePair) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Example 4 with XpathQuery

use of com.adaptris.core.services.metadata.xpath.XpathQuery 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());
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) XpathObjectQuery(com.adaptris.core.services.metadata.xpath.XpathObjectQuery) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with XpathQuery

use of com.adaptris.core.services.metadata.xpath.XpathQuery in project interlok by adaptris.

the class XpathMetadataService method initService.

@Override
protected void initService() throws CoreException {
    for (XpathQuery query : xpathQueries) {
        query.verify();
    }
    queriesToExecute = new ArrayList<>();
    queriesToExecute.addAll(getXpathQueries());
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery)

Aggregations

XpathQuery (com.adaptris.core.services.metadata.xpath.XpathQuery)12 ConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery)10 MetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MetadataXpathQuery)8 MultiItemConfiguredXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery)8 MultiItemMetadataXpathQuery (com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery)8 Test (org.junit.Test)8 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 ServiceException (com.adaptris.core.ServiceException)4 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)3 ArrayList (java.util.ArrayList)2 CoreException (com.adaptris.core.CoreException)1 MetadataElement (com.adaptris.core.MetadataElement)1 LogMessageService (com.adaptris.core.services.LogMessageService)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1 XpathMetadataService (com.adaptris.core.services.metadata.XpathMetadataService)1 XpathObjectQuery (com.adaptris.core.services.metadata.xpath.XpathObjectQuery)1 TruncateMetadata (com.adaptris.core.util.TruncateMetadata)1 KeyValuePair (com.adaptris.util.KeyValuePair)1 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)1 XPath (com.adaptris.util.text.xml.XPath)1