Hi Eperts,
I have written this piece of code to create an output attachment in Message Mapping (not UDF), see screen. It's running fine in Message mapping. But it is getting failed in Operation mapping. See the reults and sample code below.
Message mapping Result:
DN File Attached
Operation Mapping Result:
outAtt is null
Error in Operation mapping:
com.sap.aii.mapping.api.StreamTransformationException: while trying to invoke the method com.sap.aii.mapping.api.OutputAttachments.create(java.lang.String, byte[]) of a null object loaded
Code:
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {try{
OutputStream os = out.getOutputPayload().getOutputStream();
//creating output attachment
OutputAttachments outAtt = out.getOutputAttachments();
if (outAtt==null)
getTrace().addInfo("outAtt is null");//File Names
String dnFileName="001DN.txt";
String CRLF = "\r\n";
String df="test attachment";
// Forming attachment for DN file
Attachment attDN = outAtt.create(dnFileName, df.getBytes());
if (attDN!=null)
{
outAtt.setAttachment(attDN);
getTrace().addInfo("DN File Attached");
}
else
getTrace().addInfo("DN File NOT Attached");
// forming Email Package
String emailPackage=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+CRLF+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"+CRLF+ "<Subject>Delivery notes of CORUS</Subject>"+CRLF+ "<From>test.com</From>"+CRLF+ "<To>test.com</To>"+CRLF+ "<Reply_To />"+CRLF+ "<Content_Type>text/plain</Content_Type>"+CRLF+ "<Content></Content>"+CRLF+ "</ns:Mail>";
// writing Email Package
getTrace().addInfo("Writing Email Package");
os.write(emailPackage.getBytes());
os.flush();
os.close();
}
catch (Exception e)
{
throw new StreamTransformationException(e.getMessage());
}
}Can someone explain to me, why it's happening. Why outAtt is not null in Message mapping and null in Operation Mapping?