Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member187339
Active Contributor
0 Kudos

Have you ever encountered a situation where you need to zip multiple files and creating a single zipped file in the target directory? The first approach that wouls have come across will be to use the option of additional files present in the File Sender Adapter. But pretty soon you would have realized its major drawback. (File adapter only allows to pick additional files which has a part different in them.) So the next approach, have you heard about the OS Commands and PayloadZipBean and wondered how powerful the module is?  In this blog I which will update you the design approaches which can be used in these types of situations.  

Scenario I

To zip multiple files (with different name and extensions) and to create a single target zipped file.  

Approach

Use the following OS Commands: cmd /C "jar cvfM \\machine-name\foldername\zippedfolder\test.zip -C \\machine-name\foldername\files2zip ." 

  1. Files which need to be zipped is kept in location : \\machine-name\foldername\files2zip
  2. Zipped file will be created in location \\machine-name\foldername\zippedfolder\zip and will have name test.zip.

 Additionally the files that are zipped now needs to be deleted, which can be done through the command cmd /C "DEL /Q "\\machine-name\foldername\files2zip \*.*"" This approach can be used for zipping multiple files and keeping the zipped file in a particular directory. 

Scenario II

There are multiple files available in a directory which needs to be zipped into a single zipped file. But the catch here is it is also having a XML file which first needs to be transformed and the transformed (output) file should be kept in the zipped file with the same name a the source xml file 

Approach

 

Start with the approach as mentioned in Scenario I.  Once all the files are zipped and kept in a folder, use a file adapter to pick the zipped file with the following modules and key.

 

 

The PayloadZipBean will unzip the contents of the zipped folder in SAP PI and the PayloadSwapBean will swap the current payload with a payload of type application/xml. Once the files are unzipped in PI, the current payload is taken randomly, we need to swap this payload with an xmlized payload (else our message mapping step will fail). In order to achieve PayloadSwapBean should be mandatorily used after PayloadZipBean. And finally which writing the file in target directory we need to use a file adapter with the payload zip bean with mode = zipAll;

 

 

Finally I will mention the advantages and disadvantages of this method.

Advantages:

  1. Functionality can be achieved by using OS Commands and Standard Modules
  2. Development/testing time for customized modules can be avoided

Disadvantages:

  1. You are first zipping and then unzipping the entire payload in PI, this could have been avoided by using a customized module which will pick only the required xml file and make it as the primary payload.
  2. The set of source files which need to be zipped should have only one xml file.
9 Comments