on 08-29-2016 10:58 AM
Hi ,
I am having one requirement : in FTP server I am having 3 directories with 3 file names :
Directory1 : PO_Server01_001*.zip (File Name to be pick)
Directory2: PO_server02_002*.zip (File Name to be pick)
Directory3: PO_server03_003*.zip (File Name to be pick)
I need to select the files from these directories and unzip the files , for this I used option Advanced selection for source file to pick the files from different directories , to unzip the files I used Module configuration (Payloadzip )it's working fine,
Here my issue I need to send same file name to the target system for this I used ASMA option in both Channels (Sender and Receiver) .
In target system I am seeing file names as : PO_Server01_001111.zip , PO_server02_002222.zip , PO_server03_003333.zip , Here I don't want file extension as .ZIP . The file name should be .xml (like PO_Server01_001111.xml)
Note: Files in FTP server are dynamic .
Thanks in advance.
Thanks,
Shiva
Hi Shiva,
Either you need adapter module or java mapping to resolve the issue.
If you plan to use adapter module please check this blog http://scn.sap.com/docs/DOC-61728
If you want to create java mapping please use following approach
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(".zip", ".xml");
newFileName = oldFileName ; // 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) In 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.
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 Anupam ,
I am trying to implement based on your Java code. and followed the mentioned steps .
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 in
But in Operation mapping I didn't find any java class , which I imported java file as Java_Mapping.jar .
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.