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;
}
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;
}
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());
}
}
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;
}
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);
}
}
Aggregations