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