Tuesday, September 8, 2020

SOA Scenario - Dynamic File name for sync read operation in FTP Adapater.

 

As we design the file adapter for sync read it asks for the file name which is static, this means that only file with this given name will be read.

Q) Now suppose if we need to read files having same format but different names.
How are we going to do that? 

Dynamic File name for sync read operation in FTP Adapater.
how to use a file name that is dynamically created for sync read operation of FTP adapter
In your bpel file:

1. Create a variable which will contain the file name

<variable name="FileName" type="xsd:string"/>

2. Use an assign activity and assign the file name you want to use to FileName variable

<assign name="Assign_FileName">
    <copy>
      <from>'TestFile'</from>
      <to>$FileName</to>
    </copy>
</assign>

3. 
-> Double click the invoke activity which invokes the sync read adapter.
-> Go to adapters tab and click the torch icon.
Edit ->Properties ->To
Create a new property and select Name as jca.ftp.FileName and Value as $FileName
In source it will appear as:

<bpelx:toProperties>
        <bpelx:toProperty name="jca.ftp.FileName" variable="FileName"/>
</bpelx:toProperties>

Now at run time TestFile will be read irrespective of whatever file name specified for the FileName property in your {xyz}_ftp.jca file.

Now we can give the name of the file at runtime as the input parameter or we can define deployment descriptor to give the file name.

Note: passing the file name when you are reading the file in the middle of a running BPEL process. Also you can not pass the file name when you poll for the files.

Step1:  Drag and drop a file adapter onto the external references lane.

Step2File adapter wizard will open up.Configure the file adapter for write operation and specify output directory and file name to be written.
Please note these values are dummy values since,they will be modified at run time when call to file adapter will be made.

Step3: Use any schema that you have handy for the write file operation.Click finish.



Step4: Call to File adapter is made using invoke activity and input variable for file adapter is created using “+” sign. For this we have to create variables for invoke activities. once done

Step5: Now drag and drop assign activity for populating the input payload for file adapter.Fields such as FName,LName,City,Designation in the input payload is mapped to the input variable for invoking file adapter.
Create two new variables of string data type namely “NewFileName” and “NewDir”. 
Now we will set the values for these two variables in the same assign activity in which we mapped the input file variable.These are the values that will be passed at run time to file adapter for write operation.




Step6: Now, we will set the new file name and new file directory. Double click the invoke activity and switch to “Properties” tab. Drill down to properties “jca.file.filename” and set its values to variable that we created “NewFileName”.


Step7: In the same manner for “jca.file.Directory” set its values to “NewDir”.


Step8: In this manner we pass the values to any JCA adapter during runtime.


Step9: Save all compile and deploy the code to EM.

Step10: Test the newly created SOA service.Pass the values and invoke Test Web Service.

Step11: Open up the flow trace of the invoked instance and notice the value for filename and filedir being passed at runtime.

Step12: Now got to the location whose dir path was given in file adapter at runtime.File is written with a name we gave at runtime.

Step13: Open the file to verify the contents of the file.

Step14: This way passing dynamic values at run time. can pass dynamic values to other JCA adapters as well.List of available properties for every adapter can be seen under properties tab of an invoke activity. 



No comments:

Post a Comment

SOA Overview Part-1

  Middleware It provides a mechanism for the process to interact with other processes running on multiple network machines. Advantages...