Friday, September 11, 2020

12c SOA - How to call a shell script from BPEL using java embedding

 Implementation steps:

Step 1: Create a SOA project with empty composite.

Step 2: Create an XSD.

<?xml version="1.0" encoding="windows-1252" ?>

<xsd:schema xmlns:xsd="" xmlns=""

            targetNamespace="" elementFormDefault="qualified">

  <xsd:element name="Input">



        <xsd:element name="num1" type="xsd:string"/>

        <xsd:element name="num2" type="xsd:string"/>




    <xsd:element name="Output">



        <xsd:element name="result" type="xsd:string"/>





Step 3: Create a Synchronous BPEL service using that schema exposing as a web service.

Step 4: Create a Shell script file and saved in UNIX directory.




function add(){

sum=`expr $num1 + $num2`

echo "$sum"

return $sum


add $num1 $num2

Step 5 : Create a Java class(Right click on project⇾ New Galary⇾ Class(Java))

package invokeshellscriptproject;


public class Test {

          public String ShellScript(int i, int j) throws IOException


               String Var=null;


                Process P;



              String strParam = "bash /soashare/shellscript/ "

                                                     +i+" "+j+" ";

                                     P = Runtime.getRuntime().exec(strParam);

             System.out.println("here " + strParam);

             BufferedReader br = new BufferedReader(new InputStreamReader(P.getInputStream()));

            String line=null;

             while ( (line = br.readLine()) != null){

                        System.out.println("Output" + ">" + line);




                System.out.println("Output of Var:-"  +Var);

            int wait = P.waitFor();

            System.out.println("exit code: "+wait);


            catch (InterruptedException ie)


              System.out.println("exception caught");


            catch (Throwable t)




               return Var;



Step 6: Create a string variable Var1.

Step 7:  Drag and drop a Java embedding activity in the BPEL.


Test pocob = new Test();               


addAuditTrailEntry("Started From This Place");        

String i = ((oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/ns1:Input/ns1:num1")).getFirstChild().getNodeValue();    

int k = Integer.parseInt(i);        

addAuditTrailEntry("k Variable " +k);        

String j = ((oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/ns1:Input/ns1:num2")).getFirstChild().getNodeValue();           

int n = Integer.parseInt(j);        

addAuditTrailEntry("n Variable " +n);        

addAuditTrailEntry("Before Variable");        

String greetings = pocob.ShellScript(k,n);       

addAuditTrailEntry("After Variable");        

addAuditTrailEntry("Value:- " +greetings);        

setVariableData("Var1",greetings);     //Var1 is a variable created in BPEL process to contain result     

addAuditTrailEntry("After Assignment");        

}        catch(Exception io){                                                                          

      addAuditTrailEntry("Exception occured:"+io.getMessage());                                                          

      javax.xml.namespace.QName qName=new javax.xml.namespace.QName("","remoteFault");                                                                              bpelFault=new;               

      throw bpelFault;                                 





Step 8 : Import the java class in the BPEL. location used as packageName.ClassName

<import location="invokeshellscriptproject.Test" importType=""/>

Step 9 : Assign Var1 to result variable.

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...