Saturday, December 1, 2012

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.
  • Create a composite named “MoveFile” and create “One-Way” BPEL process.
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”.
Choose Sync Read Operation
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
Incoming File path

  • Enter a dummy file name, and then click next.
dummy file name
File Name

  • Select native format translation is not required (Schema is opaque), and then click Next. The Finish page is displayed.
Choose Native Format
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>

File Adapter JCA File
Jca file
  • Now wire BPEL process to “MoveFile” file adapter.
wire bpel to adapter
BPEL Process

  • Open BPEL process, add one invoke activity and link it to MoveFile adapter.
Bpel Flow
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 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.
                     




34 comments :

  1. Hi Vivek,

    can 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"?

    ReplyDelete
    Replies
    1. I used SyncRead just to simplify the scenario. The above scenario does not read the content of file, it simple moves the file.


      Regards,
      Vivek

      Delete
  2. Hi Vivek,
    Sangamesh 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.

    ReplyDelete
    Replies
    1. Hi Sangamesh,

      Can 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

      Delete
  3. Hi Vivek,

    Is it possible to get the file size while using sync read?

    Regards,
    Srijith

    ReplyDelete
  4. Hi Vivek,

    Have you worked JCA adapter along with Oracle Service Bus file move concept ?

    Thanks.

    Regards,
    Rajesh

    ReplyDelete
    Replies
    1. I haven't worked on that scenario, I will work on it and will share one post for that scenario.

      Thanks
      Vivek Garg

      Delete
    2. Hi Rajesh,

      I have added a new post related to file move in OSB.

      http://soawork.blogspot.com/2014/06/move-large-files-in-osb.html

      Vivek

      Delete
  5. Hi Vivek,

    I 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?

    ReplyDelete
    Replies
    1. Please post your error message here.

      Vivek

      Delete
  6. Hi Vivek, I am new to SOA. Can you please tell me why you put below properties in .jca file?





    ReplyDelete
    Replies
    1. SourcePhysicalDirectory
      SourceFileName
      TargetPhysicalDirectory
      TargetFileName

      Delete
    2. These are JCA properties which are used to set source & target directory and filename.

      Delete
  7. Hi,

    In the above example, could i need to create the source and target folders before deploy?

    Thanks in Advance,

    Gowtham

    ReplyDelete
  8. I tried to implement above logic.But it throws error at runtime as:
    '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'

    ReplyDelete
    Replies
    1. Hi Shital,

      You 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

      Delete
  9. 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.
    With 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

    ReplyDelete
    Replies
    1. Krister,

      Refer below post to achieve same thing in OSB.

      http://www.soawork.com/2014/06/move-large-files-in-osb.html

      Delete
  10. Hi vivek,
    While deploying i'm getting below error for SourcePhysicalDirectory,SourceFileName,TargetPhysicalDirectory,TargetFileName variables.

    Error(58): prefix of qname "xsd" can not be resolved.

    Thanks,
    visva

    ReplyDelete
  11. Hello,
    Yes 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

    ReplyDelete
  12. Is it possible to override the Type at runtime or I need to create a separate adapter for each MOVE / COPY / DELETE action?

    ReplyDelete
    Replies
    1. Hi Hod, As per I know it is not possible.

      Delete
  13. hi vivek,

    I 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

    ReplyDelete
  14. hi vivek,

    Can 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

    ReplyDelete
    Replies
    1. Did you see any error in log file ?, ideally it should work if you follow all the steps.

      Delete
  15. Hi Vivek,

    Thanks 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.

    ReplyDelete
  16. Vivek,

    Nice 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

    ReplyDelete
  17. Hi Vivek,
    Can 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

    ReplyDelete
  18. Hi Vivek

    i 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.

    ReplyDelete
    Replies
    1. Hi Gaurav

      I 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.

      Delete
  19. Thanks for the great post! I was wondering is there a way to use wildcards or regex for the source file name?

    ReplyDelete
  20. i am facing two faults
    1.

    System Fault Error Message: {http://schemas.oracle.com/bpel/extension}remoteFault
    Fault ID January_2017/synchread!1.0*soa_ef64a270-39a6-468f-b444-a656b7bd5c65/movefile/130002-BpInv0-BpSeq0.3-3
    Fault Time Apr 13, 2017 4:10:20 PM
    Non Recoverable System Fault :
    bpelFault faultType>0 /faultType remoteFault xmlns="http://schemas.oracle.com/bpel/extension" part name="summary" summary>Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'SynchRead' failed due to: The IO operation failed. The IO operation failed. The "MOVE[NOOP][IO_ONLY]" IO operation for "TargetDirectory\TragetFileName.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. /summary /part part name="detail" detail>The source file SourceDirectory\SourceFileName.txt does not exist /detail /part part name="code" code>null /code /part /remoteFault /bpelFault

    2.
    System Fault Error Message:
    Fault ID reference:80002
    Fault Time Apr 13, 2017 4:10:19 PM
    Non Recoverable System Fault :
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'SynchRead' failed due to: The IO operation failed. The IO operation failed. The "MOVE[NOOP][IO_ONLY]" IO operation for "TargetDirectory\TragetFileName.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.

    ReplyDelete
  21. Hi Vivek,

    I 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)?

    ReplyDelete