cancel
Showing results for 
Search instead for 
Did you mean: 

Need to add .pdf file extension in FTP Receiver channel explicitly !!!

Former Member
0 Kudos

Hi All,

I a working on File to FTP Scenario to pull pdf file (the Filename scheme is without pdf extension but the file type is pdf) and upload on FTP Server.

Now, since the sender file name do not have .pdf extension, I am not able to get the same .pdf file at receiver FTP Also.

The file at receiver side is of FileType PDF but its not opening directly as pdf file.Instead it asks every time how to open the file.

Can any one suggest me how i can achieve this .pdf extension explicitly at target side.

Note: There is no ESR in this scenario.

Current parameters settings in channels

Sender File Name Scheme - *

Receiver File Name Scheme - *.pdf

Using ASMA attributes to pull same file name from sender to receiver.

Thanks

Neha

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos
Former Member
0 Kudos

Hi Neha

Either you need to create some dummy interface in ESR and create an dummy mapping which will contain the UDF for changing the file name.

UDF code:

String FileName_input = "";

try
{

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey Filekey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

FileName_input=conf.get(Filekey)+".pdf";

conf.put(Filekey,FileName_input);


return "";

}

catch (Exception e)
{

}

Or you can create this adapter module and use it in the communication channel

Module Code:

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.InputStream;

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.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.PublicAPIAccess;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;
import com.sap.engine.interfaces.messaging.api.XMLPayload;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditAccess;
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
import com.sap.engine.interfaces.messaging.api.exception.InvalidParamException;
import com.sap.engine.interfaces.messaging.api.exception.MessagingException;

public class GenerateFilename implements Module, SessionBean {

private static final long serialVersionUID = 1L;
private AuditAccess Audit = null;
private MessageKey amk = null;

public ModuleData process(ModuleContext moduleContext,
   ModuleData inputModuleData) throws ModuleException {

  Message mes = null;
  String filename = "";
  XMLPayload xmlData = null;
  mes = (Message) inputModuleData.getPrincipalData();
  xmlData = mes.getDocument();

  // For Audit Log Fetch the Audit Message key from the message.
  amk = new MessageKey(mes.getMessageId(), mes.getMessageDirection());
  PublicAPIAccess pa;
  try {
   pa = PublicAPIAccessFactory.getPublicAPIAccess();
  } catch (MessagingException me) {
   ModuleException e1 = new ModuleException(me);
   throw e1;
  }
 
  MessagePropertyKey mpk = new MessagePropertyKey("FileName","http://sap.com/xi/XI/System/File");
                String NewFileName = mes.getMessageProperty(mpk)+".pdf";
               

  try {
   mes.setMessageProperty(mpk, NewFileName);
  } catch (InvalidParamException e2) {
   Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR,
     "Error Target filename  : " + filename);
   ModuleException e1 = new ModuleException(e2);
  
   throw e1;
  }
 
  return inputModuleData;

}
}

iaki_vila
Active Contributor
0 Kudos

Hi Neha,

If you want to rename the file via script you can read  Raja Sekhar Reddy's blog
http://scn.sap.com/people/rajasekhar.reddy14/blog/2011/04/19/logging-archiving-and-changing-the-file...

Thinking about this theme, I agree with Amit, you should develop an own adapter module to rename the file. Right now i cant find any example code, but i remember a blog wich its code worked with file receiver.

Regards,

Former Member
0 Kudos

Hello,

I would suggest you to write a small piece of code (AM) and rename files if ur sender system i.e. SAP (if i am not wrong) is not adding file extension.

Using scripts also u can change the filename, but personally speaking i don't like that option just because if by any reasons script executions fails PI message won't go into error state - in short a dicey situation.

Thanks

Amit Srivastava