Search in sources :

Example 11 with InterlokException

use of com.adaptris.interlok.InterlokException 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

InterlokException (com.adaptris.interlok.InterlokException)11 Test (org.junit.Test)6 CoreException (com.adaptris.core.CoreException)5 File (java.io.File)4 IOException (java.io.IOException)3 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)2 MessageTarget (com.adaptris.interlok.client.MessageTarget)2 DefaultSerializableMessage (com.adaptris.interlok.types.DefaultSerializableMessage)2 InterlokMessage (com.adaptris.interlok.types.InterlokMessage)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ServiceException (com.adaptris.core.ServiceException)1 MetadataDataOutputParameter (com.adaptris.core.common.MetadataDataOutputParameter)1 FileBackedMessage (com.adaptris.core.lms.FileBackedMessage)1 ExceptionHelper.rethrowInterlokException (com.adaptris.interlok.client.jmx.ExceptionHelper.rethrowInterlokException)1 RemoteBlob (com.adaptris.interlok.cloud.RemoteBlob)1 DataOutputParameter (com.adaptris.interlok.config.DataOutputParameter)1 MessageProcessor (com.adaptris.interlok.management.MessageProcessor)1 FileOutputStream (java.io.FileOutputStream)1