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();
}
}
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);
}
}
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) {
}
}
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());
}
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);
}
}
Aggregations