Manipulating messages in the MIME domain
A MIME message does not need to be received over a particular transport. For example, a message can be received over HTTP by using an HTTPInput node, or over WebSphere® MQ by using an MQInput node. The MIME parser is used to process a message if the message domain is set to MIME in the input node properties, or if you are using WebSphere MQ, and the MQRFH2 header has a message domain of MIME.
This topic explains how to deal with messages that belong to the MIME domain, and are parsed by the MIME parser. Use this information in conjunction with the information in Manipulating message body content.
You can manipulate the logical tree using ESQL before passing the message on to other nodes in the message flow. A message flow can also create a MIME domain tree using ESQL. When a MIME domain message reaches an output node, the MIME parser is called to rebuild the bit stream from the logical tree.
Creating a new MIME tree
CREATE FIELD OutputRoot.MIME TYPE Name;
DECLARE M REFERENCE TO OutputRoot.MIME;
CREATE LASTCHILD OF M TYPE Name NAME 'Data';
- A bit stream from another part of the tree is used. This example
shows how a bit stream could be created from an XML message that is
received by the message flow. The flow
then invokes the BLOB parser to store the data under the Data element.
DECLARE partData BLOB ASBITSTREAM(InputRoot.XMLNS); CREATE LASTCHILD OF M.Data DOMAIN('BLOB') PARSE(partData);
- Instead of parsing the bit stream, create the new structure, then
attach the data to it, as shown in this ESQL example:
DECLARE partData BLOB ASBITSTREAM(InputRoot.XMLNS); CREATE LASTCHILD OF M.Data DOMAIN('BLOB') NAME 'BLOB'; CREATE LASTCHILD OF M.Data.BLOB NAME 'BLOB' VALUE partData;
Both of these approaches create the same tree structure. The first approach is better because explicit knowledge of the tree structure that the BLOB parser requires is not built into the flow.
DECLARE part1Data BLOB ASBITSTREAM(InputRoot.XMLNS, InputProperties.Encoding, InputProperties.CodedCharSetId);
SET OutputRoot.Properties.ContentType = 'multipart/related; boundary=myBoundary';
CREATE FIELD OutputRoot.MIME TYPE Name;
DECLARE M REFERENCE TO OutputRoot.MIME;
CREATE LASTCHILD OF M TYPE Name NAME 'Parts';
CREATE LASTCHILD OF M.Parts TYPE Name NAME 'Part';
DECLARE P1 REFERENCE TO M.Parts.Part[1];
CREATE FIELD P1."Content-Type" TYPE NameValue VALUE 'text/plain';
CREATE FIELD P1."Content-Id" TYPE NameValue VALUE 'part one';
CREATE LASTCHILD OF P1 TYPE Name NAME 'Data';
CREATE LASTCHILD OF P1.Data DOMAIN('BLOB') PARSE(part1Data);
CREATE LASTCHILD OF M.Parts TYPE Name NAME 'Part';
DECLARE P2 REFERENCE TO M.Parts.Part[2];
CREATE FIELD P2."Content-Type" TYPE NameValue VALUE 'text/plain';
CREATE FIELD P2."Content-Id" TYPE NameValue VALUE 'part two';
CREATE LASTCHILD OF P2 TYPE Name NAME 'Data';
CREATE LASTCHILD OF P2.Data DOMAIN('BLOB') PARSE(part2Data);
Modifying an existing MIME tree
SET OutputRoot = InputRoot;
-- Check to see if the MIME message is multipart or not.
IF LOWER(InputProperties.ContentType) LIKE 'multipart/%'
THEN
CREATE LASTCHILD OF OutputRoot.MIME.Parts NAME 'Part';
DECLARE P REFERENCE TO OutputRoot.MIME.Parts.[<];
CREATE FIELD P."Content-Type" TYPE NameValue VALUE 'text/xml';
CREATE FIELD P."Content-ID" TYPE NameValue VALUE 'new part';
CREATE LASTCHILD OF P TYPE Name NAME 'Data';
-- This is an artificial way of creating some BLOB data.
DECLARE newBlob BLOB '4f6e652074776f2074687265650d0a';
CREATE LASTCHILD OF P.Data DOMAIN('BLOB') PARSE(newBlob);
END IF;
CREATE LASTCHILD OF OutputRoot.XMLNSC.emailData DOMAIN('XMLNSC')
PARSE(InputRoot.MIME.Data.BLOB.BLOB,InputProperties.Encoding,
InputProperties.CodedCharSetId);
Managing Content-Type
SET OutputRoot.Properties.ContentType = 'text/plain';
Do
not set the Content-Type value directly in the MIME tree or HTTP trees
because the value is ignored or used inconsistently.starts-with($Root/MIME/Content-Type,"multipart")