Business requirement is like:
- While triggering SAP-PI’s SOAP web-service from client system, zip attachments will be send along with SOAP Request Payload. Here, please note, one zip per web-service call is in scope.
- This zip attachments has multiple CSV files, which needs to be extracted in SAP’s application directory
- Once unzip is successful, return unzipped zip-File in SOAP-Response Message
To accomplish above business requirements, one Java UDF will be written in Request Message Mapping of SAP-PI’s respective (SOAP-to-File Synchronous Inbound) interface
Here, given example of SAP PI Java UDF (user defined function), has below functionalities:
- To read zip attachment from Request Payload
- Unzip attachment to one SAP application server directory
- Using Dynamic-configuration, return unzipped zip file name
UDF Imports:
-
java.util.zip.* java.io.ByteArrayInputStream
public String UnZip(String upzipPath, Container container) throws StreamTransformationException{ /* UDF to: 1. Get ZipFile Attachment (i.e. get the input attachment from the source message) 2. Unzip/extract ZipFile to SAP-Application directory 3. Set unzipped attachment name to "FileName" variable using 'DynamicConfiguration' */ //File destDir = new File("/folde1/folde2/folde3/"); File destDir = new File(upzipPath); String resultStr = ""; //To add trace info AbstractTrace trace; trace = container.getTrace(); trace.addInfo("UDF to unzip ZipFile atatchment to the directory " + destDir ); //Get the input attachment from the source message) GlobalContainer globalContainer = container.getGlobalContainer(); InputAttachments inputAttachments = globalContainer.getInputAttachments(); try { //checks for the availability of attachments in the input message if(inputAttachments.areAttachmentsAvailable()){ trace.addInfo("Attachments Available"); //Get the attachmentIds and store it in an Object array Collection
New NetWeaver Information at SAP.com
Very Helpfull