Showing posts with label Oracle Service Bus (OSB). Show all posts
Showing posts with label Oracle Service Bus (OSB). Show all posts

Wednesday, January 23, 2013

For Each Action In OSB


I was replying to OTN  forum post regarding OSB For each action at :


So thought of writing it down to make it more clear.....

  1. I have made xml based proxy service.



2. I assumed the payload would be 

<request>
<CompanyCollection>
<company>
<name>name1</name>
</company>
<company>
<name>name2</name>
</company>
</CompanyCollection>
<CompanyCollection>
<company>
<name>name3</name>
</company>
<company>
<name>name4</name>
</company>
</CompanyCollection>
</request>

3. Assigned $body to companycollreq ( user defined variable) using Assign action
    
4. To keep a count of companycollection elemennt in the  request payload
   Assign count($companycollreq/request/CompanyCollection) to  companyCount
   


5. Now use a for each action to iterate over companycollection
    For each expression would like as:
   For Each variable companycoll   in ./request/CompanyCollection of variable  companycollreq 
   Indexed by variable currIndex with total count in variable  companycount


6.  Under Do 
      I am logging the companycollection element based upon the currindex count in for loop.
      This is important as we need to pass payload under iteration in for loop. 

     Assign $companycollreq/request/CompanyCollection[xs:int($currIndex)] in log action with annotation 
     of companycoll

Now Testing is done with above payload.


In Console logs obtained:



This is how for each action works.
Log action runs twice as companycollection count was two in payload passed.
In place of log action we can use service callout/Publish/Java callout .
The payload passed must contain currIndex as xquery predicates expression while passing value to other services being called from for loop.




Monday, February 6, 2012

OSB Clustering & Load Balancer

OSB clustering is being used to run multiple servers in parallel and to provide failover in case any managed server fails. Load Balancer is being used to effectively distribute the request payload among the running managed server in cluster depending upon the algorithm being used ( by default round robin ).

I will make use of Software Load Balancer (HTTP proxy servlet ) inbuilt in weblogic server as the implementation is being is done to simulate in clustering and load balancing in development or testing environment for the HTTP requests.
For production environment Hardware Load Balancer like BIG IP  ..are being used.

Architecture would be like :






 1. Domain Creation


    2.  Do Select Oracle Service Bus and not OSB for developer's

    3. 



    4. 



    5. 
    6. 

    7. Add managed server ip and port no in cluster address  (127.0.0.1:7201, 127.0.0.1:7301)


    8. Add only osb1 & osb2 to osbcluster


    9. Add the third managed server as Proxy server 



     10.

    11.Add all to machine 



    12.  Finished the setup and start admin server.

    13. Start managed server osb1


    14. Start managed server osb2


    15. Start managed server lb (load Balancer) 


    16. Go Service Bus Console and check the server health 


    17. Load a wsdl and make a proxy on it, add a log action( to check which managed server the request is going ) to capture the request payload and do reply with success 

    18. Go to weblogic console to check the clustering setup  : 


     Go to deployments under weblogic home, you will find the encircled app which is handling the load      balancing 



    19. Just enter 
                        http://[managed server ip address]:[managed server port no]/yourproxyurl?wsdl   
    You will find a wsdl published but have endpoint pointing to loadbalancer ip and port no 



    20. Now i have used soap-ui to test the load balancing 

    My request would be hitting load balancer  and load balancer would be handling the distrubution among osb1 and osb2 

    keep a look in the endpoint being hit in soap-ui 
    a.                      http://127.0.0.1:7101/default/PS_LoadBalancerTest

    First time the request has gone to osb1 as we can see in logs of osb1 managed server 

     b: I again tested it from soap-ui then the request would go to osb2 as we can see in logs of osb2 managed server (green)

    • If you shutdown admin server, still the request can be fulfilled by osb1 and osb2 . 
    • If any of osb1 or osb2 is down then request would be re-directed to running managed server either osb1 or osb2.
    • If you shutdown load balancer managed server (lb) then request won't be fulfilled you need to point your request to osb1 or osb2 by changing the endpoint                                                                                                http://[managed server ip address]:[managed server port no]/yourproxyurl.

    So the osb clustering and load balancing is achieved in simple manner !!








    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 !!