cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Directory Module getting null on getMessageProperty

former_member540174
Participant
0 Kudos

HI - I am testing my custom module and seem to be having trouble retrieving the directory.

On the channel I have populated the filename and directory, checked the Adapterspecific Message-Attributes and checked all there items (Directory included).

I have my module in the Module tab and I see that it is called.

Code is:

Object obj = null;

Message msg = null;

MessageKey key = null;

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);

audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();

//creating object for audit log audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS, "AddYMDFolderToEndOfDirectory: New Module called");

// 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);

Audit Log shows:

10.02.2014 13:46:53.448InformationDay Directory:10
10.02.2014 13:46:53.448InformationMonth Directory:02
10.02.2014 13:46:53.448InformationYear Directory:2014
10.02.2014 13:46:53.448Informationinput Directory:null

What might be causing the directory to be null?  What step did I miss?

Regards,

Diane

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;  

    }  

    }  

Thanks

Amit Srivastava

former_member540174
Participant
0 Kudos

I found three things. One I had forgotten to check the sending adapter ASMA Directory (I'd checked Filename but NOT Directory).  Two my namespace for ASMA was different than the example (http://sap.com/xi/XI/System vs http://sap.com/xi/XI/System/File).  Third I did not have the inputModuleData.setPrincipalData(msg);  

Thank you everyone!

Diane

Answers (2)

Answers (2)

Harish
Active Contributor
0 Kudos

Hi Diane,

I the code which you posted here dynamicpath is not defined any where. Can you check if you defined dynamicpath?

regards,

Harish

former_member184720
Active Contributor
0 Kudos

Hi Diane -

Can you check the code @ http://scn.sap.com/docs/DOC-46112

i see one difference in getting the message property

blog - msg.getMessageProperty("http://sap.com/xi/XI/System/File", "Directory");

your code - MessagePropertyKey("Directory",http://sap.com/xi/XI/System/File);

former_member540174
Participant
0 Kudos

I've been starring at the code from http://scn.sap.com/docs/DOC-46112 all afternoon comparing it to my code (part of it above).  The code you mentioned was my source and I modified it to meet my needs.  The initial call to get the directory is returning null.  Why would it return null?

Diane

former_member184720
Active Contributor
0 Kudos

Try invoking it directly with the below statement

To read :

dynamicpath = msg.getMessageProperty(dirKey);

change it to

dynamicpath  = msg.getMessageProperty("http://sap.com/xi/XI/System/File", "Directory");

To set :

msg.setMessageProperty(dirKey,dynamicpath);

The difference is the way you pass the parameters while using get method i.e. First namespace follwed by Attribute.

Message was edited by: Hareesh Gampa

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Diane,

Please use mpk = new MessagePropertyKey("Directory","http://sap.com/xi/XI/System/File");

instead of mpk = new MessagePropertyKey("Directory",http://sap.com/xi/XI/System/File);

The msg.getMessageProperty(String arg0, String arg1) is already deprecated.

Hope this helps,
Mark