Wednesday 23 November 2011

Dynamically passing the file name to read adapter

Sync Read option in BPEL file adapter allows us to read the file from the middle of the process, this is different from the Read option which polls for the new files and is the start of the BPEL process.

As we design the file adapter for sync read it asks for the file name whcih is static, this means that only file with this given name will be read. Now suppose if we need to read files having same format but different names. How are we going to do that?
 
There's a simple way to do this. Whenever we create an adapter a fileAadapterOutboundHeader.wsdl file is created. If we open this file we'll find an inline schema having the fileName element. Below is the fileAadapterOutboundHeader.wsdl file:

<definitions
name="fileAdapter"
targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/file/"
xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/file/"
xmlns="http://schemas.xmlsoap.org/wsdl/" >

<types>
<schema attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/file/"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:FILEAPP="http://xmlns.oracle.com/pcbpel/adapter/file/">
<element name="OutboundFileHeaderType">
<complexType>
<sequence>
<element name="fileName" type="string"/>
</sequence>
</complexType>
</element>
</schema>
</types>
<!-- Header Message -->
<message name="OutboundHeader_msg">
<part element="tns:OutboundFileHeaderType" name="outboundHeader"/>
</message>

</definitions>


While invoking the adapter we only need to set this fileName element with some dynamic generated value. Below are the steps to do this:
  1. Double click the invoke activity which invokes the sync read adapter.
  2. Go to adapters tab and click the torch icon.
  3. Click on Variables and create a new variable.
  4. Give some name like OutboundheaderVariable, choose message type and click the torch.
  5. Drill down to fileAadapterOutboundHeader.wsdl > Message Types and select OutboundHeader_msg. Click Ok till you are back in the diagram.
  6. Place an assign activity above this invoke and copy the file name to the OutboundHeaderVariable > fileName variable.
That's it.

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.

 

2 comments:

  1. Hi,
    Actually i m using jdev11.1.1.3.0..so i cant get adapters window.so how can i use this syncread option.pls help

    ReplyDelete
    Replies
    1. Shilpa,
      First go to Composite.xml and create a File Adapter. You will get the SyncRead option there. Then attach the Adapter to the BPEL and then come to BPEL process and add one Assign and one Invoke activity.

      Inside Invoke activity, create input & Output variables and inside Assign activity, assign the desired File Name to the input variable you just created.

      Delete

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...