Search in sources :

Example 16 with BodyPartIterator

use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.

the class MimePartSplitter method splitMessage.

/**
 * @see MessageSplitter#splitMessage(AdaptrisMessage)
 */
@Override
public List<AdaptrisMessage> splitMessage(AdaptrisMessage msg) throws CoreException {
    List<AdaptrisMessage> result = new ArrayList<AdaptrisMessage>();
    AdaptrisMessageFactory fac = selectFactory(msg);
    try (BodyPartIterator mp = MimeHelper.createBodyPartIterator(msg)) {
        while (mp.hasNext()) {
            AdaptrisMessage splitMsg = fac.newMessage();
            MimeBodyPart part = mp.next();
            copy(part, splitMsg);
            copyMetadata(msg, splitMsg);
            result.add(splitMsg);
        }
    } catch (Exception e) {
        throw new CoreException(e);
    }
    logR.trace("Split gave " + result.size() + " messages");
    return result;
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) CoreException(com.adaptris.core.CoreException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException)

Example 17 with BodyPartIterator

use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.

the class IgnoreOriginalMimeAggregatorTest method testService_ContentEncoding.

@Test
public void testService_ContentEncoding() throws Exception {
    // This is a 100 line message, so we expect to get 10 parts.
    AdaptrisMessage msg = SplitterCase.createLineCountMessageInput();
    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 LineCountSplitter());
    MimeAggregator aggr = createAggregatorForTests();
    aggr.setEncoding("base64");
    service.setAggregator(aggr);
    execute(service, msg);
    BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
    assertEquals(10, input.size());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) TimeInterval(com.adaptris.util.TimeInterval) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) LineCountSplitter(com.adaptris.core.services.splitter.LineCountSplitter) NullService(com.adaptris.core.NullService) Test(org.junit.Test)

Example 18 with BodyPartIterator

use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.

the class IgnoreOriginalMimeAggregatorTest method testService_ContentIdProvided.

@Test
public void testService_ContentIdProvided() throws Exception {
    // This is a 100 line message, so we expect to get 10 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.setPartContentId("%message{" + getName() + "}");
    service.setAggregator(aggr);
    execute(service, msg);
    BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
    assertEquals(10, input.size());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) TimeInterval(com.adaptris.util.TimeInterval) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) LineCountSplitter(com.adaptris.core.services.splitter.LineCountSplitter) Test(org.junit.Test)

Example 19 with BodyPartIterator

use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.

the class MimeAggregatorCase method testJoinMessage_ContentTypeExpression.

@Test
public void testJoinMessage_ContentTypeExpression() throws Exception {
    MimeAggregator aggr = createAggregatorForTests().withPartContentType("%message{MyContentType}");
    Set<MetadataElement> metadata = new HashSet<>();
    metadata.add(new MetadataElement("MyContentType", "application/xml"));
    AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>", null, new HashSet<>(metadata));
    AdaptrisMessage s1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>", null, new HashSet<>(metadata));
    AdaptrisMessage s2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>", null, new HashSet<>(metadata));
    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);
        assertEquals("application/xml", part.getContentType());
    }
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) MimeBodyPart(javax.mail.internet.MimeBodyPart) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with BodyPartIterator

use of com.adaptris.util.text.mime.BodyPartIterator in project interlok by adaptris.

the class MimeAggregatorCase method testJoinMessage_ContentIdExpression.

@Test
public void testJoinMessage_ContentIdExpression() throws Exception {
    MimeAggregator aggr = createAggregatorForTests().withPartContentId("%message{MyContentId}");
    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()));
    }
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) MetadataElement(com.adaptris.core.MetadataElement) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.junit.Test)

Aggregations

BodyPartIterator (com.adaptris.util.text.mime.BodyPartIterator)24 Test (org.junit.Test)20 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)18 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)7 TimeInterval (com.adaptris.util.TimeInterval)7 MimeBodyPart (javax.mail.internet.MimeBodyPart)6 LineCountSplitter (com.adaptris.core.services.splitter.LineCountSplitter)5 MetadataElement (com.adaptris.core.MetadataElement)4 NullService (com.adaptris.core.NullService)4 IgnoreOriginalMimeAggregator (com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CoreException (com.adaptris.core.CoreException)2 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MimePartSplitter (com.adaptris.core.services.splitter.MimePartSplitter)2 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)2 HashSet (java.util.HashSet)2 MessagingException (javax.mail.MessagingException)2 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)2 AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)1