0% found this document useful (0 votes)
107 views13 pages

Adapter Module To Stop Processing of Duplicate File (FTP Location) - SAP Blogs PDF

The document describes how to create an adapter module to stop processing duplicate files from an FTP location. The module checks a text file for the file name, deletes the file if it's a duplicate, and writes new file names to the text file. The module makes a URL connection to the FTP using credentials from another text file. Configuration and testing steps are also provided.

Uploaded by

fziwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views13 pages

Adapter Module To Stop Processing of Duplicate File (FTP Location) - SAP Blogs PDF

The document describes how to create an adapter module to stop processing duplicate files from an FTP location. The module checks a text file for the file name, deletes the file if it's a duplicate, and writes new file names to the text file. The module makes a URL connection to the FTP using credentials from another text file. Configuration and testing steps are also provided.

Uploaded by

fziwen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

Follow RSS feed Like


Community

Ask a Question Write a Blog Post

Former Member
May 12, 2008 9 minute read

Adapter Module to stop processing of duplicate le (FTP Location)


1 Like 3,035 Views 7 Comments

 We had a requirement in one of our project, to stop the processing of duplicate les at the adapter level i.e. the message should not enter  the
integration engine, if the le has been already processed earlier. There was a chance that client might place a le at FTP location more than ones.
 
Here we have used two text le at server to maintain the name of processed le and the password of the FTP. Example: name.txt and
FtpPassword.txt.
 
The developed module code has the following functionality.

Whenever a le will be picked from a FTP location, the module code will check the existence of that le name in the text le placed at the
server. Example name.txt.
 If the name of the le already exist, the code will make the le empty by making URL connection with the FTP server (so that adapter will
delete that le when pinged to the server next time. For that we had set the property “do not process empty le” in the ftp channel). An
error will be thrown.
Else the name will be written in the text le (server) i.e. name.txt.

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 1/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

 The module code will make a URL connection with the FTP server by picking the password from a text le stored at the server.Example
Follow RSS feed Like
FtpPassword.txt.

 
     To implement this functionality, we had written a module code. This module code will keep the name of les as record which will be checked
before processing of the next le. If the le has been already processed, it will throw an error at adapter level which in turn can trigger alerts. 
 
For step by Step procedure of  the creation of adapter module, please refer the following pdf:
http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3bdc14e1-0901-0010-b5a9-a01e29d75a6a
 
The code for the adapter module:
        p p y p p y
<span>“,”Directory”)+”/”+fileName+ “”); //msg.getMessageProperty(“</span>
<a class="jive-link-external-small"
href="http://sap.com/xi/XI/System/File">http://sap.com/xi/XI/System/File</a>
<span>“,”SourceFTPHost”) this is used to retrieve the name of host. For this
adapter specific message attributes must be enabled in the channel.
DeleteFile(FileLocation); //to delete the file } catch (Exception e)
{ throw new ModuleException(fileName+”should be deleted”); }
throw new ModuleException(fileName+”is already processed”); } }
catch( Exception e ) { ModuleException me = new
ModuleException(e); throw me; } return
inputModuleData; } public void DeleteFile(URL FileLocation) throws
Exception{ URLConnection uc = FileLocation.openConnection() ; // to establish
connection with FTP server using URL uc.setDoOutput(true); OutputStream out
= uc.getOutputStream(); out.flush();//to make the file empty out.close();//close
the file so that connection can be terminated } }</span>
 
And to maintain jndi name edit ejb-j2ee-engine.xml:
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 2/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

 
Follow RSS feed Like
This jndi Name will be used at the time of calling this module in communication channel.
 
Scenario to test the Custom Module:

Con guration of sender channel: To pick any le available at FTP location

To delete the le :

The adapter speci c message attribute must be checked (so that message can hold all the checked value which will be used by module code).
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 3/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

The Module Tab of the Sender communication channel.


Follow RSS feed Like
 

 
        FtpUser: user name of the client FTP        

        Location: The complete paths of the text le which will keep the record of the processed le

        PassLocation:  The complete paths of the text le which will maintain the password of the FTP client
 

 
Testing
 
Case1: 

When a new le will be placed at FTP location.Example: sanjaisw.xml

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 4/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

Follow RSS feed Like

 
we can see in the text le name.txt : sanjaisw.xml has not been processed earlier:
 

 
In SXMB_MONI
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 5/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

The text le on the server: the le name sanjaisw.xml has been added at the last place as shown below.
Follow RSS feed Like
 

 
Case2:    When a duplicate le will be placed at FTP location:
Example: sandeep.xml (we can see below, sandeep.xml has been already processed)
 

 
Place the le at FTP Location
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 6/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

Follow RSS feed Like

 
 
After some time le will be deleted as shown below:
 

 
But this le will not be send to the integration engine as shown below. Here it is showing only one le has been processed and that is the previous
one.
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 7/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

 
Follow RSS feed
We can see error: Go to Runtime Workbench à Message Monitoring àLike
select Adapter engine XI1 and click on display as shown below:

After that select your message.


 

 
And we can see there is no change in the text le that is stored at server:
 
 

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 8/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

Follow RSS feed Like

Alert Moderator

Assigned tags

Retagging required | sandeep jaiswal |

Related Blog Posts

We are sorry but we are currently unable to retrieve related content.

Related Questions

We are sorry but we are currently unable to retrieve related content.

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 9/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

Follow RSS feed Like

7 Comments

Former Member

May 12, 2008 at 10:57 pm

Good Work Sandeep… Keep it up… Looking for more blogs from u…

Like (0) Reply Alert Moderator

Sumesh k

May 12, 2008 at 11:03 pm

Could you please also provide how similar scenario can be handled for NFS protocol.

Like (0) Reply Alert Moderator

Former Member | Post author

May 13, 2008 at 12:32 am

Hi,
u can implement the same just by using le methods in ur module code.
String FileLocation = moduleContext.getContextData(“FileLocation”); //pass the complete path for the le.
and then call
DeleteFile(FileLocation);

and implementation of method will be as:

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 10/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

public void DeleteFile(String FileLocation)throws Exception {          try


          { Follow RSS feed Like
          File f1 = new File( lename);
             f1.delete();
                }
      catch (Exception e){}
}

Like (0) Reply Alert Moderator

Former Member

May 14, 2008 at 10:01 pm

Hi,
Excellent work, keep posting excellent things

Regards,
Krishnaraju

Like (0) Reply Alert Moderator

Former Member | Post author

May 18, 2008 at 8:09 pm

thanks

Like (0) Reply Alert Moderator

Former Member | Post author

May 22, 2008 at 1:48 am

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 11/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

it seems that it is a nice blog.


but i cannot see the images on Follow
the page RSS feed Like

Like (0) Reply Alert Moderator

Dheeraj Kumar

December 15, 2009 at 3:47 am

Hi Sandeep
I tried to do operation on FTP location via custom module (operations like renaming of le at FTP location) but nothing worked. My problem is i want
to rename a le at ftp location if found duplicate. Is it possible to do so please give some inputs if feasible.

Regards
Dheeraj kumar
9891802720

Like (0) Reply Alert Moderator

Add Comment

Find us on

Privacy Terms of Use

Legal Disclosure Copyright

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 12/13
4/20/2020 Adapter Module to stop processing of duplicate file (FTP Location) | SAP Blogs

TrademarkFollow RSS feed Like Cookie Preferences

Newsletter Support

https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 13/13

You might also like