Friday, April 23, 2010

BPEL 11g – Hello World Tutorial/Sample



Goal: Create a Asynchronous BPEL Process which will invoke a Web Service passing some name. The Web Service will return the output to the BPEL with Hello prefix to the name passed.
First of all you need to develop a WebService which can be invoked using a partner link in BPEL process.
Developing a WebService using Annotations:
1.       Create a Java Project in Eclipse (or any other IDE)
2.       Create a class TestWS with a method sayHello which will take a String as input and add Hello to string and return the new string in output.
3.       Add annotation @WebService to class and @WebMethod to method
4.       Write simple piece of code in main method which can be used to publish the web service. Note that the port used should be free and no service should be running on the port.
Endpoint.publish("http://localhost:7002/TestWS", new TestWS());
5.       Now execute the main method. You will have to add weblogic.jar in the classpath.


6.       Once executed goto url => http://localhost:7002/TestWS?wsdl  to get the WSDL. Save the WSDL as TestWS.wsdl on your PC.
7.       WSDL will have the link to schema generated i.e. http://localhost:7002/TestWS?xsd=1. Save the XSD as TestWS.xsd on your PC.
Developing BPEL process:
1.       Create a project with a default asynchronous process in JDeveloper
2.       Copy the TestWS.wsdl & TestWS.xsd in the project
3.       In the TestWS.wsdl modify the schema import to point to TestWS.xsd
4.       Open the bpel design view
5.       In the partner link swim lane right click and select “Create Partner Link”
6.       In Create Partner Link dialog box choose TestWS.wsdl
7.       Click Yes to dialog for generating Ref WSDL
8.       Selected the default role in Partner Role drop down
9.       Place an Invoke node between receiveInput and callbackClient node. In the Invoke node choose partner link as TestWSService. Choose operation as sayHello. Create input and output variable by clicking on ‘plus’ button.
10.   Place an Assign node in between receiveInput and Invoke node. In Assign node copy from input variable of the BPEL to input string attribute of the input variable for sayHello call.



11.    Save the project and deploy on server by right clicking on project.


Testing BPEL process: 

1.       Go to em console
2.     Select the project under soa-infra folder.



3. Click Test button.
4. Select operation as process (operation for launching BPEL), give input in input arguments as Abhishek and click on Test Web Service button.



5. Select the Project under soa-infra list. You will find a new instance created (Instance ID 2002 in my case).
6. Select the instance link to open the message flow



7. Click on the BPEL process (BPEL Process1 in my case). You will find audit trail and flow tabs.
8. Click on Flow tab to open the message flow. 



9. Click on Invoke node to see its input and output.


I hope the post will be useful for new developers of BPEL.

1 comment: