cancel
Showing results for 
Search instead for 
Did you mean: 

Java mapping for dynamic file name in sap pi

former_member60331
Participant
0 Kudos
1,919

Hi Experts,

I have requirement to change the input filename from "ABC_zyxinputfile.txt" to "zyxinputfile.txt" in the output.
I am using the java mapping for the same -

Code -

import java.io.InputStream;


import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;


public class FileToSFTP_DynamicFileName extends AbstractTransformation {
	@Override
	 public void transform(TransformationInput in , TransformationOutput out) throws StreamTransformationException {
	  try {
															
	   DynamicConfiguration dc = in.getDynamicConfiguration(); //getting the instance of Dynamic Configuration to access the adapter specific attributes																
	   DynamicConfigurationKey dckey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName"); //creating a Dynamic Configuration key to get the Input File FileName
	   String inFilename = dc.get(dckey);
	   String outFilename = inFilename.split("_")[1];
	   dc.put(dckey,outFilename);
	  } catch (Exception e) {
	   throw new StreamTransformationException("Error in java mapping:" + e.getMessage()); //any exception occured in mapping execution will be captured here
	  }
	 }
}


However, I am getting the below error in the sender file channel -

Channel CC_File_Sender: Empty document found - proceed without sending message

ASMA for filename is activated.

Please suggest if any code changes are required so resolved this error -

Regards,

Akash

View Entire Topic
stefan_grube
Active Contributor
0 Kudos

You need to copy the input payload to the output payload.

Add this code:

            InputStream inputstream = in.getInputPayload().getInputStream();
            OutputStream outputstream = out.getOutputPayload().getOutputStream();
            byte[] b = new byte[inputstream.available()];
            inputstream.read(b);
            outputstream.write(b);