on 05-15-2015 8:12 AM
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the reply.
I think my code is exactly same as you suggested in that link,
As per your code,
transformationOutput.getOutputAttachments().create("FileAttachment", b);
I will get null exception due to this handler method of OutputAttachment. interface. Because no input attachment is there in my source message.
transformationOutput.getOutputAttachments()
Also read attachment check box is meant to read input attachment, in my case it's null. I had already tried checking that option.
"And it's failing in my operation mapping only. When I am running my message/java mapping, attachment is successful"
By the way I will explore your links/suggestions and award you if it works.
Thanks again!.
Ambuj,
Ideally attachment should be created, with both codes. You can try below code in tranform method
transformationOutput.getOutputAttachments().create("FileAttachment", "Something".getBytes());
transformationOutput.getOutputHeader().setContentType("Filename.txt");
transformationOutput.getOutputPayload().getOutputStream().write("Something else"".getBytes());
Message was edited by: Raghu Vamseedhar Reddy KadipiReddy
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.