on 07-29-2015 12:43 PM
Hi All,
My requirement is to get the hostname,port,username details as a receiver module parameters.Filename and directory details should come from the source payload..Adapter module should place the file in the remote server location which is windows SMB fileshare.I am new to ebj.Please help to achieve this requirement.
Regards,
Karthiga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Hareesh,
I have developed the ejb code,based on sample blog which you have provided.
Could you please check the below code whether it is correct or not.I am using PI 7.11 server and NWDS 7.2 version.
package com.sap.pi.com;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.util.Vector;
import javax.ejb.CreateException;
import javax.ejb.Local;
import javax.ejb.LocalHome;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
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.Payload;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccess;
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;
import com.sap.engine.interfaces.messaging.api.exception.MessagingException;
public class FileModule implements SessionBean, Module {
private SessionContext myContext;
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
myContext = context;
}
public void ejbCreate() throws javax.ejb.CreateException {
}
public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)
throws ModuleException
{
Message msg = null;
String hostname = null;
String port = null;
String username = null;
String password = null;
String filename = null;
String directory = null;
// String FileKey = null;
try
{
msg = (Message)inputModuleData.getPrincipalData();
MessageKey amk = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
PublicAPIAccess pa;
try
{
pa = PublicAPIAccessFactory.getPublicAPIAccess();
}
catch (MessagingException me)
{
throw new ModuleException("Internal SAP PI 7.11 Error -> Accessing PublicAPIAccessFactory Failed!");
}
AuditAccess audit = pa.getAuditAccess();
audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"ReadFiles: MODULE called");
//Reading file name from message header
MessagePropertyKey msgFileName = new MessagePropertyKey("FileName", "http://sap.com/xi/XI/System/File");
//Reading file directory from message header
MessagePropertyKey msgDirectory = new MessagePropertyKey("Directory", "http://sap.com/xi/XI/System/File");
//Read Trigger File Name
filename = msg.getMessageProperty(msgFileName);
directory = msg.getMessageProperty(msgDirectory);
audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"Trigger File Name -> " + filename);
hostname = moduleContext.getContextData("hostname");
port = moduleContext.getContextData("port");
username = moduleContext.getContextData("username");
password = moduleContext.getContextData("password");
// Get PI Main Payload
Payload xiMsgPayload = msg.getDocument();
byte[] inpbyt = xiMsgPayload.getContent();
audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Input file read successfully");
String path="smb://"+hostname+directory+filename;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(hostname,username, password);
SmbFile smbFile = new SmbFile(path,auth);
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
smbfos.write(inpbyt);
audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"File placed successfully");
xiMsgPayload.setContent(inpbyt);
inputModuleData.setPrincipalData(msg);
audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Principle data is set successfully.");
}
catch (Exception e)
{
Message currentMsg = (Message) inputModuleData.getPrincipalData();
MessageKey mk = new MessageKey(currentMsg.getMessageId(), currentMsg.getMessageDirection());
ModuleException me = new ModuleException(new MessagingException(mk, e.getMessage()));
throw me;
}
return inputModuleData;
}
}
Regards,
Karthiga
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
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.