Search in sources :

Example 96 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class ConfiguredXpathQueryTest method testResolveXpath_function.

@Test
public void testResolveXpath_function() throws Exception {
    ConfiguredXpathQuery query = init(create(), "count(/message)");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    Document doc = XmlHelper.createDocument(XML);
    MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
    assertEquals("1", result.getValue());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 97 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class ConfiguredXpathQueryTest method testResolveNodesAsString.

@Test
public void testResolveNodesAsString() throws Exception {
    ConfiguredXpathQuery query = new ConfiguredXpathQuery("result", "//source-id");
    query.setAsXmlString(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    MetadataElement result = query.resolveXpath(XmlHelper.createDocument(msg.getContent()), new XPath(), query.createXpathQuery(msg));
    assertEquals("<source-id>partnera</source-id>", result.getValue().strip());
}
Also used : XPath(com.adaptris.util.text.xml.XPath) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 98 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class FirstRowMetadataTranslator method translateResult.

@Override
public long translateResult(JdbcResult source, AdaptrisMessage target) throws SQLException, ServiceException {
    List<MetadataElement> added = new ArrayList<MetadataElement>();
    long resultSetCount = 0;
    Iterator<JdbcResultRow> iter;
    for (JdbcResultSet resultSet : source.getResultSets()) {
        if (resultSet.getRows() != null && (iter = resultSet.getRows().iterator()) != null && iter.hasNext()) {
            JdbcResultRow storedProcedureResultRow = iter.next();
            if (storedProcedureResultRow != null) {
                for (int i = 0; i < storedProcedureResultRow.getFieldCount(); i++) {
                    String column = storedProcedureResultRow.getFieldName(i);
                    String resultSetPrefix = source.countResultSets() > 1 ? Long.toString(resultSetCount) + getResultSetCounterPrefix() : "";
                    MetadataElement md = new MetadataElement(resultSetPrefix + getMetadataKeyPrefix() + getSeparator() + getColumnNameStyle().format(column), toString(storedProcedureResultRow, i));
                    if (log.isTraceEnabled()) {
                        added.add(md);
                    }
                    target.addMetadata(md);
                }
                if (log.isTraceEnabled()) {
                    log.debug("Added metadata : " + added);
                }
            } else {
                log.debug("No Rows to process");
            }
            resultSetCount++;
        }
    }
    return resultSetCount;
}
Also used : JdbcResultRow(com.adaptris.jdbc.JdbcResultRow) ArrayList(java.util.ArrayList) MetadataElement(com.adaptris.core.MetadataElement) JdbcResultSet(com.adaptris.jdbc.JdbcResultSet)

Example 99 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByContentId.

@Test
public void testDoService_MimeServiceExtractor_ByContentId() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByContentId("Service")));
    AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_8BIT);
    execute(dynamicService, msg);
    assertEquals(getName(), msg.getMetadataValue(getName()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) SelectByContentId(com.adaptris.util.text.mime.SelectByContentId) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 100 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_ByPosition.

@Test
public void testDoService_MimeServiceExtractor_ByPosition() throws Exception {
    AddMetadataService metadataService = new AddMetadataService();
    metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
    DynamicServiceExecutor dynamicService = createService();
    dynamicService.setServiceExtractor(new MimeServiceExtractor(new SelectByPosition(0)));
    AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_7BIT);
    execute(dynamicService, msg);
    assertEquals(getName(), msg.getMetadataValue(getName()));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) LogMessageService(com.adaptris.core.services.LogMessageService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) SelectByPosition(com.adaptris.util.text.mime.SelectByPosition) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Aggregations

MetadataElement (com.adaptris.core.MetadataElement)151 Test (org.junit.Test)101 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)94 XPath (com.adaptris.util.text.xml.XPath)23 Document (org.w3c.dom.Document)19 MetadataCollection (com.adaptris.core.MetadataCollection)18 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 ServiceException (com.adaptris.core.ServiceException)17 ServiceList (com.adaptris.core.ServiceList)14 Cache (com.adaptris.core.cache.Cache)14 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)12 ArrayList (java.util.ArrayList)11 CoreException (com.adaptris.core.CoreException)10 Service (com.adaptris.core.Service)10 HashSet (java.util.HashSet)9 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)7 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Session (javax.jms.Session)6