Monday, January 9, 2012

Adding namespace to XML Structure

I came across a situation while doing CSV to XML transformation, the MFL action in OSB transforms CSV to XML or vice -versa but the resulted XML structure does n't have a namespace added to it.

Namespace is required while doing service orchestration (by using Service Callout or Route action ).
There are two ways u can add namespace to xml structure .

1. Make a XSD of the xml structure and use Xquery transformation selecting newly created xsd of non-namespace as Source and in Target select as xsd/wsdl element which u want as result.

2. We can use xquery to add a default namespace to xml structure.(which is obtained using mfl action and storing the result in variable named InputRequestXmlBody
                         

xquery version "1.0" encoding "Cp1252";
(:: pragma parameter="$noNamespaceXML" type="xs:anyType" ::)
(:: pragma parameter="$namespaceURI" type="xs:string" ::)
(:: pragma type="xs:anyType" ::)
declare namespace xf = "http://tempuri.org/Resources/XQueries/addNamespace/";

declare function xf:addNamespaceToXML($noNamespaceXML as element(*),$namespaceURI as xs:string) as element(*)
{
element {fn:expanded-QName($namespaceURI,fn:local-name($noNamespaceXML))}
{
$noNamespaceXML/@*,
for $node in $noNamespaceXML/node()
return
if (exists($node/node())) then xf:addNamespaceToXML($node,$namespaceURI)
else if ($node instance of element()) then element {fn:expanded-QName($namespaceURI,fn:local-name($node))}{$node/@*}
else $node }
};

declare variable $noNamespaceXML as element(*) external;
declare variable $namespaceURI as xs:string external ;
xf:addNamespaceToXML($noNamespaceXML, $namespaceURI)


We can use replace action then to add namespace to xml structure .
                               

So XML Structure like this :




<Transaction>
    <MemberDetails>
        <CashMemoNumber>CashMemoNumber</CashMemoNumber>
        <Date>Date</Date>
        <Time>Time</Time>
        <ShopCode>ShopCode</ShopCode>
        <PrivilegeCustomerCode>PrivilegeCustomerCode</PrivilegeCustomerCode>
        <Country>Country</Country>
    </MemberDetails>
</Transaction>


would end up like this :
<req:Transaction xmlns:req="http://in.abhinav/schema/request">
<req:MemberDetails>
<req:CashMemoNumber>CashMemoNumber</req:CashMemoNumber>
<req:Date>Date</req:Date>
<req:Time>Time</req:Time>
<req:ShopCode>ShopCode</req:ShopCode>
<req:PrivilegeCustomerCode>PrivilegeCustomerCode</req:PrivilegeCustomerCode>
<req:Country>Country</req:Country>
</req:MemberDetails>
</req:Transaction>

Happy Flows !!

Sunday, January 1, 2012

Split Join - OSB

I was working on requirement to call multiple service in parallel to improve the performance count .
But the split join works only on WSDL Operation means if you are calling different type of services like Messaging based, XML based u need to create a wsdl to support your split join  ...
I need to write the final end xml response of split join to file system location using file transport in non -xml format (CSV).
But my excitement came to sudden end when i could not locate  MFL transformation action in split join design pallate 



The next problem with split join is that there is not any publish action to call your asynchronous processes (for example: Writing a file)...
But there is always a work around ...
1. Made xsd and wsdl for the final end xml response .

                     
                                    

2. Made a proxy service local transport based on wsdl created above .
3. In message flow of abobe local proxy service use a publish action to call my File Write Business Service.                                                                             
4. In request actions of Publish actions use MFL Transformation Action to convert final end xml response to non- xml(CSV)  
                            
5.So as my requirement was to write the final end response to a file through splt join, use a Invoke service   action to call the above made local proxy that will call your File Write Business Service .
                                          


So have a happy Split Join !!