Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182412
Active Contributor
0 Kudos

Introduction


The requirement is to pick the files from dynamic directory using sender file adapter as mentioned in below question
Move Folders containing multiple file with File adapter

I want to show how we can implement this in PI/PRO.


Design


Create the data type like below, it can be any data type because the file is non XML.



Create a message type and refer the above data type and create the below service interfaces. One is sender side receive the file, one is to send the file to the receiver.



Since file is non XML so select the interface pattern to Stateless (XI30-Compatible) forSenderData_Out service interface then we no need to remove the software component in ICO.



Create below java mapping to set the file name and directory using dynamic configuration.
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.InputPayload;
import com.sap.aii.mapping.api.OutputPayload;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import org.apache.commons.io.IOUtils;

public class SetFileNameDirectoryJavaMap
extends AbstractTransformation
{
private static final String NAMESPACE = "http://sap.com/xi/XI/System/File";

public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException
{
try
{
DynamicConfiguration dynConfig = transformationInput.getDynamicConfiguration();
DynamicConfigurationKey FILE_NAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
String fileName = dynConfig.get(FILE_NAME);
String[] parts = fileName.split("/");
dynConfig.put(FILE_NAME, parts[1]);
dynConfig.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory"), "/usr/sap/intf/test/FileData/In/" + parts[0]);
IOUtils.copy(transformationInput.getInputPayload().getInputStream(), transformationOutput.getOutputPayload()
.getOutputStream());
}
catch (Exception e)
{
throw new StreamTransformationException(e.getMessage());
}
}
}

Create imported archive and import the above java mapping.



I am using IOUtils class from commons IO, so you need to import this jar in common software component then create the dependency for your original software component then this jar will be available.





Configuration


Create the below IFLOW in NWDS.



 

Configure the sender channel like below,



Enable FileName under adapter specific message attributes.



Maintain below values in FileName and Directory in receiver file channel.



Enable FileName and Directory under adapter specific message attributes.



Testing


Files are placed in the source directory.


The file name comes with folder and the file name, The file successfully written to the dynamic target directory with source file name.


The folder and files are placed in the target FTP server.
2 Comments
Labels in this area