we will now see a use case on how to use a java embedding activity in our BPEL process.
Just create a new application and within that application create a new BPEL process make this process asynchronous bpel process and provide some logical name to it.
now select Process activities in component pallete and drag and drop a assign activity in between the input and call back client as below
now double click on assign activity and create a sopy operation.Assign the input variable to the output variable as below
now drag and drop a java activity and place it after the assign activity.
Now we will try to get the value of the input variable through java coding.
Since bpel is written in xml langauge all the input and output variables are called as elements.
/* accessing a variable within the complex type */
Element inputValue = (Element)getVariableData("inputVariable", "payload","/client:JavaEmbedProcessRequest/client:input");
This command is used to get the input value.
here inputValue is a temporary element to store the value of the input that we will pass from the console.
getVariableData is a predefined function to get the data stored in the variable.
now we will check how we have reached to this command
"inputVariable", "payload","/client:JavaEmbedProcessRequest/client:input"
Just go to your assign activity and edit the copy operation.
now expand it fully to get see the root input.
Now as you can see here we have first inputVariable
then payload
then copy the xpath
the value we got needs to be converted to string
so we will use the code
String inputVal = inputValue.getTextContent();
Further if we want to add the entry to the audit trail in the bpel console we use the following command
addAuditTrailEntry("Value Entered is : " + inputVal);
i will show the result where does it reflect in audit trail.
Next is setting the value to the output variable
setVariableData("outputVariable", "payload","/client:JavaEmbedProcessResponse/client:result", inputVal);
Again we will use the same concept to reach to the output variable.
so in all i am using the following command in my java embedding
System.out.println("Hello, World") ;
Element inputValue = (Element)getVariableData("inputVariable", "payload","/client:JavaUsageProcessRequest/client:input");
String inputVal = inputValue.getTextContent();
addAuditTrailEntry("Value Entered is : " + inputVal);
setVariableData("outputVariable", "payload","/client:JavaUsageProcessResponse/client:result", inputVal);
the logic of this program is to get the input value and assing it to output variable.
and my activity is looking something like this
This is not it we need to import some packages also.So go to the source of the BPEL and add the following statments
<bpelx:exec import="java.util.*"/>
<bpelx:exec import="java.lang.*"/>
<bpelx:exec import="java.rmi.RemoteException"/>
<bpelx:exec import="javax.naming.NamingException"/>
<bpelx:exec import="org.w3c.dom.Element"/>
Now save the project and deploy it.Now try to run the program and check the output.
The assign activity is giving the following output
<outputVariable>
- <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
- <JavaEmbedProcessResponse xmlns="http://xmlns.oracle.com/JavaUsage">
<result>
arpit
</result>
</JavaEmbedProcessResponse>
</part>
</outputVariable>
If you click on java embedding here you will get the value that we have provided using audit trail so it will be
Now if you will check the callback client we will get the following output
<outputVariable>
- <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
- <JavaEmbedProcessResponse xmlns="http://xmlns.oracle.com/JavaUsage">
<result>
Arpit rahi
</result>
</JavaEmbedProcessResponse>
</part>
</outputVariable>
As you can see the output here is Arpit Rahi because that is the value we have provided when we invoked the process.In the assign step we assigned arpit to the output variable but in java embed activity we are assigning the input variable to the output variable so we got the output as Arpit rahi
2 comments:
Great help......
understood the concept really very well
Thank you and very good explanation
Post a Comment