Saturday, June 14, 2008

BPEL: Getting File Name and directory name from File Adapter

Problem:
How to know the file name and the directory name at run time that we selected during configuring File adapter in our BPEL Process?

Solution:
I will give the answer for this in step wise manner.
1) Create an empty BPEL process.
2) Create a Read File Adapters. This will create fileAdapterInboundHeader.wsdl and .wsdl file.
3) Drag receive activity to the swim lane and link it to the read operation and create variable(choose in receive activity). Check the create instance check box.
4) Create a variable of type InboundHeader_msg, say Varaiable_1 ( this message is chosen from the fileAdapterInboundHeader.wsdl).
5) Create two more variables of simple type (String), say Test1 and Test2.
5) Drag the assign activity. In the assign activity create a copy operation you can see the Variable_1 having two elements i.e. FileName and DirectoryName. You can point these two elements to the variable Test1 and Test2 respectively.
6) Now double click on receive activity go to the "Adapter" tab and choose the above Variable_1 as the Input Header Variable.

Similarly you can do it for File Write Adapter. In this case the fileAdapterOutboundHeader.wsdl contains only one element i.e. file name.

And you are done....Now you can use that value for further operations, depending upon your needs.

Have a happy learning.....

14 comments:

Eric Elzinga said...

Little add-on
See :
http://www.solbourne.com/blogs/middleware/2008/03/passing-in-directory-path-as-parameter_18.html

By adding the directory-element, you're also capable to assign the directory dynamically.
just fyi

Abhishek Saurabh said...

Thanx eric for sharing the blog information. That was really helpful.

Unknown said...

Hi Abhishek,
I want to pass the file name for file adapter from a variable in BPEL process. The link posted by eric is not working. Any idea of how to pass.

Thanks in advance,

Abhishek Saurabh said...

Hi Amith,

Follow these steps:
1) Create File Adapter
2) Then join that with receive activity. Create a input variable in receive activity. Check the create instance.
3) Create variable of file adapter header type. say 'Header'
4) Also create two variables of string type, say 'a' and 'b'.
5) Goto receive activity and click on Adapter tab. Select the variable Header.
6) Assign Header->Filename to the 'a' and Header->directoryname to 'b'.

Cheers,
Abhi...

Milind Alaspure said...

Hi,
For providing filename and directory path dynamically to file adapter, I did what u say but I hv face with error as
File Adapter::Inbound Poller raising Alert for exception : ORABPEL-11001
Invalid Input Directory.
The value specified for the input (Physical/Logical)Directory activation parameter has an invalid value "D:\Milind\File2".
Ensure that the following conditions are satisfied for the input directory :
1) It exists and is a directory (not a file). and
2) It is readable (file read permissions). and
3) If activation parameter "DeleteFile" is set to "true" then the directory should also have granted write permissions. and
4) If using a logical name, then ensure that the mapping from logical name<->physical directory is correctly specified in the deployment descriptor.
It is trying to read file from directory mansion in logical path.

Abhishek Saurabh said...

Milind,

The steps specified in the write-up is working good. I feel you missed somewhere something.

Can you check whether you have all privileges i.e. Read, Write, Execute on File picking folder?

Cheers,
Abhishek

Milind Alaspure said...

Hi Abhishek,

do I need to mention Logicalpath in bpel.xml before deploying a process? Can you please provide me the steps for configuring the file read adapter?
I have provided full privileges to the picking folder.

Anonymous said...

Hi Abhishek,

Could you explain how to implement the same in the 11g

Abhishek Saurabh said...

Hi,

There is totally different approach for this in 11g. If you double click on the Receive activity (connecting to file Adapter), then on Properties tab, you will find three properties jca.file.Directory, jca.file.Filename and jca.file.Size. Select the property which ever you want and assign variable/expression to it. (Create variable before hand)

palakh said...

Hello Abhishek

I am trying to read a file as attachment(it can be any format .pdf,.txt) and i want write this file in the same format which i read..how do i do that.Please let me know if you have any idea

dandu said...

hi,
abishek...i want to write data of specific files by using switch activity.one flow(happy flow) in switch is used to write one type of naming files and other flow is used to write other type of naming files...will you please provide the condition to check condition for "filename"...

Unknown said...

Hi

Unknown said...

I want to write files based on file Size using file adapter?

For example if i can set the size to 20kb and actual file size is 50 kb ,3 files need to create.

Can you please suggest how to acheive this?

Loulou said...

In the properties of the BPEL Receive activity, which receives the content from the File reader adapter, you can set the property "jca.file.fileName" to a string variable (that you create for this purpose).
You can also uyse "jca.file.Directory" to get the file path.

At the opposite, you can use those same properties for an Invoke activity invoking a file writer adapter. This will set the path and filename of the file to write.