cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in JavaMapping

Former Member
0 Kudos


HI All,

I have a FILE-->PI----->SOAP scenario where I need to pick the file and send it as an attachment to soap.

We are working on SAP 7.0 version.

we have javamapping for this , but as per my knowledge I guess 7.0 dosen't support Abstract transformation we need to implement streamtransformation.

below is java mapping with Abstract transformation.

import com.sap.aii.mapping.api.*; 

import com.sap.aii.mapping.api.Attachment;

import java.io.*;

public class JM_Attachment extends AbstractTransformation  

{  

private MappingTrace trace;  

private static final DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");  

public void transform(TransformationInput in, TransformationOutput out)throws StreamTransformationException  

{  

trace = getTrace();  

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out.getOutputPayload().getOutputStream()));  

StringBuffer sb = new StringBuffer();  

DynamicConfiguration conf = in.getDynamicConfiguration();  

String filename1 = conf.get(KEY_FILENAME);  

InputStream ins = in.getInputPayload().getInputStream();

sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");  

sb.append("<ns0:VendorDetails xmlns:Cobranzas\">\r\n");  

try {  

byte[] bt = new byte[ins.available()];

ins.read(bt);

OutputAttachments outAttach = out.getOutputAttachments();

Attachment attOut = outAttach.create(filename1, "text/plain", bt);

outAttach.setAttachment(attOut);

   }

catch (IOException e)

trace.addWarning(e.getMessage());  

}  

sb.append("<FileName>" + filename1 + "</FileName>\r\n");

sb.append("</ns0:VendorDetails>\r\n");  

try{  

   bw.write(sb.toString());  

   bw.close(); 

   }

   catch (IOException e)

{  

                    trace.addWarning(e.getMessage());  

}  

}  

can some one help me how to transfer this to stream transformation.

Accepted Solutions (0)

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Balaji,

As Mark Dihiansan said, Attachments can not be accessed using Java Mapping in PI 7.0.

Please change design of interface, like having a tigger file and attachment file in source folder OR request target system to handle main payload (instead of attachment).

FYI.

http://help.sap.com/javadocs/NW04S/current/pi/index.html (no Attachment class - PI7.0)

http://help.sap.com/javadocs/pi/SP3/xpi/index.html  (Attachment  class is present -  PI7.1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Balaji,

As far as I know, the attachments API which can be called via UDF/Java mapping is only supported from PI 7.1 and above. For PI 7.0 and below, you have to use adapter modules. PayloadSwapBean could help but you need two files and should be NFS.

Regards,

Mark