Skip to Content
Author's profile photo Roger Allue

Adapter Module: RenameFile


RenameFile module is used to replace strings within the value of Dynamic Configuration key [“FileName”,]. It can be used to modify a part of the file name of the message before it gets in PI and also before it gets out.  The module obtains a pair of string : <OldString>;<NewString> as parameter. Reads the Dynamic Configuration key [“FileName”,] of the message. Then it searches <OldString> within the  filename and replace each occurrence with <NewString>. Finally it updates the key with the new value and the original message is returned.

The module accepts multiple string pairs to allow multiple replacements in one execution.


Enterprise Java Bean Project: RenameFile_EJB

Enterprise Java Bean Application: RenameFile_EAR


The module can be used in any Sender or Receiver File/FTP Adapter.


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
separator Optional

Any alphanumeric character.

Default value: ‘|’

This parameter configures the character that separates a pair of strings. separator = ‘;’
param(*) Mandatory

Pair of strings separated by

“separator” character.


  Default value: none.

This parameter is used to obtain Old string to be replaced by the New string in the message. The pair is separated by “separator”. As Adapter module tab in PI trims strings by the right side, if it’s needed to replace OldString by a blank string or an empty string, the values  blankString or emptyString have to be used.




(*) The parameter name can be any string: param1, parameter, aaa, etc.


Adapter Type:

File/Ftp Sender

Dynamic Configuration before execution:

Module parameters:

separator = ‘;’

param1 = .GENERATED;emptyString

Dynamic Configuration after execution:

Audit Log

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


package com.rav.integrations.modules;
import java.rmi.RemoteException;
import java.util.Enumeration;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
* @author Roger Allué Vall
public class RenameFileBean implements SessionBean, TimedObject {
    private static final long serialVersionUID = 1L;
    private static final String C_SEPARATOR_STRING = "separator";
    private static final String C_AUX_SEPARATOR = "|";
    private static final String C_MODULEKEY_STRING = "module.key";
    private static final String C_BLANK_STRING = "blankString";
    private static final String C_EMPTY_STRING = "emptyString";
    /* (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 {
    public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)    throws ModuleException {
        Message msg;
        Enumeration<String> paramList;
        String sep, paramKey,param, strArray[];
        try {
             msg = (Message) inputModuleData.getPrincipalData();
             MessageKey amk = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
             MessagePropertyKey FileKey = new MessagePropertyKey("FileName","");           
             String fileName = msg.getMessageProperty(FileKey);
             sep = moduleContext.getContextData(C_SEPARATOR_STRING);
             if ( sep == null ) {
                sep = C_AUX_SEPARATOR;
                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Default separator used: " + sep);
             else {
                Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Separator found: " + sep);
             paramList = moduleContext.getContextDataKeys();
               while( paramList.hasMoreElements()) {
                    paramKey = paramList.nextElement();
                 param =  (String) moduleContext.getContextData(paramKey);
                 if ( ! paramKey.equals(C_SEPARATOR_STRING) && ! paramKey.equals(C_MODULEKEY_STRING) ){
                    Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"ParamKey: " + paramKey);
                    Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitució Param: " + param);
                    Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitució sep: " + sep);                  
                    strArray = param.split(sep);
                    if (strArray != null){  
                       if ((! strArray[0].equals(null)) && (! strArray[1].equals(null))){
                        if ( strArray[1].equals(C_BLANK_STRING)){
                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Blank String");
                            strArray[1]=" ";                          
                        else if (strArray[1].equals(C_EMPTY_STRING)){
                            Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Empty String");
                        Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitution array strArray[0]: " + strArray[0]);
                        Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitution array strArray[1]: " + strArray[1]);
                        Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitution array fileNameA : " + fileName);          
                        fileName = fileName.replaceAll(strArray[0],strArray[1]);
                        Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"Substitution fileNameB : " + fileName);
        catch(Exception e) {
            ModuleException me = new ModuleException(e);
            throw me;
        return inputModuleData;

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.