We usually deal with files in our projects. We can perform multiple operations using file adapter like poll, read, write etc. But in some scenario we need to simply move file from one location to other without reading its content.
In this post I will explain how we can move file without reading its content using file adapter.
Follow below steps to move file from one directory to other directory.
In this post I will explain how we can move file without reading its content using file adapter.
Follow below steps to move file from one directory to other directory.
- Create a composite named “MoveFile” and create “One-Way” BPEL process.
One-Way BPEL Process |
- Drag & Drop File adapter from Component Palette to the External Reference swim lane. This will open adapter configuration wizard.
- Enter Service name in Service Name field. We named it “MoveFile” and click next.
- Select Define from operation and schema (specified later), and click Next. The Operation page is displayed.
- Synchronous Read File”.
Sync Read Operation |
- Enter a dummy physical path for the directory for incoming files, and then click next. We will assign this value at runtime.
Incoming File path |
- Enter a dummy file name, and then click next.
File Name |
- Select native format translation is not required (Schema is opaque), and then click Next. The Finish page is displayed.
Choose Schema |
- Open “MoveFile_file.jca” and modify the endpoint interaction.
Earlier
<adapter-config name="MoveFile"
adapter="File Adapter" wsdlLocation="MoveFile.wsdl"
xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
<connection-factory
location="eis/FileAdapter"/>
<endpoint-interaction
portType="SynchRead_ptt" operation="SynchRead">
<interaction-spec
className="oracle.tip.adapter.file.outbound.FileReadInteractionSpec">
<property
name="DeleteFile" value="true"/>
<property
name="PhysicalDirectory" value="dummy"/>
<property
name="FileName" value="dummy"/>
</interaction-spec>
</endpoint-interaction>
</adapter-config>
New
<adapter-config name="MoveFile"
adapter="File Adapter"
wsdlLocation="MoveFile.wsdl"
xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
<connection-factory
location="eis/FileAdapter"/>
<endpoint-interaction
portType="SynchRead_ptt" operation="SynchRead">
<interaction-spec
className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
<property
name="SourcePhysicalDirectory" value="SourceDirectory"/>
<property
name="SourceFileName" value="SourceFileName.txt"/>
<property
name="TargetPhysicalDirectory" value="TargetDirectory"/>
<property
name="TargetFileName" value="TragetFileName.txt"/>
<property
name="Type" value="MOVE"/>
</interaction-spec>
</endpoint-interaction>
</adapter-config>
Jca file |
- Now wire BPEL process to “MoveFile” file adapter.
BPEL Process |
- Open BPEL process, add one invoke activity and link it to MoveFile adapter.
BPEL Process Flow |
- Create 4 string variable with suitable name.
<variable
name="sourceDirectory" type="xsd:string"/>
<variable
name="sourceFileName" type="xsd:string"/>
<variable
name="targetDirectory" type="xsd:string"/>
<variable
name="targetFileName" type="xsd:string"/>
- Populate above created string variables with required values.
Assign Activity |
- Pass these parameters as headers to the invoke operation, for this open bpel process in source mode and add below 4 input Properties to invoke.
<invoke
name="Invoke_MoveFile"
inputVariable="Invoke_MoveFile_SynchRead_InputVariable"
outputVariable="Invoke_MoveFile_SynchRead_OutputVariable"
partnerLink="MoveFile" portType="ns1:SynchRead_ptt"
operation="SynchRead" bpelx:invokeAsDetail="no">
<bpelx:inputProperty name="jca.file.SourceDirectory"
variable="sourceDirectory"/>
<bpelx:inputProperty name="jca.file.SourceFileName"
variable="sourceFileName"/>
<bpelx:inputProperty name="jca.file.TargetDirectory"
variable="targetDirectory"/>
<bpelx:inputProperty name="jca.file.TargetFileName"
variable="targetFileName"/>
</invoke>
- Use below parameters for BPEL 2.0
<bpelx:toProperties>
<bpelx:toProperty name="jca.file.SourceDirectory"
variable="sourceDirectory"/>
<bpelx:toProperty name="jca.file.SourceFileName"
variable="sourceFileName"/>
<bpelx:toProperty name="jca.file.TargetDirectory"
variable="targetDirectory"/>
<bpelx:toProperty name="jca.file.TargetFileName"
variable="targetFileName"/>
</bpelx:toProperties>
- Deploy the process and test it.
Hi Vivek,
ReplyDeletecan you please tell me if the requirement is to transfer the file without reading its contents then why are you selecting the operation as SyncRead which means "a synchronous file operation that reads the current contents of the file"?
I used SyncRead just to simplify the scenario. The above scenario does not read the content of file, it simple moves the file.
DeleteRegards,
Vivek
Hi Vivek,
ReplyDeleteSangamesh here. I'm new to this SOA world. still i'm learning things with Fault Handling. I have a requirement like:- Create a process that inserts data into a database. After deploying the process, delete the table. So when you invoke the process it will error out. Use a fault policy framework to retry the error after 5 minutes. During this 5 minutes, create the table again. So that in next try, data will be inserted.
I'm not very sure how to catch ORA-00942 Exception from DB Adapter to BPEL catch and throw it. Pls Help me.
Regards & Thanks,
Sangamesh.
Hi Sangamesh,
DeleteCan you please let me know what exact fault you are getting ?. Inside BPEL you can add catch block for that specific fault and do what ever you want to do inside that catch block.
Regards,
Vivek
Hi Vivek,
ReplyDeleteIs it possible to get the file size while using sync read?
Regards,
Srijith
Hi Vivek,
ReplyDeleteHave you worked JCA adapter along with Oracle Service Bus file move concept ?
Thanks.
Regards,
Rajesh
I haven't worked on that scenario, I will work on it and will share one post for that scenario.
DeleteThanks
Vivek Garg
Hi Rajesh,
DeleteI have added a new post related to file move in OSB.
http://soawork.blogspot.com/2014/06/move-large-files-in-osb.html
Vivek
Hi Vivek,
ReplyDeleteI am new to SOA so forgive my ignorance. I get compilation error - prefix of qname "xsd" can not be resolved. Any ideas what might be wrong?
Please post your error message here.
DeleteVivek
Hi Vivek, I am new to SOA. Can you please tell me why you put below properties in .jca file?
ReplyDeleteSourcePhysicalDirectory
DeleteSourceFileName
TargetPhysicalDirectory
TargetFileName
These are JCA properties which are used to set source & target directory and filename.
DeleteHi,
ReplyDeleteIn the above example, could i need to create the source and target folders before deploy?
Thanks in Advance,
Gowtham
Not required.
DeleteI tried to implement above logic.But it throws error at runtime as:
ReplyDelete'Cannot set JCA WSDL Property. Error while setting JCA WSDL Property. Property setTargetFileName is not defined for oracle.tip.adapter.file.outbound.FileReadInteractionSpec Please verify the spelling of the property'
Hi Shital,
DeleteYou are using wrong classname in jca file. You need to use below class name to make it work.
className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec
Any way to get this jca adapter to work in OSB and to change the directory and filename attributes within the message flow in OSB.
ReplyDeleteWith the BPEL example the move is more like a rename and it happens instantly, is it possible to achieve the same thing with OSB
Regards Krister
Krister,
DeleteRefer below post to achieve same thing in OSB.
http://www.soawork.com/2014/06/move-large-files-in-osb.html
Hi vivek,
ReplyDeleteWhile deploying i'm getting below error for SourcePhysicalDirectory,SourceFileName,TargetPhysicalDirectory,TargetFileName variables.
Error(58): prefix of qname "xsd" can not be resolved.
Thanks,
visva
Hello,
ReplyDeleteYes I've tried that one but it's more like a read-write-delete, not like an os rename; which seems to be the result when you use the jca adapter. I guess there is a need to change either the jca:outbound-properties or the jca:dynamic-endpoint-properties in the business service created from the jca file. Is there any way to change these from a proxy service with for example transport headers or something else?
Regards Krister
Is it possible to override the Type at runtime or I need to create a separate adapter for each MOVE / COPY / DELETE action?
ReplyDeleteHi Hod, As per I know it is not possible.
Deletehi vivek,
ReplyDeleteI have used file adapter to move a file from one location to another in my local machine .
After deploying i find no instances in my dash board.
Can you please help me why i am facing this issue.
Thanks in advance
hi vivek,
ReplyDeleteCan you please help me with an issue in my file Adapter.
I have created a file adapter to move a file from 1 folder to another and i find no instances after deployment.
can you please tell me what have to be done to successful execution
Did you see any error in log file ?, ideally it should work if you follow all the steps.
DeleteHi Vivek,
ReplyDeleteThanks for you post we have implemented the similar coding in our project to move the files based on the time stamp. It is working fine for small files but now we are facing issue in moving the files which are >50MB. Is there any work around to move the larger files.
Vivek,
ReplyDeleteNice write-up. However, i feel Oracle should have documented these things properly. Not every one will have Support licence or be part of Oracle team.
Thanks,
Sai
Hi Vivek,
ReplyDeleteCan you please help me with an usecase, where i need to delete files using File Adapter.File name and Target Directory will be at runtime .there are two diffrent directory where i need to delete the files. I am able to set the FileName dynamically but the directory name set in bpel invoke proeprties, its not working. its always taking the what value is there in jca.
its showing that jca.file.TargetPhysicalDirectory is set in audit trail but its not working
let me know if this dynamic directory set works with delete.
Thanks,
Pankaj
Hi Vivek
ReplyDeletei am facing this issue.
Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'Write' failed due to: The IO operation failed. The IO operation failed. The "MOVE[NOOP][IO_ONLY]" IO operation for "C:\test\target\textxxx.txt" failed. Check the error stack and fix the cause of the error. Contact oracle support if error is not fixable. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.
when i move the file. i want to me Replace the file If exist.
Please Help me.
Thanks in Advance.
Hi Gaurav
DeleteI have updated the post to include require parameters for BPEL 2.0. You need to use that if you are using BPEL 2.0 version.
Thanks for the great post! I was wondering is there a way to use wildcards or regex for the source file name?
ReplyDeleteHi Vivek,
ReplyDeleteI am using synchronous-read in file adapter but I do not want to delete the file after reading it.
But in sync-read, the checkbox "Delete Files after successful retrieval" is by default checked and non-editable.
I do not want to move the file to another location as well, it should stay in same folder.
Is this possible in Bpel 2.0 (SOA 12c)?