use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.
the class MimeAggregatorCase method testJoinMessage_ContentId.
@Test
public void testJoinMessage_ContentId() throws Exception {
MimeAggregator aggr = createAggregatorForTests();
aggr.setPartContentId("%message{MyContentId}");
AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>", null, new HashSet<>(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentId", getName() + "_original") })));
original.addMetadata("originalKey", "originalValue");
AdaptrisMessage s1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>", null, new HashSet<>(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentId", getName() + "_split1") })));
AdaptrisMessage s2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>", null, new HashSet<>(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentId", getName() + "_split2") })));
List<String> expectedContentIDs = new ArrayList<>(Arrays.asList(new String[] { getName() + "_original", getName() + "_split1", getName() + "_split2" }));
aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { s1, s2 }));
BodyPartIterator m = new BodyPartIterator(original.getInputStream());
for (int i = 0; i < m.size(); i++) {
MimeBodyPart part = m.getBodyPart(i);
assertTrue(expectedContentIDs.contains(part.getContentID()));
}
}
use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.
the class MimeAggregatorTest method testService_MimeSplitter.
@Test
public void testService_MimeSplitter() throws Exception {
// This is a 3 part message, so that should generate 3 split messages; which should generate 4 parts at the end.
AdaptrisMessage msg = MimeJunitHelper.create();
PooledSplitJoinService service = new PooledSplitJoinService();
// The service doesn't actually matter right now.
service.setService(new NullService());
service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
service.setSplitter(new MimePartSplitter());
MimeAggregator aggr = createAggregatorForTests();
aggr.setEncoding("base64");
service.setAggregator(aggr);
execute(service, msg);
BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
assertEquals(4, input.size());
}
use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.
the class MimeAggregatorTest method testService_withFilter.
@Test
public void testService_withFilter() throws Exception {
// This is a 100 line message, so we expect to get 11 parts.
AdaptrisMessage msg = SplitterCase.createLineCountMessageInput();
PooledSplitJoinService service = new PooledSplitJoinService();
// The service doesn't actually matter right now.
service.setService(createAddMetadataService(getName()));
service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
service.setSplitter(new LineCountSplitter());
MimeAggregator aggr = createAggregatorForTests();
aggr.setFilterCondition(new EvenOddCondition());
service.setAggregator(aggr);
execute(service, msg);
BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
assertEquals(6, input.size());
}
use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.
the class MimeEncoder method readMessage.
@Override
public AdaptrisMessage readMessage(InputStream source) throws CoreException {
try {
AdaptrisMessage msg = currentMessageFactory().newMessage();
BodyPartIterator input = new BodyPartIterator(source);
addPartsToMessage(input, msg);
return msg;
} catch (Exception e) {
throw ExceptionHelper.wrapCoreException(e);
}
}
Aggregations