Search in sources :

Example 86 with MetadataElement

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

the class OrderedItemMetadataFilter method filter.

@Override
public MetadataCollection filter(MetadataCollection originalCollection) {
    MetadataCollection results = new MetadataCollection();
    Map<String, String> original;
    if (ignoreCase()) {
        original = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        original.putAll(MetadataCollection.asMap(originalCollection));
    } else {
        original = MetadataCollection.asMap(originalCollection);
    }
    for (String key : getMetadataKeys()) {
        String value = original.get(key);
        if (value != null) {
            results.add(new MetadataElement(key, value));
        } else {
            results.add(new MetadataElement(key, ""));
        }
    }
    return results;
}
Also used : MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement)

Example 87 with MetadataElement

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

the class LargeMessageWorkflowTest method testRuntimeException.

@Override
@Test
public void testRuntimeException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer() {

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new RuntimeException();
        }
    };
    ;
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    try {
        LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
        channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make none produced", 0, producer.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        for (AdaptrisMessage m : meh.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Service(com.adaptris.core.Service) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) StandardWorkflowTest(com.adaptris.core.StandardWorkflowTest)

Example 88 with MetadataElement

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

the class MimePartChooserTest method testSelect_MarkAsNotMime_OriginalWasNotMarked.

@Test
public void testSelect_MarkAsNotMime_OriginalWasNotMarked() throws Exception {
    MimePartSelector mps = createBaseService();
    mps.setSelector(new com.adaptris.util.text.mime.SelectByPosition(1));
    mps.setMarkAsNonMime(true);
    AdaptrisMessage msg = create();
    msg.removeMetadata(new MetadataElement(CoreConstants.MSG_MIME_ENCODED, "true"));
    assertFalse("Should be not marked as a MIME Message", msg.containsKey(CoreConstants.MSG_MIME_ENCODED));
    execute(mps, msg);
    assertEquals(ASSERT_PAYLOAD, PAYLOAD_2, msg.getContent());
    assertTrue(ASSERT_MSG_SUBJECT_HEADER, msg.containsKey(KEY_METADATA_SUBJECT));
    assertTrue(ASSERT_PART_CID_HEADER, msg.containsKey(METADATA_PART_HDR_CONTENT_ID));
    assertFalse("Should no longer be marked as a MIME Message", msg.containsKey(CoreConstants.MSG_MIME_ENCODED));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 89 with MetadataElement

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

the class MetadataXpathQueryTest method testResolveXpath_EmptyResults_Allowed.

@Test
public void testResolveXpath_EmptyResults_Allowed() throws Exception {
    MetadataXpathQuery query = init(create());
    query.setAllowEmptyResults(Boolean.TRUE);
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
    MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
    assertEquals("", 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 90 with MetadataElement

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

the class MetadataXpathQueryTest method testResolveXpath_EmptyResults_NotAllowed.

@Test
public void testResolveXpath_EmptyResults_NotAllowed() throws Exception {
    MetadataXpathQuery query = init(create());
    Document doc = XmlHelper.createDocument(XML);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML);
    msg.addMetadata("xpathMetadataKey", "//@MissingAttribute");
    try {
        MetadataElement result = query.resolveXpath(doc, new XPath(), query.createXpathQuery(msg));
        fail();
    } catch (CoreException expected) {
    }
}
Also used : XPath(com.adaptris.util.text.xml.XPath) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Document(org.w3c.dom.Document) 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