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