Tuesday, June 23, 2015

Oracle SOA: How to surround data around fields in file adapter

I was working on one of the usecase in which we need to surround single quote(') around the fields in output file during write operation in file adapter. For example:

Input:

<QuoteFileInput>
    <QuoteFile>
        <F1>A<F1>
        <F2>B<F2>
        <F3>C<F3>
        <F4>D<F4>
    <QuoteFile>
<QuoteFile>
        <F1>E<F1>
        <F2>F<F2>
        <F3>G<F3>
        <F4>H<F4>
    <QuoteFile>

<QuoteFileInput>

Output:








Well the main logic for this is in the nxsd schema file that file adapter creates. I created a simple soa application, and the composite and bpel looks like below




In the transformation, I simply mapped the input parameter of request to file adapter input parameter.

here is my nxsd schema file:





you can download the soa project from here click here

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.