Search in sources :

Example 1 with AttachmentHandler

use of org.finos.symphony.toolkit.workflow.sources.symphony.handlers.AttachmentHandler in project spring-bot by finos.

the class JerseyAttachmentHandlerConfig method attachmentHandler.

@Bean
public AttachmentHandler attachmentHandler() {
    return new AttachmentHandler() {

        @Override
        public Object formatAttachment(AttachmentResponse ar) {
            File temp;
            try {
                temp = File.createTempFile(ar.getName(), "." + ar.getExtension());
                FileOutputStream fos = new FileOutputStream(temp);
                fos.write(ar.getAttachment());
                fos.close();
            } catch (Exception e) {
                throw new RuntimeException("Couldn't create file", e);
            }
            FileDataBodyPart fdbp = new FileDataBodyPart("attachment", temp);
            return fdbp;
        }
    };
}
Also used : AttachmentHandler(org.finos.symphony.toolkit.workflow.sources.symphony.handlers.AttachmentHandler) FileOutputStream(java.io.FileOutputStream) AttachmentResponse(org.finos.symphony.toolkit.workflow.response.AttachmentResponse) File(java.io.File) FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart) Bean(org.springframework.context.annotation.Bean)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 AttachmentResponse (org.finos.symphony.toolkit.workflow.response.AttachmentResponse)1 AttachmentHandler (org.finos.symphony.toolkit.workflow.sources.symphony.handlers.AttachmentHandler)1 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)1 Bean (org.springframework.context.annotation.Bean)1