I just share my experience which I got while doing the development to send the payload (Text file) as attachment with SMTP adapter at the receiver communication channel.
This blog explains how the XML to plain text file conversion and attachment name change can be achieved.
The main part explained here is, XML to flat file conversion and payload name change. Please note that this document explains only about the important configurations.
Prerequisites:
- Developer should have basic knowledge on PI ESR and ID developments.
- Should have the mail package schema downloaded (if mail package is used for the development)
Here two concepts are explained in this blog
- Without mail package type
- With mail package type
CONCEPT(A): Without Mail Package Type (Target structure can be any type or compatible type for content conversion)
(Concept: A1). Static Naming for the File (File Conversion using Modules/Beans):
Below is the channel parameters to get the file name “NGC.txt”.
Select the “Keep attachments” check box in the receiver communication channel.
Below are the module tab parameters:
1 AF_Modules/StrictXml2PlainBean Local Enterprise Bean 0
2 AF_Modules/PayloadSwapBean Local Enterprise Bean 1
3 AF_Modules/MessageTransformBean Local Enterprise Bean 2
4 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local Enterprise Bean mail
0 Data.fieldSeparator ^
0 Header.fieldSeparator ^
0 Trailer.fieldSeparator ^
0 recordTypes Header,Data,Trailer
1 swap.keyName payload-name
1 swap.keyValue MainDocument
2 Transform.ContentDescription NGC
2 Transform.ContentDisposition attachment;filename=NGC.txt
2 Transform.ContentType text/plain
Variables Transport Binding: (Mime type related setting)
XHeaderName1 : Content-Type
XHeaderName2 : Content-Description
XHeaderName3 : Content-Disposition
Additional Parameters:
OMail.AddContentDisposition false
OMail.AddContentDescription false
OMail.AddContentType false
(Concept: A2) Dynamic File Names:
Usually, file name can be changed using java Code (UDF) with dynamic configuration related API or logic. This file name change works only if we don’t use content conversion.
Note: If we combine dynamic configuration UDF and content conversion modules in the CC, dynamic text file name is not working (File name will be always MainDocument).
Create the below UDF and assign it to root node of target structure (in Message Mapping):
public String setFilename(String strPrefix, String strSuffixDateFormat, String strFileExtension, Container container) throws StreamTransformationException
{
MappingTrace objTrace = container.getTrace();
DynamicConfiguration objDynConfig;
DynamicConfigurationKey objDCKey;
final String NAMESPACE = "http://sap.com/xi/XI/System/Mail";
final String ATTRIBUTE3 = "XHeaderName3"; //ContentDisposition
final String ATTRIBUTE1 = "XHeaderName1"; //ContentType
final String ATTRIBUTE2 = "XHeaderName2"; //ContentDescription
Date objDate = new Date();
String strFomatedDate = "";
String strFileName = "";
SimpleDateFormat objSDF = new SimpleDateFormat(strSuffixDateFormat);
try
{
objDynConfig = (DynamicConfiguration) container.getTransformationParameters().
get(StreamTransformationConstants.DYNAMIC_CONFIGURATION );
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE3);
//get the current date and time for file name
strFomatedDate = objSDF.format(objDate);
//setting the file name dynamically
strFileName = strPrefix + strFomatedDate + strFileExtension;
strFileName = "attachment; filename=" + strFileName;
objTrace.addWarning(strFileName);
objDynConfig.put(objDCKey, strFileName);
strFileName = "text/plain;";
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE1);
objTrace.addWarning(strFileName);
objDynConfig.put(objDCKey, strFileName);
strFileName = "NGC";
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE2);
objTrace.addWarning(strFileName);
- objDynConfig.put(objDCKey, strFileName);
- container.setParameter(StreamTransformationConstants.DYNAMIC_CONFIGURATION, objDynConfig);
}
catch (Exception objException)
{
objTrace.addWarning( objException.getMessage() );
}
return "";
}
Configure the Receiver channel parameters are as below to enable adapter specific settings:
Select the “Keep attachments” check box in the receiver communication channel.
Module tab parameters:
1 AF_Modules/StrictXml2PlainBean Local Enterprise Bean 0
2 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local Enterprise Bean mail
0 Data.fieldSeparator ^
0 Header.fieldSeparator ^
0 Trailer.fieldSeparator ^
0 recordTypes Header,Data,Trailer
Additional Parameters:
- OMail.AddContentDisposition false
- OMail.AddContentDescription false
- OMail.AddContentType false
So, I would suggest to go for CONCEPT (B) if dynamic file name and content conversion needs to be applied same time...
CONCEPT (B): Target structure should be MAIL package:
Use the mail package external definition file as the target message type (Attached in this blog).
Create an UDF and assign it to target structure (in Message Mapping):
public String setFilename(String strPrefix, String strSuffixDateFormat, String strFileExtension, Container container) throws StreamTransformationException
{
MappingTrace objTrace = container.getTrace();
DynamicConfiguration objDynConfig;
DynamicConfigurationKey objDCKey;
final String NAMESPACE = "http://sap.com/xi/XI/System/Mail";
final String ATTRIBUTE3 = "XHeaderName3"; //ContentDisposition
final String ATTRIBUTE1 = "XHeaderName1"; //ContentType
final String ATTRIBUTE2 = "XHeaderName2"; //ContentDescription
Date objDate = new Date();
String strFomatedDate = "";
String strFileName = "";
SimpleDateFormat objSDF = new SimpleDateFormat(strSuffixDateFormat);
try
{
objDynConfig = (DynamicConfiguration) container.getTransformationParameters().
get(StreamTransformationConstants.DYNAMIC_CONFIGURATION );
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE3);
//get the current date and time for file name
strFomatedDate = objSDF.format(objDate);
//setting the file name dynamically
strFileName = strPrefix + strFomatedDate + strFileExtension;
strFileName = "attachment; filename=" + strFileName;
objTrace.addWarning(strFileName);
objDynConfig.put(objDCKey, strFileName);
strFileName = "text/plain;";
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE1);
objTrace.addWarning(strFileName);
objDynConfig.put(objDCKey, strFileName);
strFileName = "NGC";
objDCKey = DynamicConfigurationKey.create(NAMESPACE, ATTRIBUTE2);
objTrace.addWarning(strFileName);
- objDynConfig.put(objDCKey, strFileName);
- container.setParameter(StreamTransformationConstants.DYNAMIC_CONFIGURATION, objDynConfig);
}
catch (Exception objException)
{
objTrace.addWarning( objException.getMessage() );
}
return "";
}
Assign the file name UDF on the root node of target message (in Message Mapping):
Here, prepare the flat file records and assign fill it to content fled of message (separated with the character ‘\n’ for the new line).
Configure the Receiver channel parameters are as below to enable adapter specific settings:
Select the “Use Mail Package” and “Keep attachments” check boxes in the receiver communication channel.
Variables Transport Binding: (Mime type related setting)
XHeaderName1 : Content-Type
XHeaderName2 : Content-Description
XHeaderName3 : Content-Disposition
Additional Parameters
OMail.AddContentDisposition false
OMail.AddContentDescription false
OMail.AddContentType false