Skip to Content

Hi All,

I once had a similar requirement as mentioned in Renaming Email Attachment with input File Name by madhav poosarla .

Here is the requirement:

Pick a CSV file from FTP location and mail it to external team without any changes to the content and file name. Subject of the mail should be based on the input file name. Also, in the body of the mail mention the directory where the file is archived once it is picked by PI.

I was able to achieve this without module and I would like to discuss how.

Sender File Channel Configurations:

CSV file has to be picked from a FTP Location and has to be archived. ASMA parameters have to be checked.

/wp-content/uploads/2014/09/1_549311.png

In the message mapping, I had a dummy message type as the source and mail package as the target. No graphical mapping has been done. Everything is handled by the Java Code.

This Java Code is written in Attributes and Methods in the Functions tab.

/wp-content/uploads/2014/09/1_549311.png

Four Parameters From_id, To_id1, To_id1 and Directory are defined in the Operation Mapping.

Initially, we declared only one To_id. Later, we realized that we cannot mention more than 99 characters in the ICO for a parameter. We were unable to see the characters after 99th character in the payload.

Issue with parameterized mapping using ICO

Below is the Java Code:


public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
String inputPayload = convertInputStreamToString(arg0.getInputPayload().getInputStream()); // Calls convertInputStreamToString function
Map mapParameters = (Map) arg0.getInputHeader().getAll();
String Directory =  arg0.getInputParameters().getString("Directory"); // Assigns value of 'Directory' - Parameterized mapping
String From =  arg0.getInputParameters().getString("From_id"); // Assigns value of 'From_id' - Parameterized mapping
String To1 =  arg0.getInputParameters().getString("To_id_1"); // Assigns value of 'To_id' - Parameterized mapping
String To2 =  arg0.getInputParameters().getString("To_id_2"); // Assigns value of 'To_id' - Parameterized mapping
String newSubject="";
/*<<<Dynamic File Name Configuration>>>*/
DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey  KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String SourceFileName = conf.get(KEY_FILENAME); // Assigns file name to String SourceFileName
if(SourceFileName.contains(".ABC"))
newSubject= "ABC File is received";
else  if(SourceFileName.contains(".EFG"))
newSubject= "EFG File is received";
else  if(SourceFileName.contains(".HIJ"))
newSubject= "HIJ File is received";
/* <<< Output payload structure>>>*/
String outputPayload = "";
outputPayload = outputPayload .concat("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").concat("\r\n");
outputPayload = outputPayload .concat("<ns1:Mail xmlns:ns1=\"http://sap.com/xi/XI/Mail/30\"><Subject>").concat(newSubject).concat("</Subject><From>").concat(From).concat("</From><To>").concat(To1).concat(To2).concat("</To><Content_Type>multipart/mixed;boundary = --AaZz</Content_Type><Content>----AaZz");
outputPayload = outputPayload .concat("\r\nContent-Type: text/plain; charset=UTF-8").concat("\r\n");
outputPayload = outputPayload .concat("Content-Disposition: inline").concat("\r\n").concat("\r\n");
outputPayload = outputPayload .concat(Directory+SourceFileName+" is attached.").concat("\r\n");
outputPayload = outputPayload .concat("----AaZz").concat("\r\n");
outputPayload = outputPayload .concat("Content-Type: application/xml; name="+SourceFileName).concat("\r\n");
outputPayload = outputPayload .concat("Content-Disposition: attachment; filename="+SourceFileName).concat("\r\n").concat("\r\n").concat(inputPayload).concat("\r\n");
outputPayload = outputPayload .concat("</Content></ns1:Mail>");
try {
/*
* Output payload is returned using the TransformationOutput class          
* arg1.getOutputPayload().getOutputStream(
*/
arg1.getOutputPayload().getOutputStream().write(outputPayload.getBytes("UTF-8"));
} catch (Exception exception1) {
getTrace().addWarning("Exception caught in Transform: " + exception1.toString());
}
}
/* <<< Reads input payload>>>*/
public String convertInputStreamToString(InputStream in) {
StringBuffer sb = new StringBuffer();
try {
InputStreamReader isr = new InputStreamReader(in);
Reader reader = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
sb.append((char) ch);
}
reader.close();
} catch (Exception exception) {
getTrace().addWarning("Exception caught in convertInputStreamToString: "+ exception.toString());
}
return sb.toString();
}


Receiver Mail Channel Configurations:

/wp-content/uploads/2014/09/1_549311.png

ASMA parameters were checked.

/wp-content/uploads/2014/09/1_549311.png

Integrated Configuration:

In the inbound processing tab, SWCV of sender interface is not selected. If it is selected we were getting content not allowed in prolog error.

/wp-content/uploads/2014/09/1_549311.png

Archive Directory, From ID and To IDs are mentioned in the Receiver Interfaces tab.

/wp-content/uploads/2014/09/1_549311.png

And that’s all.. CSV file was picked from FTP and was archived using File Channel. Mail was sent with as-is attachment. No changes to the filename or the content in the file. Archive directory was mentioned in the body of the E-mail.

To report this post you need to login first.