Skip to Content

Use

AddTimeStamp module can be used to construct a new filename with a special timestamp format. The module sets a new value for the Dynamic Configuration key [“FileName”,http://sap.com/xi/XI/System/File] according to the parameters FILENAME_PREFIX, FILENAME_SUFIX and TIMESTAMP_FORMAT.


The new filename is constructed as follows:

FILENAME = <PREFIX_TAG> + SYSTEM_TIMESTAMP(TS_FORMAT) + <SUFIX_TAG>

This module has been developed to simulate the functionality “Add Timestamp” of the Receiver File/FTP Adapter and allow user to customize the timestamp formatting to override the standard format yyyymmdd-HHMMDD-SSS.

Deployment

Enterprise Java Bean Project: AddTimeStamp_EJB

Enterprise Java Bean Application: AddTimeStamp_EAR

Integration

The module can be used in Sender and Receiver File/FTP Adapters.

Adapter specific option File Name has to be active.

Activities

This section describes all the activities that have to be carried out in order to configure the module.

Entries in processing sequence

Insert the module in front of the adapter module as shown in the picture below.

Entries in the module configuration


The table below shows the possible parameters and values of the adapter module.


Parameter Type Possible Values Description Example
FILENAME_PREFIX Optional

Any alphanumeric character except: < > : ” / \ | ? *

This parameter specifies the string to be placed before the timestamp.

exp_
TIMESTAMP_FORMAT Optional

Any correct format for the class java.text.SimpleDateFormat.


Default value: yyyyMMdd-HHmmss

This parameter specifies the timestamp format according to the java class  java.text.SimpleDateFormat.

ddMMyyyyHHmmss
FILENAME_SUFIX Optional

Any alphanumeric character except: < > : ” / \ | ? *

This parameter specifies the string to be placed after the timestamp.

.txt



Example


FILENAME_PREFIX = MeterReadings_

FILENAME_SUFIX = .xml

TIMESTAMP_FORMAT = ddMMyyyyHHmmss

Dynamic configuration after execution:


[“FileName”,http://sap.com/xi/XI/System/File] –> MeterReadings_01082010210013.xml


Audit Log


The execution process can be followed in the audit log generated per message.


AddTimeStampBean


/**
*
*/
package com.rav.integrations.modules;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
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.auditlog.AuditLogStatus;
/**
* @author Roger Allué Vall
*
*/
public class AddTimeStampBean implements SessionBean, TimedObject {
    /**
     *
     */
    private static final long serialVersionUID = 8087133996851499898L;
    private static final String C_FILENAME_PREFIX_TAG         = "FILENAME_PREFIX";
    private static final String C_FILENAME_SUFIX_TAG          = "FILENAME_SUFIX";
    private static final String C_TIMESTAMP_FORMAT_TAG    = "TIMESTAMP_FORMAT";
    private static MessageKey amk;
    /* (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 arg0) throws EJBException,
            RemoteException {
        // TODO Auto-generated method stub
    }
    /* (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 {
    
    }
    private void addInfo (String msg){
        if (amk != null){
          Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,msg);
        }
        else{
          System.out.println(msg);
        }
    }
    public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)    throws ModuleException {
    
         String fileNamePrefix   = moduleContext.getContextData(C_FILENAME_PREFIX_TAG);
         String fileNameSufix    = moduleContext.getContextData(C_FILENAME_SUFIX_TAG);
         String timeStampFormat  = moduleContext.getContextData(C_TIMESTAMP_FORMAT_TAG);
     
         String timeStamp;
         String fileName;
         Message msg;
         MessagePropertyKey key;
     
         try{         
              msg = (Message) inputModuleData.getPrincipalData();
             amk               = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
         
             addInfo("--> Start AddTimeStamp Module");
         
               if ( fileNamePrefix == null ){
                 fileNamePrefix = "";
            }
        
            if ( fileNameSufix == null){
                 fileNameSufix = "";
            }
     
            if (timeStampFormat == null) {
                 timeStampFormat = "yyyyMMdd-HHmmss";
             }
         
             addInfo("--> " + C_FILENAME_PREFIX_TAG    + " = " + fileNamePrefix);
             addInfo("--> " + C_FILENAME_SUFIX_TAG     + " = " + fileNameSufix);
             addInfo("--> " + C_TIMESTAMP_FORMAT_TAG   + " = " + timeStampFormat);
         
             try{
                 timeStamp = new java.text.SimpleDateFormat(timeStampFormat).format(new java.util.Date ());             
             }         
             catch( Exception e){
                 addInfo("--> TimeStamp could not be generated.");
                 timeStamp = "19000101-000000-" + Math.random();
             }
         
             addInfo("--> TimeStamp = " + timeStamp);         
         
             fileName = fileNamePrefix + timeStamp + fileNameSufix;
         
             addInfo("--> FileName = " + fileName);         
             key = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/File");
            msg.removeMessageProperty(key);
            msg.setMessageProperty(key,fileName);
        
             addInfo("--> Finish AddTimeStamp Module");
 
         }
        catch (Exception e) {
            addInfo ("Exception: " + e.getMessage());
            StackTraceElement[] stack = e.getStackTrace();
            for ( int i=0; i<stack.length; i++){
                addInfo (stack[i].toString());
            }    
            throw new ModuleException(e.getMessage(),e);
        }    
    
        return inputModuleData;
    }
}


To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply