Skip to Content

Output Attachment is null in Operation Mapping only while working fine in Message Mapping

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?

ESRJM.png (23.0 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 15, 2015 at 01:46 PM

    Ambuj,

    Please set "Read Attachments" in operation mapping and follow below code

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.