Search in sources :

Example 6 with Execution

use of com.adaptris.core.common.Execution in project interlok by adaptris.

the class XPathServiceTest method testPayloadSimpleValueXPathIntoPayload.

@Test
public void testPayloadSimpleValueXPathIntoPayload() throws Exception {
    message.setContent(sampleXml, message.getContentEncoding());
    message.addMetadata("sourceXpathMetadataKey", "//some/random/xml/node1/text()");
    MetadataDataInputParameter metadataDataDestination1 = new MetadataDataInputParameter("sourceXpathMetadataKey");
    Execution execution = new Execution(metadataDataDestination1, new StringPayloadDataOutputParameter());
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("value1", message.getContent());
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) MetadataDataInputParameter(com.adaptris.core.common.MetadataDataInputParameter) ArrayList(java.util.ArrayList) StringPayloadDataOutputParameter(com.adaptris.core.common.StringPayloadDataOutputParameter) Test(org.junit.Test)

Example 7 with Execution

use of com.adaptris.core.common.Execution in project interlok by adaptris.

the class XPathServiceTest method testPayloadSimpleValueXPathIntoPayloadWithHeaderNamespaces.

@Test
public void testPayloadSimpleValueXPathIntoPayloadWithHeaderNamespaces() throws Exception {
    message.setContent(sampleXmlWithHeaderNamespaces, message.getContentEncoding());
    message.addMetadata("sourceXpathMetadataKey", "//some:some/random/xml/n1:node1/text()");
    MetadataDataInputParameter metadataDataDestination1 = new MetadataDataInputParameter("sourceXpathMetadataKey");
    Execution execution = new Execution(metadataDataDestination1, new StringPayloadDataOutputParameter());
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    // Add the namespace mappings
    KeyValuePairSet namespaceMappings = new KeyValuePairSet();
    namespaceMappings.addKeyValuePair(new KeyValuePair("some", "http://adaptris.com/xml/some"));
    namespaceMappings.addKeyValuePair(new KeyValuePair("n1", "http://adaptris.com/xml/n1"));
    namespaceMappings.addKeyValuePair(new KeyValuePair("n2", "http://adaptris.com/xml/n2"));
    namespaceMappings.addKeyValuePair(new KeyValuePair("n3", "http://adaptris.com/xml/n3"));
    service.setNamespaceContext(namespaceMappings);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("value1", message.getContent());
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) MetadataDataInputParameter(com.adaptris.core.common.MetadataDataInputParameter) KeyValuePair(com.adaptris.util.KeyValuePair) ArrayList(java.util.ArrayList) KeyValuePairSet(com.adaptris.util.KeyValuePairSet) StringPayloadDataOutputParameter(com.adaptris.core.common.StringPayloadDataOutputParameter) Test(org.junit.Test)

Example 8 with Execution

use of com.adaptris.core.common.Execution in project interlok by adaptris.

the class XPathServiceTest method testPayloadSimpleValueXPathIntoPayloadWithNamespace.

@Test
public void testPayloadSimpleValueXPathIntoPayloadWithNamespace() throws Exception {
    message.setContent(sampleXmlWithInternalNamespaces, message.getContentEncoding());
    message.addMetadata("sourceXpathMetadataKey", "//some/random/xml/node1/text()");
    MetadataDataInputParameter metadataDataDestination1 = new MetadataDataInputParameter("sourceXpathMetadataKey");
    Execution execution = new Execution(metadataDataDestination1, new StringPayloadDataOutputParameter());
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("value1", message.getContent());
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) MetadataDataInputParameter(com.adaptris.core.common.MetadataDataInputParameter) ArrayList(java.util.ArrayList) StringPayloadDataOutputParameter(com.adaptris.core.common.StringPayloadDataOutputParameter) Test(org.junit.Test)

Example 9 with Execution

use of com.adaptris.core.common.Execution in project interlok by adaptris.

the class XPathService method doService.

// @Override
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    NamespaceContext namespaceContext = SimpleNamespaceContext.create(getNamespaceContext(), msg);
    try {
        DocumentBuilderFactoryBuilder builder = documentFactoryBuilder(namespaceContext);
        Document document = buildDocument(builder, this.getXmlSource().extract(msg));
        XPath xPathHandler = XPath.newXPathInstance(builder, namespaceContext);
        for (Execution execution : this.getExecutions()) {
            String result = this.serializeNode(xPathHandler.selectNodeList(document, execution.getSource().extract(msg)));
            execution.getTarget().insert(result, msg);
        }
    } catch (Exception ex) {
        throw new ServiceException(ex);
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) Execution(com.adaptris.core.common.Execution) ServiceException(com.adaptris.core.ServiceException) NamespaceContext(javax.xml.namespace.NamespaceContext) SimpleNamespaceContext(com.adaptris.util.text.xml.SimpleNamespaceContext) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Document(org.w3c.dom.Document) ServiceException(com.adaptris.core.ServiceException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 10 with Execution

use of com.adaptris.core.common.Execution in project interlok by adaptris.

the class XPathServiceTest method testPayloadAttributeValueXPathIntoMetadata.

@Test
public void testPayloadAttributeValueXPathIntoMetadata() throws Exception {
    message.setContent(sampleXml, message.getContentEncoding());
    MetadataDataOutputParameter metadataDataDestination1 = new MetadataDataOutputParameter("targetMetadataKey");
    ConstantDataInputParameter constantDataDestination = new ConstantDataInputParameter("//some/random/xml/node1/@attr");
    Execution execution = new Execution(constantDataDestination, metadataDataDestination1);
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("attribute value", message.getMetadataValue("targetMetadataKey"));
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) ConstantDataInputParameter(com.adaptris.core.common.ConstantDataInputParameter) ArrayList(java.util.ArrayList) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Aggregations

Execution (com.adaptris.core.common.Execution)13 Test (org.junit.Test)10 MetadataDataOutputParameter (com.adaptris.core.common.MetadataDataOutputParameter)9 StringPayloadDataInputParameter (com.adaptris.core.common.StringPayloadDataInputParameter)9 ArrayList (java.util.ArrayList)9 ConstantDataInputParameter (com.adaptris.core.common.ConstantDataInputParameter)7 MetadataDataInputParameter (com.adaptris.core.common.MetadataDataInputParameter)5 ServiceException (com.adaptris.core.ServiceException)3 StringPayloadDataOutputParameter (com.adaptris.core.common.StringPayloadDataOutputParameter)3 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)2 CoreException (com.adaptris.core.CoreException)1 MetadataElement (com.adaptris.core.MetadataElement)1 DocumentBuilderFactoryBuilder (com.adaptris.core.util.DocumentBuilderFactoryBuilder)1 SimpleNamespaceContext (com.adaptris.util.text.xml.SimpleNamespaceContext)1 XPath (com.adaptris.util.text.xml.XPath)1 IOException (java.io.IOException)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1