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,925

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor

Hi Akash,

While configuring sender communication channel under Processing Mode, specify what is to happen to files that have been processed successfully.

  1. Under Handling of Empty Files, specify how empty files (length 0 bytes) are to be handled there are three options
    • Do Not Create Message

      No XI messages are created from empty files.

      The files are processed according to the selected processing mode.

      For example, if the processing mode is Delete, empty files are deleted in the source directory.

    • Process Empty Files

      XI messages are created with an empty main payload.

      The files are processed according to the selected processing mode.

    • Skip Empty Files

      No XI messages are created from empty files.

      Empty files are skipped and remain in the source directory.

you need to use "Process Empty files".

Java mapping code seems to be fine.

Regards

Anupam

Answers (1)

Answers (1)

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);