Message template = createTemplate();
// Create a new message by transforming the template.
Message transformed = transform(template);
MessageWriter writer = new DefaultMessageWriter();
// Print transformed message.
System.out.println("\n\nTransformed message:\n--------------------\n");
writer.writeMessage(transformed, System.out);
// Messages should be disposed of when they are no longer needed.
// Disposing of a message also disposes of all child elements (e.g. body
// parts) of the message.
transformed.dispose();
// Print original message to illustrate that it was not affected by the
// transformation.
System.out.println("\n\nOriginal template:\n------------------\n");
writer.writeMessage(template, System.out);
// Original message is no longer needed.
template.dispose();
// At this point all temporary files have been deleted because all