Skip to Content
0

Can payloadzip bean used to unzip multiple files

Jan 31, 2017 at 02:29 PM

132

avatar image

Hi Experts ,

We have a requirement to unzip multiple files and place those files to the target directory .

Can we achieve the same using payloadzip bean ?

I could see some threads related to the same question which suggests that it is not possible to unzip multiple files using payloadzip bean . However those threads were very old .

Can someone please advise is there any option in the latest version of SAP PI to unzip multiple files using payloadzip bean ?

I'm aware that the same requirement could be achieved using Shell scripting and java mapping. But these are the last option which I would like to go with .

Thanks in advance .

Nitheesh

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Evgeniy Kolmakov Jan 31, 2017 at 07:42 PM
0

Hi Nitheesh!

Here is the code fragment from PayloadZipBean:

else if (zipmode.equals("unzip")) {
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, "unzipping");
BinaryBufferInputStream binin = new BinaryBufferInputStream(pldbin);
ZipInputStream zin = new ZipInputStream(binin);
byte[] tmpbuf = new byte['?'];
Vector bins = new Vector();
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null) {
if (!entry.isDirectory()) {
String filename = entry.getName();
BinaryBufferOutputStream binout = new BinaryBufferOutputStream();
for (;;) {
int c = zin.read(tmpbuf, 0, tmpbuf.length);
if (c < 0) {
break;
}
binout.write(tmpbuf, 0, c);
}
bins.add(filename);
bins.add(binout.toBinary());
}
}
zin.close();
if (bins.size() > 0) {
String filename = (String)bins.get(0);
setPayload(pld, (Binary)bins.get(1), generateContentType(filename), filename);
String zipStatus = "Zip: unzipped payload";
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, zipStatus);
Audit.addAuditLogEntry(auditkey, AuditLogStatus.SUCCESS, zipStatus);
if (bins.size() >= 2) {
int count = 0;
for (int i = 2; i < bins.size(); i += 2) {
String ifilename = (String)bins.get(i);
XMBPayload ipld = XMBMessageOperator.createPayload();
ipld.setPayloadDescription(ifilename);
ipld.setPayloadType(PayloadType.APPLICATION_ATTACHMENT);
setPayload(ipld, (Binary)bins.get(i + 1), generateContentType(ifilename), ifilename);
XMBMessageOperator.addPayload(mo, ipld); count++;
}
zipStatus = "Zip: unzipped additional " + count + " payloads";
TRACE.infoT("process(ModuleContext , ModuleData)", ModuleCategories.SAP_MODULE_ROOT, zipStatus);
Audit.addAuditLogEntry(auditkey, AuditLogStatus.SUCCESS, zipStatus);
}

}
}

As you can see from this code, it creates attachments for each additional extracted file.

I didn't try extracting multiple files with PayloadZipBean, but you could try it yourself.

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded