Search in sources :

Example 6 with MultiPartOutput

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

the class MimeEncoderTest method createMimeOutput.

private static byte[] createMimeOutput(boolean includePayloadPart, boolean includeMetadataPart) throws Exception {
    MultiPartOutput output = new MultiPartOutput(new GuidGenerator().getUUID());
    if (includePayloadPart) {
        output.addPart(STANDARD_PAYLOAD.getBytes(), "base64", "AdaptrisMessage/payload");
    }
    if (includeMetadataPart) {
        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");
    return output.getBytes();
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) GuidGenerator(com.adaptris.util.GuidGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 7 with MultiPartOutput

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

the class LargeFsConsumerTest method writeContent.

private File writeContent(File file) throws Exception {
    MultiPartOutput output = new MultiPartOutput(GUID.getUUID());
    output.addPart("Hello World", "base64", "AdaptrisMessage/payload");
    output.addPart("# comment", "base64", "AdaptrisMessage/metadata");
    try (FileOutputStream out = new FileOutputStream(file)) {
        output.writeTo(out);
    }
    return file;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) FileOutputStream(java.io.FileOutputStream)

Example 8 with MultiPartOutput

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

the class DynamicServiceExecutorTest method createMimeMessage.

public static AdaptrisMessage createMimeMessage(Service s, String encoding) throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String xml = DefaultMarshaller.getDefaultMarshaller().marshal(s);
    MultiPartOutput output = new MultiPartOutput(new GuidGenerator().getUUID());
    output.getMimeHeader().addHeader("Subject", "This is the Subject");
    output.addPart(xml, encoding, "Service");
    output.addPart("pack my jug with a dozen liquor jugs", encoding, "part2");
    try (OutputStream out = msg.getOutputStream()) {
        output.writeTo(out);
    }
    return msg;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) OutputStream(java.io.OutputStream) GuidGenerator(com.adaptris.util.GuidGenerator)

Example 9 with MultiPartOutput

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

the class FileBackedMimeEncoder method writeMessage.

@Override
public void writeMessage(AdaptrisMessage msg, File target) throws CoreException {
    try {
        // Use the message unique id as the message id.
        MultiPartOutput output = new MultiPartOutput(msg.getUniqueId());
        AdaptrisMessageFactory factory = currentMessageFactory();
        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);
        }
        try (OutputStream out = new FileOutputStream(target)) {
            // If we are file backed, then lets assume we're large, and we stream to disk first...
            if (factory instanceof FileBackedMessageFactory) {
                output.writeTo(out, ((FileBackedMessageFactory) factory).createTempFile(msg));
            } else {
                output.writeTo(out);
            }
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream)

Example 10 with MultiPartOutput

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

the class FlattenMimeParts method doService.

@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    try (InputStream in = msg.getInputStream()) {
        InputStreamDataSource src = new InputStreamDataSource(in);
        MimeMultipart mime = new MimeMultipart(src);
        MultiPartOutput output = new MultiPartOutput(msg.getUniqueId());
        List<BodyPart> parts = extract(mime);
        for (BodyPart p : parts) {
            output.addPart((MimeBodyPart) p, generateIfNoContentId(p));
        }
        addHeaders(src.getHeaders(), output);
        try (OutputStream out = msg.getOutputStream()) {
            output.writeTo(out);
        }
    } catch (Exception e) {
        throw ExceptionHelper.wrapServiceException(e);
    }
}
Also used : InputStreamDataSource(com.adaptris.util.text.mime.InputStreamDataSource) MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) MimeMultipart(javax.mail.internet.MimeMultipart) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) 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