Thursday, June 19, 2008

File Size from File Adapter

Well, reading/writing file name and file directory are very well documented in File Adapter guide and blogs. Just to recap, in order to read/write file name and directory you are supposed create a header variable of element InboundFileHeaderType (it will be different if it is outbound header variable). The WSDL file is created when you create FileRead or FileWrite operation.



After you create Variable, we just need to specify that variable as part of Header variable in Adapter.




That's all required, and during file polling you will get the fileName and directoryName already populated.


Wait a minute, but if you look at Variable_FileHeader at runtime in Assign Activity, you can see 5 elements are populated rather than 2. E.g.


It means, this header variable is populating 5 elements, where wsdl file is exposing only two! How to get remainder three, or let;s say SIZE which is more interesting to all of us.


Two ways:

1) Hack the wsdl file and put size as one of the element as shown below. (Note fileAdapterInboundHeader.wsdl file is created with ReadOnly attribute so you have to change the attribute prior to modification).


After doing this size attribute is populated and you can assign to any other variable if you like.

2) This is non-intrusive way. As we know that Header Variable (XML Element) already has size, it is just matter of extracting it, so why not to convert Header Variable in String and do string search? e.g. I did following assign activity to get the size and assign it to some string variable called Variable_File_Size. You can see, that I am converting xml element to string and then doing search for string between <size> </size>.




Things didn't end here, as somebody asked me that how to know how many elements/attributes are really supported. I couldn't find the documentation anywhere, so back to the JAD, and I could find the file name called "oracle/tip/adapter/file/FileAgent.java" which had following lines of code:


Based on code, it looks like variables are just getting inserted on the fly, as it is not JAXB but just being treated as DOM element. Ofcourse, it showed me a way what I need to do if I need to insert my custom header in File Adapter.


Here is the entire code used for sample.

5 comments:

Anonymous said...

Hey Chintan,

I read your blog posts and they are very helpful. I am in middle of a demo and out of nowhere I am getting an error in bpel console. I have posted it on Oracle Forum.

http://forums.oracle.com/forums/thread.jspa?threadID=672692&tstart=0

If you have nay idea about this issue can you please let me know. Your help will be greatly appreciated.

Thanks
Rajesh

Chintan Shah said...

Hi Rajesh,

Thanks for your comments.

I don't have much insight on your issue, but with Oracle Lite you will get this type of issue every now and then.

Nothing formal, may not be even true, just personal advice based on my personal experience.
I would recommend to install soa on XE, I was used to reinstall basic soasuite on weekly bases till I got XE/SOA. Life has been better and reinstallation has been push down from week to two months.
Only problem with XE is initial number of session, which can be easily fixed by one update statement.

You can reach me at chintan230 at yahoo dot com for any further questions.

Regards,
Chintan

Unknown said...

thank you chintan ,

my problem is solved

if any problem comes i will ping you

regards
janardhan

Srikant Vaidya said...

can u give a little detail steps involved in getting the file name and directory in soasuite11g.
I am new to soasuite11g

tosaurav said...

I have to FTP the files and has to retain the same name and directory structure.I followed your step but not able to get filename as well as directory.Even while testing the new variable not showing up.Any idea?

The steps are following:
1.Read File Adapter : read zip file from dir H:\abc'd\temp (an opaque data)
2.Receive's adapter has new variable entry.
3.Assign activity copy input opaque element to output.
4.Invoke call write