on 01-14-2014 3:26 AM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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 {
}
}
hi Ninad,
find . -name '*.txt.*' -print -exec zip '{}'.zip '{}' \; -exec mv '{}'.zip '{}' \;
Hope this helps.
thanks and regards,
Praveen T
This is solved by adapter module given in stefan' s blog
Thanks
Ninad Sane
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.