Advertisements
RSS

using CDATA in the Oracle Service Bus

17 Feb

>In our project when an error occured the following Error structure must be returned to the service consumer.

<ns1:Messages>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>99999</ns1:Code>
    <ns1:Description>someDescription</ns1:Description>
  </ns1:Message>
<ns1:Messages>

In a case of a validation error the consumer would receive the following message where description is a concat of $fault/ctx:errorCode and $fault/ctx:reason

<ns1:Messages>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>99999</ns1:Code>
    <ns1:Description>BEA-382505 - OSB Validate action failed validation</ns1:Description>
  </ns1:Message>
<ns1:Messages>

The limitation here is off course that the real description (the $fault variable) is not visible for the service consumer. Since the $fault contains an XML-structure we need a mechanism as CDATA to encapsulate this in the response message.

The following blogpost is a simplified result of the actual project, but should give a general idea:

So we used the above solution with a Replace action in the common Error Handler. In our data model the element is repeating so we made a choice to add a second element.

<ns1:Messages>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>99999</ns1:Code>
    <ns1:Description>{$fault/ctx:errorCode/text()} - {$fault/ctx:reason/text()}</ns1:Description>
  </ns1:Message>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>{$fault/ctx:errorCode/text()}</ns1:Code>
    <ns1:Description>{fn-bea:serialize($fault/ctx:details)}</ns1:Description>
  </ns1:Message>
<ns1:Messages>

This will result in a result like:

<ns1:Messages>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>99999</ns1:Code>
    <ns1:Description>BEA-382505 - OSB Validate action failed validation</ns1:Description>
  </ns1:Message>
  <ns1:Message>
    <ns1:Status>E</ns1:Code>
    <ns1:Code>BEA-382505</ns1:Code>
    <ns1:Description><![CDATA[<ctx:details xmlns:ctx="http://www.bea.com/wli/sb/context"><ns0:ValidationFailureDetail xmlns:ns0="http://www.bea.com/wli/sb/stages/transform/config"><ns0:message>Expected element 'someRequiredElement@http://www.rubix.nl/someNamespace' </ns0:ValidationFailureDetail></ctx:details>]]></ns1:Description>
  </ns1:Message>
<ns1:Messages>

The bea-serialize function helps us to transform an XML input to a string output. Apparently there has been an update to the XPath Expression Editor in the OSB since the editor in 11.1.1.3 now automatically sets the CDATA definition.

In the past (the AquaLogic days) you explicitly had to define this with a function as:

fn-bea:serialize(xs:string(fn:concat("<![CDATA[",fn-bea:serialize($fault),"]]>")))

Anoter solution would be to use XQuery in the error handler and the use of a namespace stripping function (as described here by Marc Keldermann) to clean-up the result of the $fault/details.

Advertisements
 
1 Comment

Posted by on 17-02-2011 in Oracle, OSB

 

Tags: , ,

One response to “using CDATA in the Oracle Service Bus

  1. archenroot

    16-02-2015 at 00:12

    Reblogged this on Black Hole Of My Memory.

     

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: