Saturday 25 October 2014

File Adapter MOVE operation in Oracle SOA 11g

File Adapter MOVE operation in Oracle SOA Suite 11g

The Oracle File and FTP Adapters let you copy or move a file from one location to another, or delete a file from the target directory. Additionally, the Oracle FTP Adapter lets you move or copy files from a local file system to a remote file system and from a remote file system to a local file system. This feature is implemented as a interaction specification for outbound services. So, this feature can be accessed either by using a BPEL invoke activity or a Mediator routing rule.

Step 1 :
Drag drop file adapter in reference pane of composite.xml

Setp 2:
In file adapter wizard perform below steps.

In wizard step4 we have to select Synchronous Read File
NOTE : You have selected Synchronous Read File as the operation because the WSDL file that is generated because this operation is similar to the one required for the file I/O operation.

provide your own name as per naming convention which you follow.
In my case i provided "FileMove" as move operation name.

Enter a dummy physical path for the directory for incoming files, and then click Next. The File name page is displayed.
Note: The dummy directory is not used. You must manually change the directory in a later step.

Enter a dummy file name, and then click Next. The Messages page is displayed.

Note: The dummy file name you enter is not used. You must manually change the file name in a later step.
Select Native format translation is not required (Schema is opaque), and then click Next. The Finish page is displayed.
Note: we are planning to perform move operation so we no need to process the payload. For this reason no need to create an XSD.



Step 3:
now open file adapter .jca file which looks as below.

=====================================================================
<adapter-config name="FileAdptMoveTest" adapter="File Adapter" wsdlLocation="FileAdptMoveTest.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
 
  <connection-factory location="eis/FileAdapter"/>
  <endpoint-interaction portType="FileMove_ptt" operation="FileMove">
    <interaction-spec className="oracle.tip.adapter.file.outbound.FileReadInteractionSpec">
      <property name="DeleteFile" value="true"/>
      <property name="PhysicalDirectory" value="C:/Dummy path"/>
      <property name="FileName" value="dummyFileName.txt"/>
    </interaction-spec>
  </endpoint-interaction>
</adapter-config> =====================================================================

Step 4:

Now replace <endpoint-interaction>-----</endpoint-interaction> with below code.
<interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
      <property name="SourcePhysicalDirectory" value="foo1"/>
      <property name="SourceFileName" value="bar1"/>
      <property name="TargetPhysicalDirectory" value="foo2"/>
      <property name="TargetFileName" value="bar2"/>
      <property name="Type" value="MOVE"/>
</interaction-spec>

After the change in .jca file, it should looks as below.
=================================================================
<adapter-config name="FileAdptMoveTest" adapter="File Adapter"
                wsdlLocation="FileAdptMoveTest.wsdl"
                xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
    <connection-factory location="eis/FileAdapter"/>
    <endpoint-interaction portType="FileMove_ptt" operation="FileMove">
        <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
            <property name="SourcePhysicalDirectory" value="C:\Users\Fusion\Desktop\source"/>
            <property name="SourceFileName" value="student.txt"/>
            <property name="TargetPhysicalDirectory" value="C:\Users\Fusion\Desktop\target"/>
            <property name="TargetFileName" value="studentNew.txt"/>
            <property name="Type" value="MOVE"/>
        </interaction-spec>
    </endpoint-interaction>
</adapter-config>
=================================================================
Note : Note: You have modified the className attribute, and added SourcePhysicalDirectory, SourceFileName,TargetPhysicalDirectory, TargetFileName and Type.  The Type attributes decides the type of operation. Apart from MOVE, the other acceptable values for the Type attribute are COPY and DELETE.

Note :  SourceFileName and TargetFileName no need to be same. we can provide different file names.

Note : Currently, the values for the source and target details are dummy. You must populate them at run-time with .The source and target details are hardcoded in the preceding example. You can also provide these details as run-time parameters.

       (a) create 4 string variables in BPEL.
                   <variable name="sourceDirectory" type="xsd:string"/>
                   <variable name="sourceFileName" type="xsd:string"/>
                   <variable name="targetDirectory" type="xsd:string"/>
                   <variable name="targetFileName" type="xsd:string"/>
            Note: Make sure about namespace in .bpel file. Just cross check below namespace is available  in .bpel or not.
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      (b) get the source and target folder path , source and target file name from any source. Like recieve activity input variable or from a DVM or from a table. Some how get the required date and by using Assign activity copy the data from proper source to newly created variables.


Step 5:
Now open .bpel source view.
Add custom properties in invoke activity.

Existing code:
 <invoke name="Invoke1" inputVariable="Invoke1_FileMove_InputVariable"
                outputVariable="Invoke1_FileMove_OutputVariable"
                partnerLink="FileAdptMoveTest" portType="ns1:FileMove_ptt"
                operation="FileMove" bpelx:invokeAsDetail="no"/>

Modified Code:
 <invoke name="Invoke1" inputVariable="Invoke1_FileMove_InputVariable"
                outputVariable="Invoke1_FileMove_OutputVariable"
                partnerLink="FileAdptMoveTest" portType="ns1:FileMove_ptt"
                operation="FileMove" 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>

sourceDirectory, sourceFileName, targetDirectory and targetFileName are string variables which we created in Step4.

NOTE : above properties syntax is related to bpel 1.1 version.




7 comments:

  1. hi,

    could you please tell me in above scenario archive file will work or not? if not in fault scenario like it fetch the file from source something happened while moving the file . what will happen to the file?
    thank you in advance

    ReplyDelete
    Replies
    1. Hi Purna, This is MOVE operation, so we no need to think about ARCHIVE file. Because File adapter will give us data guarantee.

      Delete
  2. i want to give file name without extension. is it possible kumar?

    ReplyDelete
    Replies
    1. Yes, it is possible. File/FTP adapter will accept file name with out any extension. Adapter will write the file into outbound folder with out any extension.

      Delete
  3. File move operation is not working in 12c soa . How we can move file in 12c soa? Can u please help?

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi,
    I am getting "No such file.: No such file" error.I have given all rights on the file.I am using same file name for both source and target.Can you please let me what could be the reason for this issue

    ReplyDelete