Search in sources :

Example 11 with BodyPartIterator

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

the class AggregatingFtpConsumeServiceTest method testService_MultipleFiles_NoDelete.

@Test
public void testService_MultipleFiles_NoDelete() throws Exception {
    int count = 5;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FileSystem filesystem = helper.createFilesystem(count);
    FakeFtpServer server = helper.createAndStart(filesystem);
    try {
        // should be ftp://localhost/home/user/work
        String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL;
        FtpConnection conn = createConnection(server);
        conn.setAdditionalDebug(false);
        AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, ".*", new IgnoreOriginalMimeAggregator());
        consumer.setDeleteAggregatedFiles(Boolean.FALSE);
        AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        execute(service, msg);
        BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
        assertEquals(count, input.size());
        // didn't get dleted so should still exist.
        assertEquals(count, filesystem.listFiles(DEFAULT_WORK_DIR_CANONICAL).size());
    } finally {
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) IgnoreOriginalMimeAggregator(com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) Test(org.junit.Test)

Example 12 with BodyPartIterator

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

the class AggregatingFsConsumeServiceTest method testService_MultipleMessages.

@Test
public void testService_MultipleMessages() throws Exception {
    GuidGenerator o = new GuidGenerator();
    File tempDir = TempFileUtils.createTrackedDir(o);
    String url = "file://localhost/" + tempDir.getCanonicalPath().replaceAll("\\\\", "/");
    AggregatingFsConsumer afc = createConsumer(url, ".*", new IgnoreOriginalMimeAggregator());
    AggregatingFsConsumeService service = createAggregatingService(afc);
    try {
        writeDataMessage(tempDir, o.safeUUID());
        writeDataMessage(tempDir, o.safeUUID());
        start(service);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
        service.doService(msg);
        BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
        assertEquals(2, input.size());
    } finally {
        stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) IgnoreOriginalMimeAggregator(com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 13 with BodyPartIterator

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

the class MimeHelperTest method testBodyPartIterator_CreateFromInvalid.

@Test
public void testBodyPartIterator_CreateFromInvalid() throws Exception {
    try {
        BodyPartIterator m = MimeHelper.createBodyPartIterator(AdaptrisMessageFactory.getDefaultInstance().newMessage("AAAAAAAA"));
        fail("Failed");
    } catch (Exception expected) {
    }
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) Test(org.junit.Test)

Example 14 with BodyPartIterator

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

the class MimeHelperTest method testBodyPartIterator_CreateFromFake.

@Test
public void testBodyPartIterator_CreateFromFake() throws Exception {
    BodyPartIterator m = MimeHelper.createBodyPartIterator(AdaptrisMessageFactory.getDefaultInstance().newMessage(MIME_PAYLOAD));
    assertNotNull(m);
    assertEquals(2, m.size());
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) Test(org.junit.Test)

Example 15 with BodyPartIterator

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

the class MimePartSelector method doService.

/**
 * @see com.adaptris.core.Service#doService(com.adaptris.core.AdaptrisMessage)
 */
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        BodyPartIterator mp = MimeHelper.createBodyPartIterator(msg);
        MimeBodyPart part = selector.select(mp);
        if (part != null) {
            if (preserveHeadersAsMetadata()) {
                addHeadersAsMetadata(mp.getHeaders().getAllHeaders(), headerPrefix(), msg);
            }
            if (preservePartHeadersAsMetadata()) {
                addHeadersAsMetadata(part.getAllHeaders(), partHeaderPrefix(), msg);
            }
            StreamUtil.copyAndClose(part.getInputStream(), msg.getOutputStream());
            if (markAsNonMime()) {
                if (msg.headersContainsKey(CoreConstants.MSG_MIME_ENCODED)) {
                    msg.removeMetadata(msg.getMetadata(CoreConstants.MSG_MIME_ENCODED));
                }
            }
        } else {
            log.warn("Could not select a MimePart for extraction, ignoring");
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) ServiceException(com.adaptris.core.ServiceException) MimeBodyPart(javax.mail.internet.MimeBodyPart) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

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