Pick Up The Files From Dynamic Directory Using Sender File Adapter
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.
Hello Praveen,
I'm trying your approach but I need to create dynamic target directories. Is this possible with the File Adapter?
Best,
Suphi
Hi Preaveen,
I am facing exactly same the problem need to be resolved. Thanks for your post so much! But in theĀ sender directory you only put http://usr/sap/intf/test/FileData/Out/, and file is *. And actually in this folder contains subfolder is 18102016. Then how in runtime it understands the file is /18102016/File1.txt? Normally Sender channel looking file in parent folder, if there is not any file, it doesn't looking in child folder right?
Thanks you so much!
Long.