MIME Service

Use the MIME service to build (construct) or decode an RFC822-compliant MIME multipart document.

The following table provides an overview of the MIME service:

Category Description
System name MIME Service
Graphical Process Modeler (GPM) categories All Services, Communications
Description Encodes and decodes MIME multipart messages.
Business usage Performs two functions:
  • Builds (constructs) a MIME multipart message from an XML representation of a MIME message.
  • Decodes a MIME multipart message into its corresponding XML representation.
Use the MIME service if an RFC 822-compliant document is needed.
Usage examples Examples:
  • As part of a business process, you want to create a MIME multipart document to be sent using any of the transport adapters.
  • You want a business process to parse an incoming MIME multipart document.
Preconfigured? Yes
Requires third-party files? No
Platform availability All supported Sterling B2B Integrator platforms
Related services None
Application requirements None
Initiates business processes? No
Invocation Runs as part of a business process.
Business process context considerations None
Returned status values None
Restrictions The XML node to be MIME encoded must be created in the expected XML representation. The construction of the MIME multipart document is dependent on the structure of the XML node that is being passed to the service. The service might fail if the XML node does not follow the correct structure. See Business Scenario and Usage Examples for information about how to create a valid XML node representation. This service does not support document streaming for files > 900 MB.
Testing considerations The easiest way to test this service is to set up a business process that reads in the files to be MIME encoded, creates the XML representation of the MIME message, and then runs the MIME service to encode the documents. You can then decode the MIME document and make sure it is represented in the format you expect. See Business Scenario and Usage Examples for information.

How the MIME Service Works

The MIME service is used to encode or decode an RFC822-compliant MIME multipart document. An RFC822-compliant MIME multipart document is a MIME document that includes one or more attachments and has the sender and recipient addresses, as well as the subject header, written in the headers. The attachments can be of different file types, for example, a Microsoft Word document or Excel spreadsheet.

The following section describes a business scenario in which you can use the MIME service, along with a sample solution.

Business Scenario

Your company exchanges product information with a trading partner. Your trading partner expects RFC822-compliant MIME documents from you. You need to send one Microsoft Word file and one text file as attachments. After you create the RFC822-compliant MIME document, you need to make it the primary document so another business process can send it to your trading partner.

Business Solution Example

The following approach is used to solve the above business scenario.
  1. Use the pre-configured MIME service or create your own MIME service instance.
  2. Create a business process that does the following:
    1. Uses the File System adapter to read in the documents that need to be encoded.
    2. Sets up an XML representation of the MIME message in the process data of the business process and adds the documents to the XML in process data. For more information, see Process Data Prerequisites.
    3. The MIME service encodes the documents and assigns the MIME-encoded document as the primary document.
    4. Sends the MIME-encoded document to the trading partner using the SMTP Send adapter. For more information, see SMTP Send Adapter.
      Note: The example in this section focuses only on the MIME service functionality.

Process Data Prerequisites

To use the MIME service to MIME-encode documents, you need to construct an XML representation of the MIME message and place it in the process data of the business process prior to calling the MIME service. The upper-level mime:message element placed in process data is input to the MIME service. See Business Process Modeling Language (BPML) Example.

The XML representation of the MIME message contains three main elements that represent a MIME part. These elements include:
  • mime:message – This element is the root node for the MIME part.
  • mime:header – This element creates the specific header for the MIME part.
  • mime:body – This element creates the content of the MIME part.

Because our example is a multipart message that contains two attachments, each MIME part has its own individual headers and body. To support this format, you need to create additional mime:message, mime:header, and mime:body elements underneath the first mime:body element for each of your attachments.

The example in the following section illustrates this point. In addition, see Setting up Process Data for MIME Encoding.

Business Process Modeling Language (BPML) Example

The following example shows a solution to the business scenario using BPML.

Business Process Modeling Language (BPML) Example
Business Process Modeling Language (BPML) Example
Business Process Modeling Language (BPML) Example
The code from the example above showing a solution to the business scenario using BPML is given below:
<process name="ExampleMimeEncoding2Documents">
	<sequence>
		<operation name="Read In First Document">
			<participant name="FileSystemAdapterReadFiles"/>
			<output message="FileSystemInputMessage">
				<assign to="Action">FS_COLLECT</assign>
				<assign to="collectionFolder" from="'/server1/user/temp'"/>
				<assign to="deleteAfterCollect">false</assign>
				<assign to="filter" from="'WordDoc'"/>
				<assign to="useSubFolders">false</assign>
				<assign t="." from="*"/>
				</output>
			<input message="FileSystemOutputMessage">
				<assign to="." from="*"/>
			</input>
		</operation>
		<assign to="Doc1" from="PrimaryDocument/@*"/>
		<operation name="Read In Second Document">
			<participant name="FileSystemAdapterReadFiles"/>
			<output message="FileSystemInputMessage">
				<assign to="Action">FS_COLLECT</assign>
				<assign to="collectionFolder" from="'/server1/user/temp'"/>
				<assign to="filter" from="'Text'"/>
				<assign to="useSubFolders">false</assign>
				<assign to="bootstrap">false</assign>
				<assign to="deleteAfterCollect">false</assign>
				<assign to="." from="*"/>
			</output>
			<input message="FileSystemOutputMessage">
				<assign to="." from="*"/>
			</input>
		</operation>
				<assign to="Doc2" from="PrimaryDocument/@*"/>
				<assign to="mimeDoc/mime:message/mime:header" from="'multipart/form-data'"/>
	append="true"/>
				<assign to="mimeDoc/mime:message/mime:header/@name" from="'Content-Type'"/>
				<operation name="Assign Document ID for Doc1">
				<participant name="This"/>
				<output message="giveDocumentRequest">
					<assign to="." from="*"/>
					<assign to="documentKey" from="'Doc1'"/>
				</output>
				<input message="giveDocumentResponse">
					<assign to="Doc1/doc:document-id" from="documentId/text()"
	append="true"/>
				</input>
		</operation>
			<assign to="MIMEtemp1/mime:message/mime:header" from="'111'" append="true"/>
			<assign to="MIMEtemp1/mime:message/mime:header/@name" from="'Content-ID'"
	append="true"/>
			<assign to="MIMEtemp1/mime:message/mime:header" from="'application/EDI-X12'"
	append="true"/>
			<assign to="MIMEtemp1/mime:message/mime:header/@name" from="'Content-Type'"
	append="true"/>
			<assign to="MIMEtemp1/mime:message/mime:body" from="Doc1/doc:document-id"/>
			<assign to="mimeDoc/mime:message/mime:body/mime:message" from="MIMEtemp1/mime:message/node()" append="true"/>
			<operation name="Assign Document ID for Doc2">
				<participant name="This"/>
				<output message="giveDocumentRequest">
					<assign to="." from="*"/>
					<assign to="documentKey" from="documentId/text()"
	append="true"/>
				</input>
			</operation>
			<assign to="MIMEtemp2/mime:message/mime:header" from="'112'" append="true"/>
			<assign to="MIMEtemp2/mime:message/mime:header/@name" from="'Content-ID'"
	append="true"/>
			assign to="MIMEtemp2/mime:message/mime:header" from="'text/xml'"
	append="true"/>
			assign to="MIMEtemp2/mime:message/mime:header/@name" from="'Content-Type'"
	append="true"/>
			assign to="MIMEtemp2/mime:message/mime:body" from="Doc2/doc:document-id"/>
			assign to="mimeDoc/mime:message/mime:body/mime:message" from="MIMEtemp2/mime:message/node()" append="true"/>
			<operation name="MIME encode both documents">
				participant name="MIME"/>
				<output message="packRequest">
					<assign to="mime-document" from="mimeDoc/mime:message"/>
				</output>
				<input message="packResponse">
					<assign to="." from="*" append="true"/>
				</input>
			</operation>
			<assign to="PrimaryDocument" from="mime-document/@*"></assign>
			<operation name="Email MIME Message">
				<participant name="SMTP_SEND_ADAPTER"/>
				<output message="Xout">
					<assign to="." from="*"/>
					<assign to="xport-smtp-mailhost">00.000.00.00</assign>
					<assign to="xport-smtpmailport">25</assign>
					<assign to="xport-smtp-mailfrom">stest1@co.com</assign>
					<assign to="xport-smtp-mailto">stest22co.com</assign>
					<assign to="xport-smtp-mailsubject">This is the subject</assign>
					<assign to="b2b-raw-message">false</assign>
				</output>
				<input message="Xin">
					<assign to="." from="*"/>
				</input>
		</operation>
	</sequence>
</process>

The following example shows the input to the MIME service from process data. This XML representation of the MIME message was created in the above business process prior to starting the MIME service. The MIME service processes everything under the first-level mime:message element (see the output message defined for the MIME service in the above example).

<mimeDoc> 
	<mime:message xmlns:mime="http://www.company.com/company-name/mime/v0.5"> 
 	<mime:header name="Content-Type">multipart/form-data</mime:header> 
 	<mime:body> 
	 	<mime:message> 
		 	<mime:header name="Content-ID">111</mime:header> 
		 	<mime:header name="Content-Type">application/EDI-X12</mime:header> 
		 	<mime:body> 
			 	<doc:document-id xmlns:doc="http://www.company.com/company-name/
        document-id">serverName:76f6d6a8:fbbb18bfda:-6b01</doc:document-id> 
		 	</mime:body> 
	 	</mime:message> 
	 	<mime:message> 
		 	<mime:header name="Content-ID">112</mime:header> 
		 	<mime:header name="Content-Type">text/xml</mime:header> 
		 	<mime:body> 
			 	<doc:document-id xmlns:doc="http://www.company.com/company-name/ 
         document-id">serverName:76f6d6a8:fbbb18bfda:-6aea</doc:document-id> 
		 	</mime:body> 
	 	</mime:message> 
 	</mime:body> 
	</mime:message> 
</mimeDoc>

The following example shows the output returned from the MIME service to the business process. This output is returned as a document named mime-document. The business process explicitly assigns the mime-document to primary document (see the Assign statement following the MIME service in the previous BPML), which is then passed to the SMTP Send adapter.

MIME service output to business process

GPM Example

The following example shows the corresponding GPM view of the business process.

GPM view of business process

For additional MIME service examples, see Usage Examples.

Implementing the MIME Service

You can implement the MIME service in two ways:
  • To MIME-encode documents
  • To MIME-decode documents

The information in this section applies to both implementations.

To implement the MIME service for use in a business process:
  1. Collect the following information:

    For MIME-encoding:

    • The documents you want to MIME encode
    • The XML representation of the MIME message for the MIME service to use (See Setting up Process Data for MIME Encoding for more information.)

    For MIME-decoding:

    • The document ID of the MIME-encoded document
  2. Create a MIME service configuration. For information, see Managing Services and Adapters.
  3. Configure the MIME service. For information, see Configuring the MIME Service.
  4. Use the MIME service in a business process.

Configuring the MIME Service

To configure the MIME service, you must specify settings for the following fields in the GPM:

MIME service configuration

The following example shows the corresponding BPML parameters for the MIME service encoding GPM parameters.

<process name="ExampleMimeEncodeGPM"> 
	<sequence> 
 	<operation name="MIME encode documents"> 
	 	<participant name="MIME"/> 
	 	<output message="packRequest"> 
		 	<assign to="mime-document" from="nodeInProcessData/mime:message"/> 
	 	</output> 
	 	<input message="packResponse"> 
		 	<assign to="." from="*"/> 
	 	</input> 
 	</operation> 
	</sequence> 
</process> 

The following screen shows an example of a graphical view of the GPM parameters for decoding a document using the MIME service. You must set the mime-document-id/doc:document-id parameter for the document being decoded using the Advanced Editor.

Document decoding using MIME service

The following example shows the corresponding BPML parameters for the MIME service decoding GPM parameters.

<process name="ExampleMimeDecodeGPM"> 
	<sequence> 
 	<operation name="MIME Service"> 
	 	<participant name="MIME"/> 
	 	<output message="crackRequest"> 
		 	<assign to="mime-document-id/doc:document-id" from="/ProcessData/
                documentId/text()"/> 
	 	</output> 
	 	<input message="crackResponse"> 
		 	<assign to="decodedDocument" from="mime-document/*"/> 
	 	</input> 
 	</operation> 
	</sequence> 
</process> 
The following table describes the fields used to configure the MIME service in the GPM. The Message Name in the configuration can be set either to packRequest or crackRequest:
  • Set the Message Name (or output message) of the MIME service to packRequest when you want to MIME-encode documents.
  • Set the Message Name (or output message) of the MIME service to crackRequest when you want to MIME-decode documents.

Where Message Name is the GPM parameter and output message is the BPML parameter.

Field Description
Config Name of the service configuration.
debug Indicates if debug information needs to be printed. Valid values are true and null.
inline-first-body-part Whether the first body part is to be inlined. Valid values are true and null. Required when service starts with output message set to crackRequest.
Note: inline-first-body-part = true implies that the first body part of the incoming MIME multipart document is XML and will be available in the process data upon the completion of this service.
mime-document Node that needs to be MIME encoded. Required when service starts with output message set to packRequest.
mime-document-id Node containing the document-id referencing the multipart document. Required when service starts with output message set to crackRequest.
addFilenameEscapes Indicates if the filename parameter in the Content-Disposition field has its backslashes “unescaped”. Preserves the backslashes in the filename. Optional.

Troubleshooting MIME Service Configurations

Consider these points when troubleshooting MIME service configurations:
  • The construction of the MIME multipart document is dependent on the structure of the XML representation of the MIME message in process data that is being passed to the service. If the service fails, it is often because the XML representation of the MIME message is invalid. See Setting up Process Data for MIME Encoding for information about setting up the XML representation.
  • You must keep track of the document Ids of all the payloads you want to encode. You need to specify these document Ids in the XML representation of the MIME message.
  • To enable base64 encoding of attachments, the Content-Transfer-Encoding of the attachment needs to be specified in the header. To do this, add the following line to the <mime:header> tag of the attachment:
<mime:header name="Content-Transfer-Encoding">base64</mime:header>"

Usage Examples

This section contains additional examples using the MIME service, including information about creating the XML representation of the MIME message.

Setting up Process Data for MIME Encoding

The following example illustrates how you can create the XML representation of the MIME message in process data for input to the MIME service for encoding documents. This business process assumes that you have two documents you want to MIME encode, one Microsoft Word document and one XML document. It is assumed that these files were input to the business process and stored in process data as Doc1 and Doc2 (not shown).

XML representation of the MIME message
The code snippet from the above example is given below:
<process name = "SetupProcessDataForMIMEencoding">
	<sequence>
		<assign to="mimeDoc/mime:message/mime:header" from="'multipart/form-data'"
append="true"/>
		<assign to="mimeDoc/mime:message/mime:header/@name" from="'Content-Type'"/>
		<operation name="Assign Document ID for Doc1">
			<participant name="This"/>
			<output message="giveDocumentRequest">
				<assign to="." from="*"/>
				<assign to="documentKey" from="'Doc1'"/>
			</output>
			<input message="giveDocumentResponse">
				<assign to="Doc1/dpc:document-id" from="documentId/text()"
append="true"/>
			</input>
		</operation>
		<assign to="MIMEtemp1/mime:message/mime:header" from"'111'" append="true"/>
		<assign to="MIMEtemp1/mime:message/mime:header/@name" from="'Content-ID'"
append="true"/>
		<assign to="MIMEtemp1/mime:message/mime:header" from="'application/EDI-X12'"
append="true"/>
		<assign to="MIMEtemp1/mime:message/mime:header/@name" from="'Content-Type'"
append="true"/>
		<assign to="MIMEtemp1/mime:message/mime:body" from="Doc1/doc:document-id"/>
		<assign to="mimeDoc/mime:message/mime:body/mime:message" from="MIMEtemp1/mime:message/node()" append="true"/>
		<operation name="Assign Document ID for DOc2">
			<participant name="This"/>
			<output message="giveDocumentRequest">
				<assign to="." from="*"/>
				<assign to="documentKey" from="'Doc2'"/>
			</output>
			<input message="giveDocumentResponse">
				<assign to="Doc2/doc:document-id" from="documentId/text()"
append="true"/>
			</input>
		</operation>
		</assign to="MIMEtemp2/mime:message/mime:header" from="'112'" append="true"/>
		<assign to="MIMEtemp2/mime:message/mime:header/2name" from="'Content-ID'"
append="true"/>
		<assign to="MIMEtemp2/mime:message/mime:header" from="'text/xml'"
append="true"/>
		<assign to="MIMEtemp2/mime:message/mime:header/@name" from="'Content-Type'"
append="true"/>
		<assign to="MIMEtemp2/mime:message/mime:body" from="Doc2/doc:document-id"/>
		<assign to="MIMEDoc/mime:message/mime:body/mime:message" from="MIMEtemp2/mime:message/node()" append="true"/>
	<sequence>
</process>

Running the above business process creates the following information in process data, which is input to the MIME service:

MIME service input
<mimeDoc>
	<mime:message xmlns:mime="http://www.company.com/company-name/mime/v0.5">
		<mime:header name="Content-Type">multipart/form-date</mime:header>
		<mime:body>
			<mime:message>
				<mime:header name="Content-ID">111</mime:header>
				<mime:header name="Content-Type">application/EDI-X12</mime:header>
				<mime:body>
					<doc:document-id xmlns:doc="http://www.company.com/compamy-name/document-id">servername:5f6303:fb326b59ac:6f71</doc:document-id>
				</mime:body>
			</mime:message>
			<mime:message>
				<mime:header name="Content-ID">112</mime:header>
				<mime:header name="Content-Type">text/xml</mime:header>
				<mime:body>
					<doc:document-id xmlns:doc="http://www.company.com/company-name/document-id">servername:5f6303:fb326b59ac:-6f5e</doc:document-id>
				</mime:body>
			</mime:message>
		</mime:body>
	</mime:message>
<mimeDoc>

MIME Decoding

The following example illustrates a MIME document that needs decoding. The following MIME document is input to the business process.

MIME document that needs decoding
Content-Type:multipart/form-data; boundary="ServerName:5f6303:fb4edbb774:-5b83:multipart.boundary.string"
Content-Length: 19757

--serverName::5f6303:fb4edbb774:-5b83::multipart.boundary.string
Content-ID: 111
Content-Type: application/EDI-X12
_Microsoft Word Document
MSWordDic_Word.Document.89q
--serverName::5f6303:fb4edbb774:-5b83::multipart.boundary.string
Content-ID: 112
Content-Type: text/xml

<Text>
</Text>
--serverName::5f6303:fb4edbb774:-5b83::multipart.boundary.string--

The following example illustrates a business process in BPML format that uses the MIME service to decode the MIME document.

Decoding using MIME service
The code snippet from the above example is given below:
<process name = "MIMEDecoding">
	<sequence>
	
		<operation>
			<participant name="GetDocumentInfoService"/>
				<output message="Xout">
					<assign to="." from="*"></assign>
				</output>
			<input message="Xin">
				<assign to="primaryDocId" from=DocumentId"></assign>
			</input>
		</operation>
		
		<operation>
			<participant name="MIME"/>
				<output message="crackRequest">
					<assign to="mime-document-id/doc:document-id"
from="(string)primaryDocId" append="true"/>
	</output>
	<input message="crackResponse">
		<assign to="decodedDocument" from="mime-document/*" append="true"/>
	</input>
		</operation>
		
	</sequence>
</process>	

The following example contains an XML representation of the decoded MIME document in process data after the business process has run.

<decodedDocument> 
   <mime:message xmlns:mime="http://www.company.com/company-name/mime/v0.5"> 
       <mime:header name="content-type">multipart/form-data
          <mime:parameter name="boundary">servername::5f6303:fb4edbb774:-5a60:
          :multipart.boundary.string</mime:parameter> 
       </mime:header> 
        <mime:header name="content-length">19757</mime:header> 
          <mime:body> 
            <mime:message> 
              <mime:header name="content-id">111</mime:header> 
              <mime:header name="content-type">application/edi-x12</mime:header> 
                <mime:body> 
                  <doc:document-id xmlns:doc="http://www.company.com/
                     company-name/document-id">servername:5f6303:fb4edbb774:-5a42
                  </doc:document-id> 
                </mime:body> 
              </mime:message> 
              <mime:message> 
                <mime:header name="content-id">112</mime:header> 
                <mime:header name="content-type">text/xml</mime:header> 
                  <mime:body> 
                    <doc:document-id xmlns:doc="http://www.company.com/company-name/
                      document-id">servername:5f6303:fb4edbb774:-5a40
                    </doc:document-id> 
                  </mime:body> 
              </mime:message> 
          </mime:body> 
   </mime:message> 
</decodedDocument>

The following example illustrates the business process in the GPM:

MIME service BPML

Extracting the MIME Service Decoded Documents

The following example illustrates how you can extract the documents that have been decoded by the MIME Service. This business process loops through all the documents that have been decoded by the MIME service and renames them to Document1 and Document2. The XML representation of the decoded MIME document in process data is input to this business process.

Document extraction with MIME service
The code snippet from the above example is given below:
<process name="ExtractDocumentsFromMIME">
	<rule name="hasMoreDocuments">
		<conditions> count(decodeDocument/mime:message/mime:body/mime:message) > 0 </
conditions>
	</rule>
	<sequence>
<assign to="index" from="'0'" />
		<choice name="GetDocuments">
			</select>
			<sequence name="ProcessDocuments">
				<assign to="index" from="index + 1" />
				<operation>
					<participant name="This"/>
						<output message="takeDocumentRequest">
							<assign to="." from="*"/>
							<assign to="documentKey" from="concat{'Document', index/text()}" />
							assign to="documentId"
								from="decodeDocument/mime:message/mime:body/mime:message[1]/mime:body/doc:document-id/text()"/>
							</output>
							<input message="takeDocumentResponse">
								<assign to="." from="*"/>
							</input>
				</operation>
				<operation>
					<participant nae="ReleaseService"/>
						<output message="releaseRequest">
							<assign to="TARGET" from="'decodeDocument/mime:message/mime:body/mime:message[1]'"/>
						</output>
						<input message="releaseResponse"/>
				</operation>
				<repeat ref="GetDocuments"/>
			</sequence>
		</choice>
	</sequence>
</process>