Search in sources :

Example 16 with MultiPartOutput

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

the class TestMultipartOutput method testCreate8bitMimeOutput.

@Test
public void testCreate8bitMimeOutput() {
    try {
        MultiPartOutput output = new MultiPartOutput(guid.getUUID());
        output.addPart(PAYLOAD_1, ENCODING_8BIT, guid.getUUID());
        ByteArrayIterator input = new ByteArrayIterator(output.getBytes());
        assertEquals(NUMBER_OF_PARTS, 1, input.size());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) ByteArrayIterator(com.adaptris.util.text.mime.ByteArrayIterator) Test(org.junit.Test)

Example 17 with MultiPartOutput

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

the class TestMultipartOutput method testCreateBase64MimeOutput.

@Test
public void testCreateBase64MimeOutput() {
    try {
        MultiPartOutput output = new MultiPartOutput(guid.getUUID());
        output.addPart(PAYLOAD_1, ENCODING_BASE64, guid.getUUID());
        ByteArrayIterator input = new ByteArrayIterator(output.getBytes());
        assertEquals(NUMBER_OF_PARTS, 1, input.size());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) ByteArrayIterator(com.adaptris.util.text.mime.ByteArrayIterator) Test(org.junit.Test)

Example 18 with MultiPartOutput

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

the class MimeJunitHelper method createNested.

public static AdaptrisMessage createNested() throws Exception {
    MultiPartOutput output = new MultiPartOutput(GUID.getUUID());
    MimeMultipart nestedMP = new MimeMultipart();
    nestedMP.addBodyPart(createBodyPart(PAYLOAD_1.getBytes(), GUID.getUUID(), "text/plain"));
    nestedMP.addBodyPart(createBodyPart(PAYLOAD_2.getBytes(), GUID.getUUID(), "text/plain"));
    nestedMP.addBodyPart(createBodyPart(PAYLOAD_3.getBytes(), GUID.getUUID(), "text/plain"));
    MimeBodyPart wrapper = new MimeBodyPart();
    wrapper.setContent(nestedMP);
    wrapper.setHeader(HEADER_CONTENT_TYPE, nestedMP.getContentType());
    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);
    output.addPart(wrapper, GUID.getUUID());
    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) MimeMultipart(javax.mail.internet.MimeMultipart) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 19 with MultiPartOutput

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

the class MultiPayloadMessageMimeEncoder method writeMessage.

@Override
public void writeMessage(AdaptrisMessage msg, OutputStream target) throws CoreException {
    try {
        MultiPartOutput output = new MultiPartOutput(msg.getUniqueId());
        if (msg instanceof MultiPayloadAdaptrisMessage) {
            MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) msg;
            for (String id : message.getPayloadIDs()) {
                message.switchPayload(id);
                output.addPart(payloadAsMimePart(message), PAYLOAD_CONTENT_ID + "/" + id);
            }
        } else {
            output.addPart(payloadAsMimePart(msg), PAYLOAD_CONTENT_ID);
        }
        output.addPart(getMetadata(msg), getMetadataEncoding(), METADATA_CONTENT_ID);
        if (msg.getObjectHeaders().containsKey(CoreConstants.OBJ_METADATA_EXCEPTION)) {
            output.addPart(asMimePart((Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION)), EXCEPTION_CONTENT_ID);
        }
        output.writeTo(target);
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 20 with MultiPartOutput

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

the class MimeEncoder method writeMessage.

@Override
public void writeMessage(AdaptrisMessage msg, OutputStream target) throws CoreException {
    try {
        // Use the message unique id as the message id.
        MultiPartOutput output = new MultiPartOutput(msg.getUniqueId());
        output.addPart(payloadAsMimePart(msg), PAYLOAD_CONTENT_ID);
        output.addPart(getMetadata(msg), getMetadataEncoding(), METADATA_CONTENT_ID);
        if (msg.getObjectHeaders().containsKey(CoreConstants.OBJ_METADATA_EXCEPTION)) {
            output.addPart(asMimePart((Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION)), EXCEPTION_CONTENT_ID);
        }
        output.writeTo(target);
        target.flush();
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) IOException(java.io.IOException)

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