Friday, June 19, 2015

Oracle OSB 12c: For each loop in oracle osb

Today I was working on one of the usecase in which I required to loop incoming records and pass each record to a service callout and send back response for each request as a collection. Well using foreach in OSB is not a big deal but yes due to lack of information sometimes you can stuck and take hours or day to resolve the issue. In this post I will explain a simple example in which I am passing the collection of names (FirstName and SecondName) and send back response after concatenate first name and second name as a full name. eg.

Inputs:

               <v1:Request xmlns:v1="http://xmlns.codeconfuse.com/XSD/foreach/V1">
<!--Zero or more repetitions:-->
<v1:PersonList>
<v1:FirstName>Anshul</v1:FirstName>
<v1:LastName>Mittal</v1:LastName>
</v1:PersonList>
<v1:PersonList>
<v1:FirstName>code</v1:FirstName>
<v1:LastName>confuse</v1:LastName>
</v1:PersonList>
</v1:Request>

Outputs:

              <tns:Response xmlns:tns="http://xmlns.codeconfuse.com/XSD/foreach/V1">
<Output>Anshul Mittal</Output>
<Output>code confuse</Output>
</tns:Response>


I have created two pipelines i.e. ContactPP and ForeachPP.

ContactPP

Below picture is the ContactPP pipeline

 Here in the Response Pipeline, inside replace activity used transformation to concat the Incoming payload (FirsName and SecondName) to outgoing payload(FullName).





Below is the snapshot of source of xslt:


<xsl:template match="/">
    <ns0:OutputResponse>
      <ns0:FullName>
        <xsl:value-of select='concat (/ns0:InputRequest/ns0:FirstName, " ", ns0:InputRequest/ns0:SecondName )'/>
      </ns0:FullName>
    </ns0:OutputResponse>
  </xsl:template>

ForeachPP

Below picture shows the ForeachPP pipeline:



Inside Request Pipeline, drag and drop the For Each activity and also drag and drop assign activity to set the value of Input parameter of service callout and output parameter as shown below:


For Each Activity

Configure for each activity as shown below:


Configure Service Callout as shown below:


Now set the input parameter ContactReq inside the assign activity as below:



Now transform the output of this service callout and save it to $TmpVar. This is similar to following

$TmpVar = $TmpVar + $ContactResp



Now we have the response of service callout in $TmpVar, and we need to transform into actual service output. This we can do it in Response Pipeline

Now in the first assign transform the data as shown below:


And save it to $TmpVar again. And in the next assign add the soap envelope to the out payload as below:

done, deploy and test.

Test Result




Download the project --> com.codeconfuse.foreach.zip

I hope this post helps you in understanding for each concept in OSB. There must be some other easy ways to do it, well I tried to keep it simple but if you have much better and easy way then please share it.

2 comments:

  1. Not able to download the zip.

    ReplyDelete
    Replies
    1. Hi,

      The link is working fine. I have shared again, please check.

      Thanks,
      Anshul

      Delete