cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member183816
Active Participant
0 Kudos

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?

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor

Ambuj,

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

former_member183816
Active Participant
0 Kudos

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!.

RaghuVamseedhar
Active Contributor
0 Kudos

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

former_member183816
Active Participant
0 Kudos

No, it's not working (Also tried with checking read attachment box)

As I already mentioned, while running in operation mapping this object is null.

FYI.I placed a check on this object in message mapping, there, it is not null.

I will try another aproach as per this blog.

engswee
Active Contributor
0 Kudos

Ambuj

I don't think you can test this out in ESR, that is why you are getting inconsistent behavior. Try testing this in an end-to-end scenario instead.

Rgds

Eng Swee

RaghuVamseedhar
Active Contributor
0 Kudos

Ambuj,

Can you try the normal Java mapping (not ESR java mapping)?

former_member183816
Active Participant
0 Kudos

Already tried that. Same results.

Let me test it end to end as  Eng suggested. Ill share the results.

Answers (0)