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

$inbound/ctx:transport/ctx:request/tp:headers/file:fileName

this will give us :

<file:fileName xmlns:file="http://www.bea.com/wli/sb/transports/file">c:\temp\testfile\1263968456285_test.xml</file:fileName>

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)

select substr('/tmp/testfile/test.xml',instr('/tmp/testfile/test.xml','/',-1)+1)
from dual;

In this case the function tokenize can be used :

tokenize($inbound/ctx:transport/ctx:request/tp:headers/file:fileName, "/")[last()]

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

tokenize($inbound/ctx:transport/ctx:request/tp:headers/file:fileName, "\\")[last()]

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>