cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic file name in creating Zip File

former_member207622
Contributor
0 Kudos

hi Folks ,

I want to create a Zip file at the target . I  am using dynamic configuration in mapping . At run time that same file name should be used to create zip file.

I have used payload Zip bean with zip.mode = zip in receiver channel.

I donot wish to write adapter module for same .

Can anyone help me with Unix command after message processing . so that I can zip the file after creation.?

Any help appreciated

Thanks

Ninad Sane

Accepted Solutions (1)

Accepted Solutions (1)

vkaushik82
Active Participant
0 Kudos

Hi Ninad,

i have similar scenario , just select ASMA and module configuration will be as below

It will work. My case we are creating same file as picked but as u mentioned you will set the file name in mapping. It should work in your case as well.

No need for commands.

Regards,

Vikrant

former_member207622
Contributor
0 Kudos

Hi All , Vikrant ,

Thank you  for your responses

Unfortunately , It only works for static file name and for dynamic file name if I set it in mapping . I am getting the zip file name as expected but not getting the  name of file inside same as zip file name  I am getting as untitled.txt or maindocument.txt

Can anyone throw some light on this adapter module .

Adapter Module PI 7.0 Set Attachment Name - Process Integration - SCN Wiki

How to use this ? parameters to be entered for module key ?

Thanks in anticipation

former_member184720
Active Contributor
0 Kudos

HI Ninad - This thread should address your issue. Have a look at the last 5 replies may be..

former_member207622
Contributor
0 Kudos

Folks

Any other idea how to do this using unix script ?

appreciate your help

Thanks

Ninad Sane

Former Member
0 Kudos

Hi Ninad

Try this module below. This will definitely solve the name problem but since you are using PGP , I am not sure it will handle the data properly or not. But you can give it a try

Code:

package com.sap;

import java.io.BufferedInputStream;

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import java.rmi.RemoteException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

import javax.ejb.CreateException;

import javax.ejb.EJBException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

import com.sap.aii.af.lib.mp.module.Module;

import com.sap.aii.af.lib.mp.module.ModuleContext;

import com.sap.aii.af.lib.mp.module.ModuleData;

import com.sap.aii.af.lib.mp.module.ModuleException;

import com.sap.engine.interfaces.messaging.api.Message;

import com.sap.engine.interfaces.messaging.api.MessageKey;

import com.sap.engine.interfaces.messaging.api.MessagePropertyKey;

import com.sap.engine.interfaces.messaging.api.PublicAPIAccess;

import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;

import com.sap.engine.interfaces.messaging.api.XMLPayload;

import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;

import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;

import com.sap.engine.interfaces.messaging.api.exception.MessagingException;

public class ZipFilesBean implements Module, SessionBean {

  private static final long serialVersionUID = 1L;

  private AuditAccess Audit = null;

  private MessageKey amk = null;

  static final int BUFFER = 1024 * 1000;

  public ModuleData process(ModuleContext moduleContext,

  ModuleData inputModuleData) throws ModuleException {

  Message mes = null;

  XMLPayload xmlData = null;

  mes = (Message) inputModuleData.getPrincipalData();

  xmlData = mes.getDocument();

  int len = 0;

  byte buf[] = new byte[BUFFER];

  // For Audit Log Fetch the Audit Message key from the message.

  amk = new MessageKey(mes.getMessageId(), mes.getMessageDirection());

  PublicAPIAccess pa;

  try {

  pa = PublicAPIAccessFactory.getPublicAPIAccess();

  } catch (MessagingException me) {

  ModuleException e1 = new ModuleException(me);

  throw e1;

  }

  Audit = pa.getAuditAccess();

  Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

  "Entering the GetFileName module");

  try {

  InputStream inStream = xmlData.getInputStream();

  BufferedInputStream bis = new BufferedInputStream(inStream);

  ByteArrayOutputStream myBytes = new ByteArrayOutputStream();

  ZipOutputStream zos = new ZipOutputStream(myBytes);

  MessagePropertyKey mpk = new MessagePropertyKey("FileName",

  "http://sap.com/xi/XI/System/File");

  String FileName = mes.getMessageProperty(mpk);

  String outfile = FileName.replaceAll(".csv", ".zip");

  mes.setMessageProperty(mpk, outfile);

  ZipEntry zipEntry = new ZipEntry(FileName);

  zos.putNextEntry(zipEntry);

  while ((len = bis.read(buf)) > 0) {

  zos.write(buf, 0, len);

  }

  zos.closeEntry();

  zos.close();

  byte[] docContent = myBytes.toByteArray();

  if (docContent != null) {

  xmlData.setContent(docContent);

  inputModuleData.setPrincipalData(mes);

  }

  } catch (Exception e) {

  e.printStackTrace();

  }

  return inputModuleData;

  }

  public void ejbActivate() throws EJBException, RemoteException {

  }

  public void ejbPassivate() throws EJBException, RemoteException {

  }

  public void ejbRemove() throws EJBException, RemoteException {

  }

  public void setSessionContext(SessionContext arg0) throws EJBException,

  RemoteException {

  }

  public void ejbCreate() throws CreateException {

  }

}

praveen_sutra
Active Contributor
0 Kudos

hi Ninad,

find . -name '*.txt.*' -print -exec zip '{}'.zip '{}' \; -exec mv '{}'.zip '{}' \;



shell - Script to create individual zip files for each .txt file it finds and move them after - Stac...


Hope this helps.


thanks and regards,

Praveen T

former_member207622
Contributor
0 Kudos

Thanks Praveen -  Looks good will try and  let you know

Thanks

Ninad Sane

Answers (3)

Answers (3)

former_member207622
Contributor
0 Kudos

This is solved by adapter module given in stefan' s blog

Thanks

Ninad Sane

former_member184720
Active Contributor
0 Kudos

Glad that it worked. May you can also close the thread

praveen_sutra
Active Contributor
0 Kudos

Hi Ninad,

Please try this

zip -m -R name.zip *.csv /same

http://www.computerhope.com/unix/zip.htm

http://scn.sap.com/thread/3450240

hope this helps.

thanks and regards,

Praveen T

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ninad,

                 Difficult to do this using unix command.

If you do not want adapter module, you can achieve the same using java mapping.

The mapping will zip the contents of the file and rename it using dynamic configuration.

check these links

http://www.mkyong.com/java/how-to-compress-files-in-zip-format/

Regards

Anupam

former_member207622
Contributor
0 Kudos

Thanks for your inputs Anupam ,

Actually my file is encrypted first by PGP module at receiver side and then it is required to be zipped with the dynamic file name that is why cannot use java mapping else it will be complex to handle.

Please help with  OS command if possible

Thanks

Ninad Sane