Adapter Module To Stop Processing of Duplicate File (FTP Location) - SAP Blogs PDF
Adapter Module To Stop Processing of Duplicate File (FTP Location) - SAP Blogs PDF
Former Member
May 12, 2008 9 minute read
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:
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
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:
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
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
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:
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
Alert Moderator
Assigned tags
Related Questions
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
7 Comments
Former Member
Good Work Sandeep… Keep it up… Looking for more blogs from u…
Sumesh k
Could you please also provide how similar scenario can be handled for NFS protocol.
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);
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
Former Member
Hi,
Excellent work, keep posting excellent things
Regards,
Krishnaraju
thanks
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
Dheeraj Kumar
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
Add Comment
Find us on
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
Newsletter Support
https://blogs.sap.com/2008/05/12/adapter-module-to-stop-processing-of-duplicate-file-ftp-location/ 13/13