on 08-09-2016 11:12 AM
Hello Experts,
I am working on pass through File to SFTP scenario.
My requirement is to perform encryption (using Standard module) and file name should be dynamic adding timestamp.
Source file is in format ABC.TXT and I need to rename the file as ABCyyyyMMdd-HHmmss-SSS.csv.pgp.
I have referred the blog posted by Eng .
But output which I am getting is ABC.csvyyyyMMdd-HHmmss-SSS.pgp.
Please let me know how can I achieve this functionality without using ESR.
Regards,
Hemant Malvi
Hi Hemant,
Please try with following parameters for module key "DACB".
Please do not add time stamp from channel parameter rather add it via adapter module.
parameter name, value
------------------------------------
mode , change
attribute , filename
namespace , http://sap.com/xi/XI/System/File
addTimestamp, Y
oldValue, .TXT
newValue, .csv.pgp
outNamespace, http://sap.com/xi/XI/SFTP/SFTP
timestampFormat, yyyyMMdd-HHmmss-SSS
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hemant,
Can you please change the value of outNameSpace parameter to http://sap.com/xi/XI/System/File.
Regards
Anupam
Hi Hemant,
This is a issue with the module. It is placing the date just before last file extension.
The solution to this is that you use java mapping in your scenario or you can build your own custom adapter module.In case you are going for java mapping then here is the code you can use.
package com.javaMapping;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
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 DynamicFileName_JavaMapping extends AbstractTransformation {
private static final DynamicConfigurationKey KEY_FILENAME =
DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
@Override
public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
// TODO Auto-generated method stub
String newFileName = null;
Date date = new Date(); // get the current date
SimpleDateFormat dateFormatter = new SimpleDateFormat ("yyyyMMdd-HHmmss-SSS"); // set the format for date
String dfmt = dateFormatter.format(date);
DynamicConfiguration conf = in.getDynamicConfiguration();
String oldFileName = conf.get(KEY_FILENAME);
oldFileName = oldFileName.replaceAll(".txt", "");
newFileName = oldFileName + dfmt + ".csv.pgp" ; // the final filename
String inData = convertStreamToString(in.getInputPayload().getInputStream());
String outData = inData;
try {
out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conf.put(KEY_FILENAME,newFileName);
}
public String convertStreamToString(InputStream in){
StringBuffer sb = new StringBuffer();
try
{
InputStreamReader isr = new InputStreamReader(in);
Reader reader =
new BufferedReader(isr);
int ch;
while((ch = in.read()) > -1) {
sb.append((char)ch);}
reader.close();
}
catch(Exception exception) { }
return sb.toString();
}
}
ESR steps
-----------------
1) Create a Data Type
<DT_Structure>
<Data>
</Data>
</DT_Structure>
2) Create a Message Type, MT_Structure and refer DT_Structure.
3) Create an Outbound Service Interface, SI_Structure_Out and refer MT_Structure.
4) Create an Inbound Service Interface, SI_Structure_In and refer MT_Structure.
5) Create an Operational Mapping, OM_Structure. Refer SI_Structure_Out and SI_Structure_In.
6) Create a zip or jar file of below Java Mapping ‘DynamicFileName_JavaMapping’ (compiled). Import it into ESR as imported archive. Refer this Java Mapping in OM_Structure.
ID steps
------------
1) Create a File Sender channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.
2) Create a SFTP Receiver channel. In ‘Advance’ tab, select ‘Use Adapter-Specific Message Attributes’ and ‘File Name’.
3) Create Sender and Receiver Communication Components. Create ‘Integrated Configuration’ Object to run scenario in Advance Adapter Engine
4) When input is non-XML, and you are using ICO. Delete SWCV from ICO object.
5) do not add timestamp from receiver SFTP channel.
The same logic can be applied in custom adapter module if you want to skip ESR objects. Let me know in case you need that code.
Regards
Anupam
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.