cancel
Showing results for 
Search instead for 
Did you mean: 

Same filename from a sender to receiver :: DO we really need UDF ?

Former Member
0 Kudos

Hi

This is in refrence of Weblog " <i>same filename from a sender to a receiver file adapter "</i> by <i>Michal Krawczyk</i>.

/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

Actually I worked on another weblog by " <i>Shabarish Vijayakumar</i> "-->

/people/shabarish.vijayakumar/blog/2006/04/03/xi-in-the-role-of-a-ftp

And I am getting file created on the receiver side with the same file name as on the sender side without using the user-defined function mentioned in Michal's weblog.

Now my question do we really need UDF for same file name when on the sender we are polling for one file only by its name.

I am not exaclty getting the benefit of this feature. Can you tell me why do we need this feature as in whatever scenarios I worked I mentioned the file names in both Sender & Receiver File Adapters.

So I am not getting what is the use of using this UDF, when we mention the name of file needs to be created on Receiver side.

- Lalit Chaudhary -

Accepted Solutions (0)

Answers (1)

Answers (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Lalit,

No we do not need the UDF incase you need to use the same file name gfrom the sender to the receievr file adapter.

Michal in his blog has illustrated the UDF just to show, how to access Adapter Specific Identifiers using a UDF.

Consider an Example, when you need to know the Source FileName and then on the basis of the Source FileName , do some manpiluation dynamically, in such cases, using the UDF you can access the FileName.

Regards,

Bhavesh

Former Member
0 Kudos

Hi

In my Sender File Adapter for " <i>File Name</i> ", I am using " <b>*.xml</b> " & getting 5 files as a result. I need to change the file name of all these files.

This UDF will work in this case or not.

XI will treat them as 5 different payloads or just one payload.

- Lalit -

bhavesh_kantilal
Active Contributor
0 Kudos

lalit,

XI will treat all these 5 files as separate paylads.

Your file adapter will pick up the files and create a seaparte message for each of these files and pass them to the integration engine. So, using the UDF, you can read the file name and then make changes to the filename if needed.

Regards,

Bhavesh

Former Member
0 Kudos

Hi

I put this code for UDF -->

<i>String valueNew;

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

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

String valueOld = conf.get(key);

if (valueOld != null)

{

valueNew = valueOld.replaceAll("input123",name);

conf.put(key, valueNew);

}

return valueNew;</i>

Signature of UDF is this :: <u>public String GetFileName(String name,Container container)</u>

But when I am testing this UDF, I am getting following RunTime exception -->

<i>Runtime exception during processing target field mapping /ns0:FileFTP_InOut_MT/File_nm. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._FileFTP_MsgMapping_UDF_ method GetFileName$[lalit, com.sap.aii.mappingtool.tf3.rt.Context@735df3b0] com.sap.aii.mappingtool.tf3.MessageMappingException: Runtime exception during processing target field mapping /ns0:FileFTP_InOut_MT/File_nm. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._FileFTP_MsgMapping_UDF_ method GetFileName$[lalit, com.sap.aii.mappingtool.tf3.rt.Context@735df3b0]</i>

I am not much of Java Guy, can you pls. suggest what am I doing wrong, I copied this code from <a href="http://help.sap.com/saphelp_nw04/helpdata/en/43/03612cdecc6e76e10000000a422035/content.htm">SAP Help</a>

- Lalit -

bhavesh_kantilal
Active Contributor
0 Kudos

Lalit,

Are you testing this using the TEST in Integration Respository? In that case, as the runtime values are not available, it might error out.

Run it end to end and test the same.

Also, you have an input parametr to the UDF, can you tell me why?

Regards,

Bhavesh

Former Member
0 Kudos

Bhavesh

Idea behind using an input parameter " name " is to provide the name of ouput file on the receiver side in XML file on the sender side.

<i><?xml version="1.0" encoding="UTF-8"?>

<ns0:FileFTP_InOut_MT xmlns:ns0="urn:LegacyToLegacyFTP:File-File:FileTransfer">

<File_nm>lalit.xml</File_nm>

<Data_First>one</Data_First>

<Data_second>two</Data_second>

</ns0:FileFTP_InOut_MT></i>

I want the file to be created with name as <b>lalit.xml</b>.

I am executing the scenario, will let you know with the results.

- Lalit -

bhavesh_kantilal
Active Contributor
0 Kudos

Lalit,

In that case, the UDF should look like this,

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

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

String valueOld = conf.get(key);
if (valueOld != null) 
{
<b>valueNew = name;</b>
conf.put(key, valueNew);
}
return valueNew;

Regards,

Bhavesh

Former Member
0 Kudos

Thanks Bhavesh

I am able to create the files ( with the names mentioned in my XML file ) & used the code suggested by you.

Also one strange thing is happening when I am clicking the " <i>Directory</i> " check-box of " <i>Adapter Specific message attributes</i> " in Sender & Receiver Adapter. The file is getting created in the folder from where sender adapter is polling the file.

- Lalit -

bhavesh_kantilal
Active Contributor
0 Kudos

Lalit,

If you select the Adapter Specific Identifiers for Directory, then the Source Directory will also be used as the target directory ( just like the file name). If you want the directory to be not the same as target, do not select the directoy in the Receiever Fileadapter.

Regards,.

Bhavesh