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()]
Advertisements

About Eric Elzinga
Eric Elzinga I'm an integration consultant located in The Netherlands. Mainly doing projects based on Oracle integration stacks (Oracle SOA Suite/Oracle Service Bus (OSB)), Java development, and opensource integration products.

7 Responses to Oracle Service Bus, file transport, get filename from url

  1. Pingback: Oracle Service Bus, file transport, get filename from url | Oracle .. Java .. OpenSource .. SOA

  2. mani says:

    Hi Eric,
    R u get the output for this article,can u give post the project artifacts.

    Thanks
    Mani

  3. Yuan says:

    I figured out how to get the filename directly:

    $inbound/ctx:transport/ctx:request/tp:headers/file:fileName/text()

    However, my big problem is that name is almost useless, because the input proxy moves that file behind scene, first to “stage” folder, then to “archive” folder.

    I have a java callout inside the proxy that wants to process this input file. i will get a “file not found error” in my java. I have no way to find out where the file is inside my java. Any suggestion?

    • Eric Elzinga says:

      why do you want to process the file from within java when you already have the content in your proxy service itself ?

  4. Prasad says:

    Hello Eric, I have the exact same problem as Yuan. I extract the file name from the $inbound variable and pass it to my java callout, but the Java program throws a File Not Found error because the file is already moved by the proxy service. In my use case the file is very large – about 10GB, and I have to do some complex processing, and hence I wrote the java program that needs to be called out. Please let me know if you have a solution.

  5. Prasad says:

    ok… I just found the solution to this problem. Instead of passing the original name of the file from the $inbound variable to the java callout, pass the name of the archived file.
    The name of the archived file is: fn:substring($body/ctx:binary-content/@ref,8)

  6. Nanda says:

    Well done sir, this solve my problem!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: