I was having a requirement to pick a PDF file from a file server, send it as attachment and PDF file name as field to the target server.

As a solution I created a JAVA code and used it as JAVA mapping in PI. I hope this code will help PI consultants if they have similar kind of requirement.


* Created on May 14, 2015


* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and Comments


package attach;


* @author ashutosh upadhyay


* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments


import java.io.InputStream;

import java.io.OutputStream;

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

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

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

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

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

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

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

public class AddAttachment extends AbstractTransformation{

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

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) {


  // access dynamic configuration

  InputStream inputstream = transformationInput.getInputPayload().getInputStream();

  OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

  DynamicConfiguration conf = transformationInput.getDynamicConfiguration();

  String fileName = “”;

   fileName = conf.get(KEY_FILENAME);


  // set file name

  conf.put(KEY_FILENAME, fileName);

  try {

  // a) Populate XML for XIPAYLOAD

  String fresult= “”;

  // creating the xml

  fresult=”<?xml version=\”1.0\” encoding=\”UTF-8\”?>”;

  fresult = fresult.concat(“<ns0:MT_Payload xmlns:ns0=\”http://test\”>”);

  fresult = fresult.concat(“<FileName>”);

  fresult = fresult.concat(fileName);

  fresult = fresult.concat(“</FileName>”);

  fresult = fresult.concat(“</ns0:MT_Payload>”);


// Write attachment

  OutputAttachments outputAttachments = transformationOutput.getOutputAttachments();

  byte[] b = new byte[inputstream.available()];


  Attachment newAttachment = outputAttachments.create(fileName,”application/pdf”, b);



  catch (Exception e) {








To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply