Sometimes it is easier and faster to carry out complex jobs using external scripts(e.g PERL)such a breaking a file into multiple files, record level validation of flat records etc. This blog details the technical information regarding how to execute PERL script in Java Embedding node under BPEL flow. It also receives response from PERL script for further validation. Please make sure that Perl is already installed on the server.
Let’s create a small Synchronous BPEL process called PERLExample.bpel which looks like following figure.
Declare a global simple string type variable as given below to capture the response from perl script.
<variable name="Variable_PerlResponse" type="xsd:string"/>
The Case condition for checking the response is
bpws:getVariableData('Variable_PerlResponse')='Success'
We will set the value of Varibale_PerlResponse in Java Embedding depending on the response received from Perl script execution.
Now let’s concentrate on Java Embedding (Java_Call_PerlScript) node which actually calls the Perl script. The Perl script takes a parameter(String called “Param1”) and returns a string response. Following screen shot gives you understanding of the java code written in Java embedding node. Make sure to include following java classes before the java embedding node in bpel flow source.
<bpelx:exec import="java.io.*"/>
<bpelx:exec import=" java.io.BufferedReader"/>
String cmdString has the location of Perl install, Perl script file with the location ( sample.pl in this instance )and paramONE as a parameter.
Create a file called sample.pl in data/int folder. Add the following perl code inside the file.
The Perl script will be executed at run time and based on the parameter value, it will return the appropriate string response back to the caller.
Deploy the BPEL process on any of the domain and test it using SOAP UI or BPEL Console.