Let's use xs:anyType for the xml messages. Now I don't know in the esb the structure of the xml messages. The solution is to make a main router where we use the filters and a specific xsl to extract anytype and map this to the right xsd in the next router, This router maps the data with a xsl to the db adapter.
The example main schema looks like this.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPUnb5UecBKVrUHiubAJQjm7SXplXmm6NjX3WJMArvV6XMeaxMjI1q4ZelgOF9lN_vCtaYQWdXC5qNvIQSKDafnzH94zPTIYUxEyQjv2tK__BxId3-xf13_rPn7-0ZzJLnrA6xQRlGqI8/s320/esb_anytype_1.jpg)
Here are two xml messages examples.
<ns1:Message xsi:schemaLocation="http://ordina.nl/esb message.xsd" xmlns:ns1="http://ordina.nl/esb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:RunID>100</ns1:RunID>
<ns1:MessageType>A</ns1:MessageType>
<ns1:Data>
<MessageA>
<Text>this message A</Text>
</MessageA>
</ns1:Data>
</ns1:Message>
<ns1:Message xsi:schemaLocation="http://ordina.nl/esb message.xsd" xmlns:ns1="http://ordina.nl/esb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:RunID>200</ns1:RunID>
<ns1:MessageType>B</ns1:MessageType>
<ns1:Data>
<MessageB>
<Text>this message B</Text>
<SubMessageB>
<Text>this message B</Text>
</SubMessageB>
</MessageB>
</ns1:Data>
</ns1:Message>
Let's do this in the 10.1.3 esb. I use for this example file adapters. Make a esb project and start by dragging the file adapter to the esb file. The file adapters reads the xml's in a directory and this file adapter is based on the anytype message schema.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM4bzNKXs3_lLvBO0zRMoW6Rd2EF4bQyVWn0mkwbx0k-lvsfXHjXzEhwYD1CicWJLRq-Qv2dP1io2sqJCa8SPZWZz00aJ_dzBUu8d3kKhHCDI3HWwIJUhBQevK5GHmyg1zORKwzruY9Sc/s320/esb_anytype_2.jpg)
Now we need to make a xsl where we extract the anytype to a new xml. This is how the xsl looks.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:n="http://ordina.nl/esb" xmlns="http://ordina.nl/esb">
<xsl:template match="/n:Message">
<xsl:for-each select="n:Data">
<xsl:copy>
<xsl:attribute name="RunID"><xsl:value-of select="//n:RunID"/></xsl:attribute>
<xsl:attribute name="MessageType"><xsl:value-of select="//n:MessageType"/></xsl:attribute>
<xsl:copy-of select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Let's apply this xsl to the two mail handling messages and generate ( I use Altova xmlspy) two new schema's on the new xml's, we need these schema for the specific routers. Now we can make the outgoing message A file adapter, use the new schema message A and make a messageA Router too. Use for this router also the new schema message A. Make a routing rule between the message A router and the message A file adapter.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaYlE7dge4wwe2xL4uOdPekcMBYXbDDAYUoLLKuv2RbYKBu4-9v41M5iLtLMl9kOA539b9EGjMdiGrSOaIIGVU_NKVtp8BkclqHfk4woYP0sZX_Kv9dxLKNUSAOtxAFANedx2l8D62N8U/s320/esb_anytype_3.jpg)
We can do the same for the xml message B.
Now we have to make the routing rules on the main router. First we set the filters. We test the ns1:MessageType element if it equals A or B.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvSsbaFUzbUjZ1Fcs-5hWfQUcBg_dyGqaHoNFZW7qpISN1pX43dCtmujDV2BCHrAgO1w-1Z7VgArzVZHtkY4xh9U3saS12v0lobKc9_EcYJ4sQ8kRT_FrBTB135xlpF-vXDijogydpQW4/s320/esb_anytype_4.jpg)
Then we make a xsl where we add the namespaces of the above xsl and replace the standard xsl:template with the xsl:template of the above xsl. See picture below for the xsl. This xsl can we use by all the main router rules.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhqa4syCkVheyr5DA8DW0OucvSlAXQwk3giYMKNVZqpHFfTRTcWuj9x5UlCKfXJqXydt63KbtqX0Fs-Rh7RCQnKsa0qpuV3W0vJh-OHwpvbbi4Y3qjrsK4lw9Uoa41fMJWFnRG-6gucAI/s320/esb_anytype_4_2.jpg)
The esb diagram looks like this, you can deploy it to the esb server and put xml message A or message B in the In folder. The esb puts now the messages in the right Out folder.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCgOoEnXIdY2TCOGAGcUiRH1AYsLBx_czO9VMX9nNc2nPSW-b6CcFkntx7xeHMKOWipOjmcGT7t4rvoaeFRzOlBIgqgruZRzJuKPd8kpuM-uTMPr69J5JeEg5lK-vOSWNKvraNyW5qsZo/s320/esb_anytype_5.jpg)
Here you can download the esb example project
No comments:
Post a Comment