cancel
Showing results for 
Search instead for 
Did you mean: 

Unzip the file from FTP and need to send same file name with .xml Extension

former_member308595
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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


former_member308595
Participant
0 Kudos

Hi Anupam  ,

Thanks for sharing your inputs.

My Scenario is File PassThrough  Scenario , I will try module configuration , and get back to you . 

former_member308595
Participant
0 Kudos

Hi Anupam,

If I want to use this DynamicAttributeChangeBean I am having few concerns .

(1) Is it DynamicAttributeChangeBean is standard module configuration or Cutom ?

(2) If custom how we can use ?

Thanks in advance.

Thanks,

Shiva

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

             

1) (1) Is it DynamicAttributeChangeBean is standard module configuration or Cutom ?

ans) custom

2) If custom how we can use ?

ans) download ear file from this blog

deploy the same in PI server.

Regards

Anupam

former_member308595
Participant
0 Kudos

Hi Anupam,

Can you help exactly how to start the process?? for me it's first time implementing Custom Module configuration.

Thanks,

Shiva

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

              Follow this blog to deploy Adapter module

or you can send the ear file to basis team to deploy the same in server.

Regards

Anupam

former_member308595
Participant
0 Kudos

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 .

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

               Compile the code and export the same in a jar file.

Please follow this blog step by step. Let me know in case of issues.

Regards

Anupam

former_member308595
Participant
0 Kudos

Hi Anupam ,

Tried the same process , but no use . getting same issue. or can you share the exported Jar file for this , i will try to import into PI.

Thanks ,

Shiva

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

              Please rename the attached file to javamapping.jar.

Then upoload the file in Imported archive. Then in Operation mapping include the .class file.

Save and activate.

Regards

Anupam

former_member308595
Participant
0 Kudos

Hi Anupam,

Thanks for sharing the jar file , now able to see the Imported Archive file in Operation Mapping .

But in monitoring i am getting below mentioned error log. Can you  look into that why it is getting

Thanks,

Shiva

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

              Please provide the complete error you are getting. Secondly please confirm if you have ticked on ASMA filename in sender communication channel.

Regards

Anupam

former_member308595
Participant
0 Kudos

Hi Anupam,

Thanks finally it's working..

I have one more different requirement , in PI where message logs are storing (in backend).Can we send these message logs information to ECC system .

Thanks in advance.

Thanks

Shiva

anupam_ghosh2
Active Contributor
0 Kudos

Hi Shiva,

               Messages are stored in tables in PI DB.

Can you please open a new thread in this regard so that forum members may help you on this issue.

Regards

Anupam

former_member308595
Participant
0 Kudos

Thanks I will do it..

Answers (0)