use of com.adaptris.core.MetadataCollection in project interlok by adaptris.
the class ExampleEventHandlerCase method testSendEvent_WithProperties.
@Test
public void testSendEvent_WithProperties() throws Exception {
Event e = EventFactory.create(AdapterCloseEvent.class);
T eh = applyConfiguration(newEventHandler(getName()));
Map<String, String> properties = MetadataCollection.asMap(new MetadataCollection(new MetadataElement("hello", "world")));
try {
eh.requestStart();
eh.send(e, properties);
doAssertions(eh, 1, e.getClass());
MockMessageProducer p = getProducer(eh);
AdaptrisMessage msg = p.getMessages().get(0);
assertTrue(msg.headersContainsKey("hello"));
assertEquals("world", msg.getMetadataValue("hello"));
} finally {
eh.requestClose();
}
}
use of com.adaptris.core.MetadataCollection in project interlok by adaptris.
the class MetadataHandler method moveMetadata.
/**
* <p>
* Moves metadata from an <code>AdaptrisMessage</code> to a <code>javax.jms.Message</code> if <code>moveMetadata</code> is
* <code>true</code>.
* </p>
*
* @param in the <code>AdaptrisMessage</code> to move metadata from
* @param out the JMS <code>Message</code> to move metadata to
* @return the JMS <code>Message</code> with metadata added
* @throws JMSException
*/
public final Message moveMetadata(AdaptrisMessage in, Message out) throws JMSException {
MetadataCollection metadataCollection = context.metadataFilter().filter(in);
if (context.metadataConverters().size() == 0) {
new StringMetadataConverter().moveMetadata(metadataCollection, out);
} else {
for (MetadataConverter converter : context.metadataConverters()) {
converter.moveMetadata(metadataCollection, out);
}
}
out.setStringProperty(MESSAGE_UNIQUE_ID_KEY, in.getUniqueId());
if (context.moveJmsHeaders()) {
moveJmsHeaders(in, out);
}
return out;
}
use of com.adaptris.core.MetadataCollection in project interlok by adaptris.
the class MetadataHandler method createMetadataCollection.
private MetadataCollection createMetadataCollection(Message in) throws JMSException {
MetadataCollection result = new MetadataCollection();
Enumeration<?> props = in.getPropertyNames();
while (props.hasMoreElements()) {
String key = (String) props.nextElement();
// converts all to Strings
String value = in.getStringProperty(key);
if (!isEmpty(value)) {
result.add(new MetadataElement(key, value));
} else {
log.debug("ignoring null or empty metadata value against key [" + key + "]");
}
}
return result;
}
use of com.adaptris.core.MetadataCollection in project interlok by adaptris.
the class FixedValuesMetadataFilterTest method testFilterCollection.
@Test
public void testFilterCollection() throws Exception {
FixedValuesMetadataFilter filter = new FixedValuesMetadataFilter().withMetadata(new KeyValuePair("hello", "world"));
MetadataCollection c = filter.filter(new MetadataCollection(createMessage().getMetadata()));
assertEquals(1, c.size());
Map<String, String> map = MetadataCollection.asMap(c);
assertFalse(map.containsKey("someRandomKey"));
}
use of com.adaptris.core.MetadataCollection in project interlok by adaptris.
the class FixedValuesMetadataFilterTest method testFilterSet.
@Test
public void testFilterSet() throws Exception {
FixedValuesMetadataFilter filter = new FixedValuesMetadataFilter().withMetadata(new KeyValuePair("hello", "world"));
MetadataCollection c = filter.filter(createMessage().getMetadata());
assertEquals(1, c.size());
Map<String, String> map = MetadataCollection.asMap(c);
assertFalse(map.containsKey("someRandomKey"));
}
Aggregations