Advanced reporting in Oracle Service Bus

Posted by [email protected] on Oracle Blogs See other posts from Oracle Blogs or by [email protected]
Published on Thu, 17 Jun 2010 20:53:42 +0100 Indexed on 2010/06/17 13:24 UTC
Read the original article Hit count: 399

Filed under:


Reporting in OSB is useful, it allows you to audit message going through OSB. The service bus console allows you to view the content that you reported.

To report data you simply use the Report action in your proxy. The action itself is rather straightforward. You specify the content to report ($body for example), an optional key for easier search (for example the id of the record) and that's it.

Sometimes though, what you want to is a bit more complicated. I recently had a case where the key was built from the message type (XML) and the id of the message. Seems quite simple but the id could be any element anywhere in the message depending on its type.

This could be handled by 'if' statement but adding new cases would mean changing the proxy service and if you have lots of message types this can get boring so I wanted the solution to be as dynamic as possible (read "just change a configuration file and that's it").

The following entry details how you can make this dynamic in your proxy by using XQuery/XSLT.

 

First step the XQuery

We're going to use an XQuery to make the mapping between the XML message type and the location of the identifier in it.

We assume here that the message type is the first node of the input XML and use a rather simple Xpath to find the identifier.

 The XQuery looks like this for two messages :

<reportmapping>

                <row>

                               <logical>messageType1</logical>

                               <type>MT1</type>

                               <reportingreferencelocation>//customID</reportingreferencelocation>

                </row>

                <row>

                               <logical>messageType2</logical>

                               <type>MT2</type>

                               <reportingreferencelocation>//theOtherIDLocation</reportingreferencelocation>

                </row>

 

</reportmapping>

 

Second step the XSLT

To get the identifier value of the dynamic path, we're going to use an XSLT transformation. This XSLT takes an XML parameter as input which contains our xpath (coming from the previous XQuery).

The XSLT looks like this :

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan">

              <xsl:param name="PathToNode"/>

              <xsl:template match="/">

                            <IDVALUE>

                                          <xsl:value-of select="xalan:evaluate($PathToNode/reportingreferencelocation)"/>

                            </ IDVALUE >

              </xsl:template>

</xsl:stylesheet>

(note the use of a xalan function here. Xalan is the XSLT processor used in weblogic server)

 

Last step, the proxy service

We're now going to wire everything in the proxy service. First we assign the XQuery to a variable.

assign1 - xquery.PNG

We then get the entry in the XQuery corresponding to the record we're treating.

assign2 - getMessageNode.PNG

We're then extracting the id of the message using the XSLT transformation

assign3 - getIDViaXSLT.PNG

Final assign is to built the final variable that will be used as the reporting key.

assign4 - createKey.PNG


The report action is then called with this variable.

report1 - report.PNG

Everything is setup. We're now ready to test.

 

Testing the solution

Using the test console, we're sending our first XML ...

<messageType1>

                <sender>test console 1</sender>

                <customID>ID12345</customID >

                <content>

                                <field1>value of field 1</field1>

                </content>

</messageType1>

 

... and a second one of another supported type


<messageType2>

                <header>

                                <theOtherIDLocation >ID67890</theOtherIDLocation >

                </header>

<body>

                               <data>Test data</data>

                </body>

</messageType2>

 

Reporting result is :

result2.PNG

 

Conclusion

Report is done as expected. Now if a new message type must be supported we only have to modify the XQuery and nothing at the proxy service level.

 

Sample project attached to this entry.

sbconfig-dynamicReport.jar


 

© Oracle Blogs or respective owner