Oracle Service Bus, file transport, get filename from url

In Oracle Service Bus it’s relative easy to get the filename which has been processed by the proxy service.
On the $inbound context variable we can use the next xpath expression to get file uri
[sourcecode language=”xml”]
$inbound/ctx:transport/ctx:request/tp:headers/file:fileName
[/sourcecode]

this will give us :
[sourcecode language=”xml”]
c:\temp\testfile\1263968456285_test.xml
[/sourcecode]

Now i was struckling a bit on how to get just the filename from this url.
Since i couldn’t find any instring function in the bea xqueury function list i couldn’t use any construction like (without the sql commands)

[sourcecode language=”sql”]
select substr(‘/tmp/testfile/test.xml’,instr(‘/tmp/testfile/test.xml’,’/’,-1)+1)
from dual;
[/sourcecode]

In this case the function tokenize can be used :
[sourcecode language=”xml”]
tokenize($inbound/ctx:transport/ctx:request/tp:headers/file:fileName, “/”)[last()]
[/sourcecode]
this will give me the last token in the list which is split up by the “/” sign, with as result “test.xml”.

In case your running it on a windows environment don’t forget to escape the backslash
[sourcecode language=”xml”]
tokenize($inbound/ctx:transport/ctx:request/tp:headers/file:fileName, “\\”)[last()]
[/sourcecode]
Original blog

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>