Hi All,
Below is the JAVA code for Adapter Module which I wrote for setting target directory based on source directory information. The requirement is to read the Folder name where the files are placed and as per that Folder name we need to set the target directo
There are many nice blogs to tell about how to use NWDS for creating modules so not putting that information. Only the code for the Adapter Module I feel will be helpful for PI consultants.
package com.pi.adaptermodule;
import javax.ejb.Stateless;
import java.rmi.RemoteException;
import java.util.Timer;
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.aii.af.service.auditlog.Audit;
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.XMLPayload;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
/**
* Session Bean implementation class DynamicDirectoryBean
*/
@Stateless
public class DynamicDirectoryBean implements DynamicDirectoryBeanRemote, DynamicDirectoryBeanLocal,SessionBean, Module {
/**
* Default constructor.
*/
public DynamicDirectoryBean() {
// TODO Auto-generated constructor stub
}
public ModuleData process(ModuleContext moduleContext,ModuleData inputModuleData)throws ModuleException {
Object obj = null;
Message msg = null;
MessageKey amk = null;
String inputDir = null;
String outputDir = null;
String dirpath1 = moduleContext.getContextData("dirpath1");
String dirpath2 = moduleContext.getContextData("dirpath2");
String dirpath3 = moduleContext.getContextData("dirpath3");
String dirpath4 = moduleContext.getContextData("dirpath4");
String dirpath5 = moduleContext.getContextData("dirpath5");
String dirpath6 = moduleContext.getContextData("dirpath6");
String folderName1 = moduleContext.getContextData("folderName1");
String folderName2 = moduleContext.getContextData("folderName2");
String folderName3 = moduleContext.getContextData("folderName3");
String folderName4 = moduleContext.getContextData("folderName4");
String folderName5 = moduleContext.getContextData("folderName5");
String folderName6 = moduleContext.getContextData("folderName6");
try{
// Retrieves the current principle data, usually the message , Return type is Object
obj = inputModuleData.getPrincipalData();
// A Message is what an application sends or receives when interacting with the Messaging System.
msg = (Message) obj;
// MessageKey consists of a message Id string and the MessageDirection
amk = new MessageKey(msg.getMessageId(),msg.getMessageDirection());
// Audit log message will appear in MDT of Channel Monitoring
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Dynamic Directory Module called");
// Returns the main document as XMLPayload
XMLPayload xpld = msg.getDocument();
//Reading the directory from message header
MessagePropertyKey mpk = new MessagePropertyKey("Directory","http://sap.com/xi/XI/System/File");
inputDir = msg.getMessageProperty(mpk);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "directory is" + inputDir );
if(inputDir.contains(folderName1))
{
outputDir = dirpath1;
}
else if (inputDir.contains(folderName2))
{
outputDir = dirpath2;
}
else if (inputDir.contains(folderName3))
{
outputDir = dirpath3;
}
else if (inputDir.contains(folderName4))
{
outputDir = dirpath4;
}
else if (inputDir.contains(folderName5))
{
outputDir = dirpath5;
}
else if (inputDir.contains(folderName6))
{
outputDir = dirpath6;
}
//setting directory in the message header
MessagePropertyKey dir = new MessagePropertyKey("Directory","http://sap.com/xi/XI/System/File");
msg.setMessageProperty(dir,outputDir);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "target directory is " + outputDir );
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Directory is Successfully set");
// Sets the principle data that represents usually the message to be processed
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Message Successfully updated");
inputModuleData.setPrincipalData(msg);
return inputModuleData;
}
catch (Exception e) {
ModuleException me = new ModuleException(e);
throw me;
}
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext context) throws EJBException,RemoteException {
}
/* (non-Javadoc)
* @see javax.ejb.TimedObject#ejbTimeout(javax.ejb.Timer)
*/
public void ejbTimeout(Timer arg0) {
// TODO Auto-generated method stub
}
public void ejbCreate() throws javax.ejb.CreateException {
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 20 | |
| 20 | |
| 14 | |
| 13 | |
| 13 | |
| 12 | |
| 12 | |
| 11 |