on 03-15-2016 7:14 AM
Hello All,
I have a little complex scenario. The sender sends an IDoc and it is converted into a text file. This text file is supposed to have a specified filename along with the timestamp (the file name is to be of the form VT_KKO_*timestamp*.txt. After this file has been created, it has to be zipped and sent to SFTP file server. This zip file also is to have the same filename only the extension should be zip instead of txt.
So, I decided to go ahead with first dynamically naming the file with a udf and then use java mapping to zip this file.
Can anyone provide a simple java code to just take the inbound payload and zip it and pass it along to the receiver adapter. No other operation is to be conducted. All the sample programs I found are doing some additional work like, taking mulitple payloads etc. which is not needed for my requirement.
Kindly help me with this. Also if you have any better idea or solution then, please suggest that as well.
Thanks,
Ajeya G V
Hi Ajeya,
check this link:
Regards,
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ajeya,
Additionally check if Payload Beans can you help out
SAPTechnical.COM - Zipping Files/Payloads using Module PayloadZipBean
Hello Alexander,
Thanks for the reply. The code seems to be very simple. Just for my understand please tell me, what value should be passed for the parameter filename ? The name of the file that PI has to pick up or will PI use that string to name the file that is going to be inside the zip file ?
Hi Ajeya,
u have to use "Adapter-Specific Message Attributes"
here can you pick the attributes your need
Regards,
Alex
Hi Vaani,
You can set the dynamic FileName attribute in the mapping using dynamic configuration UDF. In the receiver file adapter module configuration like below.
The adapter module DynamicContentTypeBean code:
import javax.ejb.CreateException;
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.PublicAPIAccessFactory;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
public class DynamicContentTypeBean implements SessionBean, Module {
private static final long serialVersionUID = 1L;
private SessionContext myContext;
private AuditAccess audit;
@Override
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException {
String CLASS_NAME = getClass().getSimpleName();
try {
Message msg = (Message) inputModuleData.getPrincipalData();
MessageKey key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, CLASS_NAME + ": Module Called");
MessagePropertyKey KEY_FILENAME = new MessagePropertyKey("FileName", "http://sap.com/xi/XI/System/File");
String fileName = msg.getMessageProperty(KEY_FILENAME);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "FileName read successfully. fileName: " + fileName);
fileName = fileName.replace(".zip", ".txt");
String contentType = "text/plain;charset=\"utf-8\";name=\"" + fileName + "\"";
msg.getMainPayload().setContentType(contentType);
audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "ContentType was set to: " + contentType);
} catch (Exception e) {
throw new ModuleException(e.getClass() + ": " + e.getMessage());
}
return inputModuleData;
}
@Override
public void ejbRemove() {
}
@Override
public void ejbActivate() {
}
@Override
public void ejbPassivate() {
}
@Override
public void setSessionContext(SessionContext context) {
setMyContext(context);
}
public void setMyContext(SessionContext myContext) {
this.myContext = myContext;
}
public SessionContext getMyContext() {
return myContext;
}
public void ejbCreate() throws CreateException {
}
}
The created zip file:
Regards,
Praveen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.