RSS

Modifying namespaces in the Oracle Service Bus

07 May

The scenario here is that we have an Async JMS service and the original publisher is a legacy application. This pubishes it’s message in an XML-format. Which is cool, however there are no XSD’s available and the message contains no namespaces.

 <EDI>
 <E08_UNB>
 <SYNTAX_ID>UNOC</SYNTAX_ID>
 <SYNTAX_VERS>3</SYNTAX_VERS>
 <SENDER_ID>8714xxxxxxxxx</SENDER_ID>
 <SEND_QUAL>14</SEND_QUAL>
 <EMPTY1/>
 <RECIPIENT_ID>8714xxxxxxxxx</RECIPIENT_ID>
 <RECIPIENT_QUAL>14</RECIPIENT_QUAL>
 <EMPTY2/>
 <INTERCHANGE_DATE>120110</INTERCHANGE_DATE>
 <INTERCHANGE_TIME>1615</INTERCHANGE_TIME>
 <INTERCHANGE_REF>UNIQUEID123456</INTERCHANGE_REF>
 <TEST>0</TEST>
 </E08_UNB>
....

With the help of a professional tool (Liquid XML Studio) we are able to generate an XSD from large numbers of the XMLs we received from the legacy application. Next step is creating a decent service contract (WSDL/XSD). When finished the primary subscriber of our async. service receives the WSDL/XSD datamodel from us which it imports.

However our subscriber requires a exposed namespace in the message it receives. (we tried using configuring hidden/local namespace qualification in the XSD but these fail during import). So the message would need to look something more like this:

<soapenv:Body>
<e08:EDI xmlns:e08="http://www.somecompany.com/schemas/EDIXML/E08">
 <e08:E08_UNB>
 <e08:SYNTAX_ID>UNOC</e08:SYNTAX_ID>
 <e08:SYNTAX_VERS>3</e08:SYNTAX_VERS>
 <e08:SENDER_ID>8714xxxxxxxx</e08:SENDER_ID>
 <e08:SEND_QUAL>14</e08:SEND_QUAL>
 <e08:EMPTY1/>
 <e08:RECIPIENT_ID>8714xxxxxxxx</e08:RECIPIENT_ID>
 <e08:RECIPIENT_QUAL>14</e08:RECIPIENT_QUAL>
 <e08:EMPTY2/>
 <e08:INTERCHANGE_DATE>120110</e08:INTERCHANGE_DATE>
 <e08:INTERCHANGE_TIME>1615</e08:INTERCHANGE_TIME>
 <e08:INTERCHANGE_REF>UNIQUEID123456</e08:INTERCHANGE_REF>
 <e08:TEST>1</e08:TEST>
 </e08:E08_UNB>

We want to use Oracle Service Bus as passive intermediate as much as possible. So we use a simple Rename Action of the Oracle Service Bus.

This does the trick because all elements ( //* ) in variable body are now renamed to the new namespace we require.

update May 9th: not adding namespace, but removing them

If you need to do it the other way around, like removing the namespaces from an XML message. I haven’t been able to find a way to this with the Rename Action of the Oracle Service Bus. However there is a simple XSLT stylesheet you can use. (this code is not mine but found it on the web once upon a lifetime in a galaxy far far far away. I’ve been using it for some time, but sadly don’t know who to give credits)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output method="xml" indent="no"/>

<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

Use a replace action on the message $body and your namespaces will disappear like ninjas in the night. ;)

About these ads
 
6 Comments

Posted by on 07-05-2012 in Oracle, OSB

 

Tags: ,

6 responses to “Modifying namespaces in the Oracle Service Bus

  1. Maverik

    04-12-2012 at 23:09

    Nice Post, it really saved my time

     
  2. KK

    14-02-2013 at 19:14

    Lifesaver…Thank you!!!

     
    • ad

      23-05-2013 at 21:38

      Cant’ agree less!!

       
  3. Dipayan

    02-04-2014 at 13:01

    can you let me know how to Remove newline character/white space from xml using xslt or xquery transformation,Means all the elements will come in a single line.

     
  4. alhenk

    16-10-2014 at 09:56

    ./descendant-or-self::* instead of .//*
    would be better

     

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

 
Follow

Get every new post delivered to your Inbox.

Join 354 other followers

%d bloggers like this: