Search in sources :

Example 1 with MultiPartOutput

use of com.adaptris.util.text.mime.MultiPartOutput in project interlok by adaptris.

the class FileBackedMimeEncoderTest method generateOutput.

private File generateOutput() throws Exception {
    File file = TempFileUtils.createTrackedFile(this);
    MultiPartOutput output = new MultiPartOutput(new GuidGenerator().getUUID());
    output.addPart(STANDARD_PAYLOAD.getBytes(), "base64", "AdaptrisMessage/payload");
    Properties p = new Properties();
    p.setProperty(METADATA_KEY, METADATA_VALUE);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    p.store(bytes, "");
    bytes.close();
    output.addPart(bytes.toByteArray(), "base64", "AdaptrisMessage/metadata");
    output.addPart(STANDARD_PAYLOAD_NON_JUST_ALPHA.getBytes(), "base64", "Dude/SomeOtherPart");
    try (FileOutputStream out = new FileOutputStream(file)) {
        output.writeTo(out);
    }
    return file;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) FileOutputStream(java.io.FileOutputStream) GuidGenerator(com.adaptris.util.GuidGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) File(java.io.File)

Example 2 with MultiPartOutput

use of com.adaptris.util.text.mime.MultiPartOutput in project interlok by adaptris.

the class MimeJunitHelper method create.

public static AdaptrisMessage create() throws Exception {
    MultiPartOutput output = new MultiPartOutput(GUID.getUUID());
    output.getMimeHeader().addHeader("Subject", "This is the Subject");
    output.addPart(PAYLOAD_1, ENCODING_BASE64, PART1_CONTENT_ID);
    output.addPart(PAYLOAD_2, ENCODING_7BIT, PART2_CONTENT_ID);
    output.addPart(PAYLOAD_3, ENCODING_8BIT, PART3_CONTENT_ID);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(output.getBytes());
    msg.addMetadata(CoreConstants.MSG_MIME_ENCODED, "true");
    return msg;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) AdaptrisMessage(com.adaptris.core.AdaptrisMessage)

Example 3 with MultiPartOutput

use of com.adaptris.util.text.mime.MultiPartOutput in project interlok by adaptris.

the class TestMultipartOutput method testCreateMultiPartMimeOutput.

@Test
public void testCreateMultiPartMimeOutput() {
    try {
        MultiPartOutput output = new MultiPartOutput(guid.getUUID());
        output.addPart(PAYLOAD_1, guid.getUUID());
        output.addPart(PAYLOAD_2, guid.getUUID());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        System.getProperties().store(out, PROPERTY_FILE_HEADER);
        output.addPart(out.toByteArray(), guid.getUUID());
        ByteArrayIterator input = new ByteArrayIterator(output.getBytes());
        assertEquals(NUMBER_OF_PARTS, 3, input.size());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayIterator(com.adaptris.util.text.mime.ByteArrayIterator) Test(org.junit.Test)

Example 4 with MultiPartOutput

use of com.adaptris.util.text.mime.MultiPartOutput in project interlok by adaptris.

the class MultipartMessageBuilder method createOutputPart.

protected MultiPartOutput createOutputPart(AdaptrisMessage msg) throws Exception {
    MultiPartOutput output = new MultiPartOutput(contentId(msg), mimeContentSubType(msg));
    MetadataCollection metadata = mimeHeaderFilter().filter(msg);
    metadata.forEach((e) -> {
        output.setHeader(e.getKey(), e.getValue());
    });
    return output;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) MetadataCollection(com.adaptris.core.MetadataCollection)

Example 5 with MultiPartOutput

use of com.adaptris.util.text.mime.MultiPartOutput in project interlok by adaptris.

the class MultipartMessageBuilder method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try {
        MultiPartOutput output = createOutputPart(msg);
        for (MimePartBuilder builder : getMimeParts()) {
            MimeBodyPart part = builder.build(msg);
            output.addPart(part, part.getContentID());
        }
        try (OutputStream out = msg.getOutputStream()) {
            output.writeTo(out);
        }
        msg.addMetadata(CoreConstants.MSG_MIME_ENCODED, Boolean.TRUE.toString());
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) OutputStream(java.io.OutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Aggregations

MultiPartOutput (com.adaptris.util.text.mime.MultiPartOutput)23 ByteArrayIterator (com.adaptris.util.text.mime.ByteArrayIterator)8 Test (org.junit.Test)8 OutputStream (java.io.OutputStream)5 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CoreException (com.adaptris.core.CoreException)3 MetadataCollection (com.adaptris.core.MetadataCollection)3 GuidGenerator (com.adaptris.util.GuidGenerator)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 MimeBodyPart (javax.mail.internet.MimeBodyPart)3 ServiceException (com.adaptris.core.ServiceException)2 Properties (java.util.Properties)2 MessagingException (javax.mail.MessagingException)2 MimeMultipart (javax.mail.internet.MimeMultipart)2 InputStreamDataSource (com.adaptris.util.text.mime.InputStreamDataSource)1 File (java.io.File)1 InputStream (java.io.InputStream)1 BodyPart (javax.mail.BodyPart)1