Friday, April 30, 2010

How to copy multiple input variable to multiple output variable using Transformation activity in BPEL

In last exercise we have created a business process for getting multiple order.

In this exercise we will see how to assign these multiple input to multiple output

variable.

As a though process what should be an ideal way of doing this.

We should have counter which could count the number of input variable and then we should use a loop where in we should assign the variables as an array to output variable such as

input[i] to output[i]

where in i is a variable which varies from zero to (n-1)

n is the count of nodes.

Yes it is a correct approach but it can also be done through transform activity in BPEL.

Transform activity is basically an xsl transformation.

Just have a look in my earlier post

Learning XML and
Transforming XML document using XSL transformation

XSL is a style sheet language.It is basically a XML language which transforms the raw xml document in to user defined format.We can include html tags also within it for front end presentation.

We will use the previous BPEL process itself in this exercise also.

Drag and drop a transform activity in between the receive and callbackClient.

Now in the source variable choose input variable payload and in the target choose output variable as payload.



Click on create button as shown to create a transformation

Transformation1.xsl and say apply ,it will open up a transformation page.

Now go to the design of the transformation.

Drag and drop for-each XSLT from XSLT construct in component pallete in the list of element.

Then map the input to output list and each input element to each output element each.

Save the project.

So it should appear something like this



We will try to understand more on this by looking at its source code.So here is the source code.

The XSL element can be used to select every XML element of a specified node-set.So as you can see in the xml document we are designing the output variable which does the following action.

For each element of arpit:BPELProcess1ProcessRequest/arpit:listElement

copy the value of arpit:itemID and arpit:itemValue to the corersponding output variable.

The element can be used to extract the value of an XML element and add it to the output stream of the transformation

I know it is not that easy to understand but i will suggest to get some idea of XSL and then you will be able to get it easily.





<xsl:template match="/">
<arpit:BPELProcess1ProcessResponse>
<xsl:for-each select="/arpit:BPELProcess1ProcessRequest/arpit:listElement">
<arpit:listElement>
<arpit:itemID>
<xsl:value-of select="arpit:itemID"/>
</arpit:itemID>
<arpit:itemValue>
<xsl:value-of select="arpit:itemValue"/>
</arpit:itemValue>
</arpit:listElement>
</xsl:for-each>
</arpit:BPELProcess1ProcessResponse>
</xsl:template>

Once done save your project and deploy it.

Now try to invoke the BPEL process.I invoked it with the following three inputs



and i can get the following output



This is just an example i have used to show you how you can use this transform activity.BAsed on your business requirement you can make the changes and design your process.

By the way did you guys noticed that the output what we get is not ordered it is just displayed in the same order as we have provided the input.

So obviously one question will come in to your mind that is it possible to sort the output variable based on some element.Yes that is possible and we will see in our next section how it can be done.We will use the same BPEL process for our understanding.

2 comments:

Raj said...

Hi Arpith,
Thanks you for Sharing such examples with us.

I have one issue in SOA11g, I am not able to sending the XML data to a .asp page through Java_Embedded activity. Is it only the way or is there another mathod to post xml data to .asp page.

Thanks,
Nagaraju

Mikku said...

You can use the post method to post your xml data to asp page.
If you could explain me your business functionality may be i can suggest you some workaround