Sunday, February 17, 2013

Transfering File Using FTP Adapter

Hi ,

FTP adapter is use for transfer the file from one local/remote system to another local/remote system with use of the any FTP server.Obviously FTP adapter is based on the FTP protocol and also it is based on the Java EE Connector Architecture (JCA) 1.5 architecture .

Use Case :I have require where i need to transfer file from local/remote to remote/local location.File adapter will poll the file after each 10 second(Although you can change polling time base on your requirement). Here we do not need to read the contains of file.

Approach:The step are following

Step1:-We require to have FTP server on machine where server is running.Therefore i have installed FileZilla FTP server on my server machine.

You can download FileZilla FTP server at following server
link :http://filezilla-project.org/

Step2:-Need to create two user in FTP server which later we need to configure in FTP adapter JNDI.
Configure shared folder for both user.This all need to done in FTP server only not weblogic server.

Step3:Need to create two JNDI for local and remote location.This should be done in the under FTP adapter service which is present in the weblogic server.

Step4:Need to map FTP server user with weblogic user.This will done in weblogic server.Here Security mapping is require between FTP server username and weblogic  server user .

Step5:Use two  FTP  adapter in soa application for building a service which will automatically poll the file after each 10 seconds.

Implementations:

Step1:-We require to have FTP server on machine where server is running.Therefore i have installed FileZilla FTP server on my server machine.

  




Step2:-Need to create two user in FTP server which later we need to configure in FTP adapter JNDI.
Configure shared folder for both user.This all need to done in FTP server only not weblogic server.

a) For creating new use in FTP server.Go to edit-->user.following screen will open

b)click on the add button and give the user name.Here i am giving ftpweblogic as a username. and check the password check box and give the password here i am giving weblogic1


c)click on shared folders and add shared location and make it Set as home dir. and also check all the check box under file and directories section.

The above step need to do for next user as well.I have created user with user ftpweblogiclocal, password as weblogic1 and same folder as shared folder.


Step3:Need to create two JNDI for local and remote location.This should be done in the under FTP adapter service which is present in the weblogic server.

a)go to the weblogic admin server -->deployments -->Ftpadapter

b)click on FtpAdapter-->configuration -->Outbound  Connections Pools 



c)click the New button  and select the javax.resource.cci.ConnectionFactory and then next.Give the JNDI name here i am give eis/Ftp/FtpAdapterLocal and click finished .

Do the same step for creating second JNDI. BTW there is already one JNDI present which we can use for second user.
JNDI name is eis/Ftp/FtpAdapter


Step4:Need to map FTP server user with weblogic user.This will done in weblogic server.Here credential  mapping is require between FTP server username and weblogic  server user .

a)click on again FtpAdapter-->Security-->credential mapping  
b)click on new and select the JNDI which you want to map .Here we need to map both JNDI which we have created step 3.I have selected eis/Ftp/FtpAdapter and then next

c)Select the Configured User Name option and give your weblogic user name in inputext and click next 

d)In the next page give the FTP username and password.
fpweblogic/weblogic1


 The mapping has been created successfully.


Step5:Use two  FTP  adapter in soa application for building a service which will automatically poll the file after each 10 seconds.

a)It is time to open jdeveloper.Create a SOA applicatio with BPEL and select the Define Service Later as Template

  

b)drag and drop FtpAdapter in the Expose Service.Click next  and then in the next page give the FTP adapter name here i am giving InFile .


c)click next and next give the JNDI name eis/ftp/FtpAdapter and next
d)in operation page select operation type as Get File and check the Read File as attachment




e)In file Directories page give the Directory for Incoming file(Physical File ) value as \in

*we already configure the shared location in FTP server.It will search \in inside shared folder.
click next

f)And in the next File Filtering  page and give the *.xml value in the Include Files With Name Pattern .Here i am transferring XML file  so that is reason why i have give *.xml .



g)In next page .Set file polling  time and next and then finish it.
h)Again drag and drop one more file adapter in external references section.
i)Give the FTPAdatper name PutFile and then next,again next and then give the second JNDI name here then next.
j)In Operation page select the Operation Name as put and then next

k)In Page File configuration give the file  Naming Converation  value and Directory For Outgoing files


l)No need to provide schema since here i want to transfer file one location without reading contains of file so in this page need to check the check box because schema type is Opaque .

File Adapter are ready to use .

In next step  map the value of one file adapter into second file adapter through BEPL and deploy it soa server.

Put the any sample file into in folder where file extension should be .xml.So when polling will happens it will move the file from in to out folder and it will delete the moved file from in Folder.


You can download sample application at following location

link:https://docs.google.com/file/d/0B8cP4jZuxLlXaV9MN2JUX1BBVUE/edit?usp=sharing

Thanks
Prateek