Wednesday, 27 December 2017

BPEL - Dynamic XSLT file selection and multiple inputs to XSLT

Hey guys,


In this post, I am explaining the steps to Dynamically select the XSLT files in BPEL process and pass on the multiple parameters to XSLT file as input.

This will need below implementation at High level :
1. DVM Lookup for dynamic XSLT file selection
2. Use of  ora:processXSLT() function to process XSLT and assign result to variable.


Implementations Steps :

1. Create SOA project, with BPEL process
2. Add the services and reference as per requirement
3. In the BPEL process, use assign to lookup DVM for XSLT file name.
4. Use another assign to execute the ora:processXSLT() function and assign result to variable.

Things to keep in mind while implementing ora:processXSLT() :

XSLT is processed in BPEL using the method: ora:processXSLT categorized under BPEL XPath Extension Functions.
The input parameters (signature) for the method is as defined by Oracle:

Signature:

processXSLT('template','input','properties/parameter'?)

Arguments definition:

template - The XSLT template or XSLT file Name with location (If using files from MDS)

input - The input data to be transformed

properties - This is optional. Additional inputs or parameters as defined in XSLT files.


e.g. ora:processXSLT('Transform_data.xsl', $inputVariable.body, bpws:getVariableData('metaDataVar'))

However, in our case, we are looking to dynamically select the XSLT file from DVM lookup, so the example will be like this

ora:processXSLT($xsltLocVar, $inputVariable.body, bpws:getVariableData('metaDataVar'))

Here Variable xsltLocVar already has XSLT file name fetched from DVM lookup.


The properties/parameter translated into parameter constructs of the XSLT and can be referenced within the XSLT scope. The property needs to be defined in a specific structure as mentioned below -


The definition of the schema contains for the following details:

<?xml version="1.0" encoding="windows-1252"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:p="http://schemas.oracle.com/service/bpel/common" xmlns="http://schemas.oracle.com/service/bpel/common" targetNamespace="http://schemas.oracle.com/service/bpel/common" elementFormDefault="qualified">
<xsd:element name="parameters">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="item" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="value" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>




Consider this schema structure for any variable.
A variable will always have a name and a value. eg. a variable x = 100. In case the name of the variable is "x" and the value is "100".

So the parameter variable needs to be set for all the variables which needs to be passed to the XSLT.

Define the XSD in your BPEL project. Create a variable of type global in the BPEL project with name "metaDataVar" (the name can be anything)

Lets assume, in one variable "user" we have the username and in another variable "password" we have the password for an account stored. The final payload needs to be constructed which should have both the values.

In your BPEL, create a copy operation and provide an expression to the "name" element of the variable "params". May be use the expression builder to assign a value of "userName" to the element "name".

Similarly assign "passValue" to the element "name" of the "params" variable and the xpath expression to the value to instantiate the value of the params element.

Now, come down to the XSLT where these elements needs to be accessed. Use XSLT construct to define the param as depicted below:

<xsl:param name="userName"/>
<xsl:param name="passValue"/>

Now the values of the variables can be accessed using a simple expression "$userName" and "$passValue"

Friday, 13 October 2017

Get Set Properties in BPEL header / Passing Properties from 1 BPEL and receiving in another BPEL using header

Hi Guys,

I am writing this post, because one day, I wanted to pass few properties from my bpel, which I needed in 2nd bpel process. I coudn't find any blogs with full details. There were many with partial details about how to do it.


Use Case :
Properties of 1st bpel needs to be passed to 2nd bpel. These could be timestamp, any unique ID genrated in bpel 1, or File name or location in case of file/ftp adapter service etc.


Implementation :
There could be many ways, how you do this, however one of the simplest way to achieve this is using the properties. High level steps :
1. Add the properties while invoking the reference Paternelink
2. Fetch the properties from received payload.

Note : The Syntax is different for bpel 1.1 and bpel 2.0, Most blogs has this for bpel 1.1 in their posts. This post is based on bpel 2.0


STEP 1 :
Add properties in your Invoke.



Source code view--




STEP 2:
Add properties in your receive activity of 2nd bpel


 Source code view--




Thats all.


Testing, screens from the Flow trace.

1st bpel invoke --



2nd bpel receive --



It is not only INVOKE and RECEIVE activities where you can use , but others supported activities are listed below with their format:

BPEL 2.0 bpelx Extensions Syntax
The following example shows bpelx extensions syntax in BPEL 2.0:
<invoke ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:fromProperties>
  <bpelx:toProperties>?
    <bpelx:toProperty name="NCName" .../>+
  </bpelx:toProperties>
</invoke>

<receive ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:toProperties>
</receive>

<onEvent ...>
  <bpelx:fromProperties>?
    <bpelx:fromProperty name="NCName" .../>+
  </bpelx:fromProperties>
</onEvent>

<reply...>
  <bpelx:toProperties>?
    <bpelx:toProperty name="NCName" .../>+
  </bpelx:toProperties>
</reply>

<reply ...>
  <bpelx:toProperties>
    <bpelx:toProperty name="NCName" .../>
  </bpelx:toProperties>
</reply>
Note the following details:
  • The toProperty is a from-spec. This copies a value from the from-spec to the property of the given name.
  • The fromProperty is a to-spec. This copies a value from the property to the to-spec.



BPEL 1.1 bpelx Extensions Syntax

The following example shows bpelx extensions syntax in BPEL 1.1:
<invoke ...>
  <bpelx:inputProperty name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
  <bpelx:outputProperty name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</invoke>

<receive ...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</receive>

<onMessage...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</onMessage>

<reply ...>
  <bpelx:property name="NCName" expression="string" variable="NCName"
 part="NCName" query="string"/>*
</reply>  


Refer Oracle Doc for more detail, available at -- http://docs.oracle.com/middleware/12213/soasuite/develop/GUID-33A38C1A-38A6-473B-9FEA-D3164AD7A118.htm#SOASE87180