Oracle Service Bus, xquery and optional parameters

We use custom soap headers to implement end-to-end tracking over all eai components.
Those headers will get updated during transport over all components and will also get logged to the db, together with some other metadata.
That info will be used to track and trace messages and problems.

A soap-envelope will look like this :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <slg:CustomHeader xmlns:slg="">
    <!-- over here the body payload -->

Some fields in the payload can be nullable.
When we create an xquery to transform this header to our EventObject-variable we can either create the xquery with one parameter which holds the whole ‘CustomHeader’ payload, or just map the parameters we need.

  1. declare function xf:Header2EventObject($customHeader1 as element(ns1:CustomHeader))
  2. declare function xf:Header2EventObject($corId as xs:string, $MessageType as xs:string, $Status as xs:string)
  1. When we use the payload described in the example, the assign will work. Only problem is we need to assign the whole CustomHeader-element as parameter.
    When we need to data out of the body-payload which could get huge, we would need to assign this whole payload just to get a few values out of it.
  2. We only assign the values we need, but when the xquery results in an empty node the assign will fail.
    <con:fault    xmlns:con="">
      OSB Assign action failed updating variable "eventObject": com.bea.wli.common.xquery.XQueryException: Error parsing XML: {err}FORG0005: expected exactly one item, got 0 items

And the solution i was looking for (thanks to a colleague)
I need to be able to setup the parameters of the xquery as optional, like this i don’t need to evaluate every parameter in the xquery and can just pass the result of the xquery which is used for every parameter of the xquery.
“attribute()? refers to an optional attribute node”

The xquery function will then look like

declare function xf:test1($corId as xs:string?,
    $MessageType as xs:string?,
    $Status as xs:string)
    as element(ns0:EventObject) {
                <ns0:CorId>{ $corId }</ns0:CorId>
                <ns0:MesType>{ $MessageType }</ns0:MesType>
                <ns0:Status>{ $Status }</ns0:Status>

See the definition of the $corId and $MessageType, now they can be null!


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.

2 Responses to Oracle Service Bus, xquery and optional parameters

  1. Mike says:

    Hey I’m starting to work with the OSB and I read all about it, but I’m still failing.

    Could you please help me out on understanding what am I doing wrong…
    This is the situation I created a XQuery transformation, but I’m pretending to transform the whole $body variable.
    So I created *.xq file, and I tested only with the XML that I want to transform, and it works just fine.

    When I’m trying to add it to my proxy flow, I got the error

    ALSB Assign action failed updating variable
    And says that I’m doing an ArrayOutOfBound Exception.

    I just don’t get why this is happening…

    Could you please help me out on understanding the deep reason for this?

    Thanks in advance, do you think we could keep in touch by msn messenger?
    Mine is please do not hesitate on add me and start chatting.

    Once again thanks in advance and best regards!!

    Hope to hear soon from you…

    • Eric Elzinga says:

      Hi Mike,

      Can you email me the whole stacktrace, an example xml and the xquery your creating?
      You can send it to eric dot elzinga @

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: