Search in sources :

Example 1 with FileBackedMessage

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"));
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) RandomAccessFile(java.io.RandomAccessFile) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) FileBackedMessage(com.adaptris.core.lms.FileBackedMessage) Test(org.junit.Test)

Example 2 with FileBackedMessage

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());
}
Also used : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) FileBackedMessage(com.adaptris.core.lms.FileBackedMessage) Test(org.junit.Test)

Example 3 with FileBackedMessage

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);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileBackedMessage(com.adaptris.core.lms.FileBackedMessage) FileInputStream(java.io.FileInputStream) InterlokException(com.adaptris.interlok.InterlokException) CoreException(com.adaptris.core.CoreException)

Aggregations

FileBackedMessage (com.adaptris.core.lms.FileBackedMessage)3 FileBackedMessageFactory (com.adaptris.core.lms.FileBackedMessageFactory)2 SerializableMessage (com.adaptris.interlok.types.SerializableMessage)2 File (java.io.File)2 Test (org.junit.Test)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 CoreException (com.adaptris.core.CoreException)1 InterlokException (com.adaptris.interlok.InterlokException)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1