Skip to Content
Technical Articles

Handling ZIP files in SAP Cloud Platform Integration

Introduction:

In below blog would like to share how to deal with File Archives ( ZIP ) in SAP Cloud Platform using ZIP Splitter and ZIP Aggregator.

Scenarios:

In following sections will cover scenarios involving SFTP,SOAP and HTTP adapter with ZIP file content in detail.

Unzipping input ZIP file from SFTP to have multiple files at target size keeping same source file name :

Integration Scenario where we will be getting ZIP file SFTP server and need to unzip the file in SAP CPI keeping the same source name of the files using ZIP Splitter step.

Design :

Step 1: Configure your SFTP Sender with Server Name / Source File Path with file to be read.

Step 2: Configure ZIP Splitter to unzip incoming ZIP .

Step 3: Content modifier to parse the incoming file name to keep same file name at the target side.we will be getting file name in camel header CamelFileNameOnly with value ZIPNAME/Filename in order to get only file name we can use below expression.

Value:

${header.CamelFileNameOnly.replaceAll("[0-9A-Za-z]+\/","")}

Step 4: Configure SFTP receiver to get place all the unzipped files and we can use ${property.FName} in receiver SFTP channel to get dynamic file name.

Unzipping input ZIP file from SOAP request to have multiple files at target size keeping same source file name :

Instead of loading zip file from SFTP we will be sending the ZIP file as attachment to SOAP request using SOAP UI.

Design:

All the steps remain same as use case-1 except below highlighted extra step to parse the incoming attachment

Script to parse SOAP attachment:

import com.sap.gateway.ip.core.customdev.util.Message
import java.util.Map
import java.util.Iterator
import javax.activation.DataHandler

def Message processData(Message message) {

   Map<String, DataHandler> attachments = message.getAttachments()
   if (attachments.isEmpty()) {
       message.setBody("No attachment Found")
     return message;
   } else {
      Iterator<DataHandler> it = attachments.values().iterator()
      DataHandler attachment = it.next()
      message.setBody(attachment.getContent())
   }
   return message
}

Unzipping input ZIP file from HTTP request to have multiple files at target size keeping same source file name :

Instead of loading zip file from SFTP we will be sending the ZIP file as attachment to HTTP request ( multipart/form-data ) using POSTMAN

Design:

All the steps remain same as use case-1 except below highlighted extra step to parse the incoming attachment

Add MIME Multipart Decoder to parse the incoming multipart/form-data having ZIP file as attachment.

Creating multiple files in Integration Flow and zipping it using Gather ( ZIP Aggregator ):

We will be creating simple iflow where we will be creating 3 different types of files ( CSV , Text and XML ) and sending as ZIP to target system

Design:

Step 1: Set body containing 3 different types of content inside it.

<Root>
	<file1>
		<Root>
			<Record>
				<Name>Sriprasad1</Name>
				<CompanyName>SAP</CompanyName>
				<EmpID>E1</EmpID>
				<Designation>Consultant</Designation>
			</Record>
			<Record>
				<Name>Sriprasad2</Name>
				<CompanyName>SAP</CompanyName>
				<EmpID>E2</EmpID>
				<Designation>Consultant</Designation>
			</Record>
		</Root>
	</file1>
	<file2>
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	This is sample Text file and it should be saved as TestText.txt in ZIP file.
	</file2>	
	<file3>
	Name,CompanyName,EmpID,Designation
	Sriprasad1,SAP,E1,Consultant
	Sriprasad2,SAP,E2,Consultant
	Sriprasad3,SAP,E3,Consultant
	</file3>
</Root>

Step 2.a:Parallel Multicast branch to get XML content for File1.

Step 2.b: Content filter to get XML  content for File1

/Root/file1

Step 2.c: Content Modifier to set the header for file name.

Step 3.a:Parallel Multicast branch to get text content for File2.

Step 3.b: Content filter to get text content for File2

/Root/file2

Step 3.c: Content Modifier to set the header for file name.

Step 4.a:Parallel Multicast branch to get CSV content for File3.

Step 4.b: Content filter to get CSV content for File3

/Root/file3

Step 4.c: Content Modifier to set the header for file name.

Step 5: Add Join with gather step with belo configuration to gather all the 3 files receiving from multiple branches of Parallel Multicast into Single ZIp file.

Step 6: Configure SFTP receiver to get single Zipped file having 3 different types of files inside it.

Finally deploy the IFlow to received Zip file in target SFTP server.

 

Hope above details helps to handle ZIP files coming from different adapters in SAP CPI.

References:

[1] : SAP CPI Splitter-Aggregator Capability By Mandy Krimmel

[2] : SAP CPI Handling SOAP attachment  By Morten Wittrock

5 Comments
You must be Logged on to comment or reply to a post.