Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Java

An Example Of BPEL invoking WebService

4.67/5 (3 votes)
27 Feb 2009CPOL2 min read 90.6K   1.4K  
The example below shows how to invoke an existing/external web service in BPEL. This example uses Eclipse, Eclipse BPLE designer Plug-In and Apache ODE.

Introduction

The example below shows how to invoke an existing/external web service in BPEL. This example uses Eclipse, Eclipse BPLE designer Plug-In and Apache ODE.

Background

Using the Code

There are two parts in this article:

  • Part A: Prepare a Web Service
  • Part B: Invoke this web service in BPEL

Part A: Prepare Web Service

  1. Create a web service “DoSomethingWebService”, which has only one class “DoSomething” (under namespace “ws.example”) with only one method “doSomething”. You can use the bottom-up approach to build this web service. Please see this link.
    C#
    package ws.example;
    public class DoSomething {
                public String doSomething(String myinput)
                {
                            System.out.println("doSomething is called");
                            return "doSomething is called ";
                }
    }
  2. Check the generated WSDL file, the service name is “DoSomethingService”, Port “DoSomething”, binding address is http://localhost:8080/DoSomethingWebService/services/DoSomething.

    Image 1

    Figure 1: "DoSomethingService" Web Service
  3. Export the service to a war file and deploy it under $TomcatHome/webapps. If you like to, export and deploy the test client also, it is good for testing. Please see this link.

Part B: Invoke this Web Service in BPEL

  1. Prepare ODE and BPEL Plug-In and create a BPEL project “InvokeWebServiceProj” and a synchronous BPEL process “Caller” under namespace “http://MyTest.com/Test”. Please see this link.
  2. Import DoSomething.wsdl into the project and create a partner link “DSLink” of type “DSLinkType”, Partner Role of “DSProvider”. Please see this link.

    Image 2

    Figure 2: “DSLinkType”
  3. Add Assign, Assign1 and Invoke Block in “Caller” process:

    Image 3

    Figure 3: "Caller" BPEL Process
  4. Edit Invoke Block to call “doSomething”.

    Image 4

    Figure 4: "Invoke" Block
  5. Initialize “DSLinkRequest” from “Assign” block, choose From->Fixed Value and To->DSLinkRequest>parameters. The fixed value is described as:
    XML
    <xsd:doSomething xmlns:xsd="http://example.ws">
                                <xsd:myinput/>
                            </xsd:doSomething>

    Image 5

    Figure 5: Initialize “DSLinkRequest”
  6. Set the input value for “doSomething” method. Choose From->Variable->input->payload->input and To->Variable->DSLinkRequest->parameters->myinput.

    Image 6

    Figure 6: Set “myinput” for “DSLinkRequest”
  7. Initialize “output” from “Assign1” block. Choose From->Fixed Value and To->output>payload. The fixed value is described as:
    XML
    <tns:CallerResponse xmlns:tns="http://MyTest.com/Test">
                                <tns:result/>
                            </tns:CallerResponse>

    Image 7

    Figure 7: Initialize “output”
  8. Set the output value for “Caller” process. Choose From->Variable->DSLinkResponse->parameters->dosomethingReturn and To->Variable->output->payload->result.

    Image 8

    Figure 8: Set “result” for “output”
  9. Edit the Caller.wsdl generated, so that a “CallerService” of port “CallerPort” is bound to the “Caller” process with the address “http://localhost:8080/ode/processes/Caller” using SOAP.

    Image 9

    Figure 9: "CallerService" Web Service
  10. Create deploy.xml.
    XML
    <?xml version="1.0" encoding="UTF-8"?>
    <deploy xmlns="http://ode.fivesight.com/schemas/2006/06/27/dd"
        xmlns:pns="http://MyTest.com/Test"
        xmlns:wns="http://example.ws">
    
      <process name="pns:Caller">
        <active>true</active>
        <provide partnerLink="client">
          <service name="pns:CallerService" port="CallerPort"/>
        </provide>
        <!-- If there is a BPEL process which is also deployed under the same project-->
        <!--<provide partnerLink="DSLink">
          <service name="wns:DoSomethingService" port="DoSomething"/>
        </provide>-->
        <!-- DoSomethingService is an existing/external Web Service -->
         <invoke partnerLink="DSLink">
              <service name="wns:DoSomethingService" port="DoSomething"/>
         </invoke>
         <cleanup on="always" />
      </process>
      </deploy>
  11. Test.

    Image 10

    Figure 10: Test Result

    Here is the complete list of the files of BPEL project (Caller.bpelex, Caller.wsdl and CallerArtifacts.wsdl are generated).

    Image 11

    Figure 11: File List

History

  • 27th February, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)