Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9155

Re: Dynamic Directory Module getting null on getMessageProperty

$
0
0

Hello,

For testing purpose use below code + make sure u have enabled Directory attribute (under ASMA)  in sender file channel

 

package com.test;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
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;
/**
 * @author amitsrivastava5
 *
 */
public class TestBean implements SessionBean {    /* (non-Javadoc)     * @see javax.ejb.SessionBean#ejbActivate()     */    @Override    public void ejbActivate() throws EJBException, RemoteException {        // TODO Auto-generated method stub    }    /* (non-Javadoc)     * @see javax.ejb.SessionBean#ejbPassivate()     */    @Override    public void ejbPassivate() throws EJBException, RemoteException {        // TODO Auto-generated method stub    }    /* (non-Javadoc)     * @see javax.ejb.SessionBean#ejbRemove()     */    @Override    public void ejbRemove() throws EJBException, RemoteException {        // TODO Auto-generated method stub    }    /* (non-Javadoc)     * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)     */    @Override    public void setSessionContext(SessionContext arg0) throws EJBException,            RemoteException {        // TODO Auto-generated method stub    }    public void ejbCreate() throws javax.ejb.CreateException {            }    public ModuleData process(ModuleContext mc, ModuleData inputModuleData)       throws ModuleException {           Object obj = null;        Message msg = null;        MessageKey key = null;        String dynamicpath = "";       MessagePropertyKey dirKey = null;       SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");        SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");        SimpleDateFormat sdfDay = new SimpleDateFormat("dd");        String sYear; String sMonth;        String sDay;        try {        // Calculate Day, Month, and Year        Calendar cal = Calendar.getInstance();        sYear = sdfYear.format(cal.getTime());        sMonth = sdfMonth.format(cal.getTime());        sDay = sdfDay.format(cal.getTime());        obj = inputModuleData.getPrincipalData();        msg = (Message) obj;        key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());        dirKey = new MessagePropertyKey("Directory", "http://sap.com/xi/XI/System/File");       // getting Directory from ASMA parameters       dynamicpath = msg.getMessageProperty(dirKey);        Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "input Directory:" + dynamicpath);        Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Year Directory:" + sYear);        Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Month Directory:" + sMonth);        Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Day Directory:" + sDay);    // Returns the main document as XMLPayload.       XMLPayload xpld = msg.getDocument();       byte[] inpbyt = xpld.getContent();       Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "Input file read successfully");        //Archiving target file on FTP server       xpld.setContent(inpbyt);       // Sets the principle data that represents usually the message to be processed       inputModuleData.setPrincipalData(msg);       }catch (Exception e) {       Audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,    "Module Exception caught:");       ModuleException me = new ModuleException(e);       throw me;       }       return inputModuleData;       }       }   

 

Capture.PNG

 

Thanks

Amit Srivastava


Viewing all articles
Browse latest Browse all 9155

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>