use of com.adaptris.core.lms.FileBackedMessage in project interlok by adaptris.
the class SerializableMessageTranslatorTest method testSerialize_FileBackedMessage_TooLarge.
@Test
public void testSerialize_FileBackedMessage_TooLarge() throws Exception {
FileBackedMessage adaptrisMessage = (FileBackedMessage) new FileBackedMessageFactory().newMessage();
File sourceFile = TempFileUtils.createTrackedFile(this);
RandomAccessFile rf = new RandomAccessFile(sourceFile, "rw");
// 7Mb should be bigger than the default size.
rf.setLength(1024L * 7 * 1024L);
rf.close();
adaptrisMessage.initialiseFrom(sourceFile);
adaptrisMessage.addMetadata("MetaKey1", "MetaValue1");
adaptrisMessage.addMetadata("MetaKey2", "MetaValue2");
SerializableMessage serialisableAdaptrisMessage = new DefaultSerializableMessageTranslator().translate(adaptrisMessage);
assertEquals("MetaValue1", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey1"));
assertEquals("MetaValue2", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey2"));
assertEquals(adaptrisMessage.getUniqueId(), serialisableAdaptrisMessage.getUniqueId());
assertTrue(serialisableAdaptrisMessage.getContent().contains("Size=7 MB"));
}
use of com.adaptris.core.lms.FileBackedMessage in project interlok by adaptris.
the class SerializableMessageTranslatorTest method testSerialize_FileBackedMessage_Small.
@Test
public void testSerialize_FileBackedMessage_Small() throws Exception {
FileBackedMessage adaptrisMessage = (FileBackedMessage) new FileBackedMessageFactory().newMessage("Some Payload");
adaptrisMessage.addMetadata("MetaKey1", "MetaValue1");
adaptrisMessage.addMetadata("MetaKey2", "MetaValue2");
SerializableMessage serialisableAdaptrisMessage = new DefaultSerializableMessageTranslator().translate(adaptrisMessage);
assertEquals("MetaValue1", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey1"));
assertEquals("MetaValue2", serialisableAdaptrisMessage.getMessageHeaders().get("MetaKey2"));
assertEquals(adaptrisMessage.getUniqueId(), serialisableAdaptrisMessage.getUniqueId());
assertEquals("Some Payload", serialisableAdaptrisMessage.getContent());
}
use of com.adaptris.core.lms.FileBackedMessage in project interlok by adaptris.
the class FilesystemRetryStore method buildForRetry.
@Override
public AdaptrisMessage buildForRetry(String msgId, Map<String, String> metadata, AdaptrisMessageFactory msgFac) throws InterlokException {
try {
File dir = validateMsgId(msgId, true);
File payloadFile = FsWorker.isFile(FsWorker.checkReadable(new File(dir, PAYLOAD_FILE_NAME)));
AdaptrisMessage msg = DefaultMessageFactory.defaultIfNull(msgFac).newMessage();
if (msg instanceof FileBackedMessage) {
((FileBackedMessage) msg).initialiseFrom(payloadFile);
} else {
try (InputStream in = new FileInputStream(payloadFile);
OutputStream out = msg.getOutputStream()) {
IOUtils.copy(in, out);
}
}
msg.setMessageHeaders(metadata);
msg.setUniqueId(msgId);
return msg;
} catch (Exception e) {
throw ExceptionHelper.wrapInterlokException(e);
}
}
Aggregations