Skip Headers
Oracle® BPEL Process Manager Developer's Guide
10g Release 2 (10.1.2)
Part No. B14448-01
  Go To Documentation Library
Library
Go To Product List
Product
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

3 Building a Simple BPEL Process

This chapter discusses how to create, build, deploy, and test a simple BPEL process, a synchronous Hello World application. It accepts a name as an input message and returns the message Hello followed by the name through a synchronous reply.

3.1 Overview of Building a Simple BPEL Process

The Hello World application is familiar to anyone who has taken an introductory programming class. Here it is given as an example of a BPEL process that accepts input, manipulates the input, and returns an output through a synchronous reply.

The input comes from a client application. In this case, the client application is Oracle BPEL Console, but a Java/JSP interface or a SOAP client can also serve as the client application. The client application has a partner link with the BPEL process. This defines the role of each party, what types of data each accepts and returns, and so on. The WSDL file contains the definition of the partner links.

Figure 3-1 The Hello World BPEL Process

Description of bpmdg003.gif follows
Description of the illustration bpmdg003.gif

The Hello World process accepts the input from the partner link with a receive activity, which repackages the data into a variable. The greeting is then added using an assign activity, and the result is sent back through the partner link as output using the reply activity.


See Also:

See "Reviewing the BPEL Source Code" section for more information on these activities

3.2 Creating a New BPEL Project

The project describes how to create the Hello World process using Eclipse BPEL Designer.

Eclipse BPEL Designer includes a New Project wizard that automatically generates the skeleton of a BPEL project, including the BPEL source, a WSDL interface, a BPEL deployment descriptor, and an Ant script for compiling and deploying the BPEL process.


Note:

Do not create a project name that begins with a number.

To create a new BPEL project

  1. Open Eclipse BPEL Designer.

  2. On the File menu, click New > Project.

  3. Select Oracle BPEL Project.

  4. Click Next.

    Description of hello1.gif follows
    Description of the illustration hello1.gif

  5. Enter SyncHelloWorld as the BPEL process name.

  6. (Optional) Enter http://tutorial.oracle.com as the namespace (replacing the one provided by default).

  7. Change the template to Sync BPEL Process.

  8. Leave the Use default check box selected, and click Finish.

    Description of hello2.gif follows
    Description of the illustration hello2.gif

3.3 Browsing a New Project

The New Project wizard creates a skeleton for a new synchronous BPEL process, with all the necessary source files.

Description of hello3.gif follows
Description of the illustration hello3.gif

Specifically, the following files are created:

File Description
.project Eclipse BPEL Designer format .project file.
bpel.xml The deployment descriptor for the process. Defines the locations of the WSDL files for services called by this flow, along with other project-specific parameters.
build.xml Apache Ant script for compiling and deploying this process.
SyncHelloWorld.bpel The BPEL source for the process. The New Project wizard creates an empty flow, with just the minimum activities and definitions for the selected flow type. For a synchronous BPEL process, the only activities are a receive to initiate the flow from a synchronous client request and a reply to return.
SyncHelloWorld.wsdl The WSDL (client) interface for this process. Defines the input and output messages for this flow, the client interface and operations supported, and the BPEL partnerLinkTypes, so that the flow can be incorporated into other processes. The New Project wizard generates a document-literal style WSDL that takes a string input message and returns a string response message.

3.4 Editing the WSDL Interface of a BPEL Process

To start, you edit the WSDL file, which defines the interface to the flow, the messages that it accepts and returns, operations that are supported, and so on.

To modify the input and output messages of the BPEL process:

  1. Expand SyncHelloWorld in the Navigator on the left and double-click the SyncHelloWorld.wsdl file.

  2. Scroll down in the WSDL file. The New Project wizard has defined both a SyncHelloWorldRequest complexType element that the flow accepts as input (in a document-literal style WSDL message) and a SyncHelloWorldResponse element that it returns.

    Description of hello4.gif follows
    Description of the illustration hello4.gif


    Note:

    You can currently edit the WSDL file for the BPEL process in text mode in Eclipse BPEL Designer (or in any other text editor). If you edit the WSDL file (which you do not perform as part of this tutorial), you must refresh the client interface for the flow, if it is currently open in the designer.

  3. Close the (unmodified) SyncHelloWorld.wsdl window in the designer.

3.5 Switching Between the Overview, Process Map, and Source Code

This section describes how to view the BPEL file in three different ways.

To view an overview of the BPEL process:

Double-click SyncHelloWorld.bpel in the Navigator if it is not already open in the designer (however, it opens by default when you create a new BPEL project, so it is likely already open).

You are initially provided with a visual overview of the BPEL process file. On the left is the client interface, displaying operations exposed by the process (process in this case) and any asynchronous callback operations (there are none for this process). Note that the designer automatically puts any partner link named client on the left side of the window. All other partner links are displayed in a list on the right.

Description of hello5.gif follows
Description of the illustration hello5.gif

To view the detailed process map:

In the middle of the window is a link to edit the process map for the flow (visual representation of the flow logic) and a list of any global XML variables defined for the flow (input and output in this case, created by the wizard). An Inspector pane appears on the right after you drill down into the Process Map view.

At the top of the window, the Overview and Process Map links also allow you to shift from the current view (which is the Overview view) to the Process Map view, and back.

Click the Process Map button to see the visual representation of the process's flow logic.Alternatively, you can click the Edit Process Map link to access this view of the process.

Description of hello6.gif follows
Description of the illustration hello6.gif

To view the BPEL source code:

At the bottom of the window, the BPEL Designer and BPEL Source tabs allow you to switch between graphical editing mode (BPEL Designer) and a text-editing mode for the source code of the BPEL process (BPEL Source). Note that two-way editing is enabled; changes you make in either editing mode are reflected in both modes.

Click the BPEL Source tab of the editor window.

Description of hello7.gif follows
Description of the illustration hello7.gif

3.6 Reviewing the BPEL Source Code

BPEL Source mode is a good way to review the BPEL code that has been generated by Eclipse BPEL Designer or by a wizard. This is a good way to understand exactly what the designer does, because everything you do in the designer is saved in standard BPEL source code. This can also be a great way to learn BPEL if you are not already familiar with it.

The New Project wizard has created a basic skeleton for you of a synchronous BPEL process. It begins with a process element defined with the name and target namespace you specified in the window.

<process name="SyncHelloWorld"
     targetNamespace="http://tutorial.oracle.com"
     suppressJoinFailure="yes" xmlns:tns="http://tutorial.oracle.com"
     xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
     xmlns:bpelx="http://schemas.oracle.com/bpel/extension">

Next come the partner links, which in BPEL define the other services or processes with which the process interacts. In this case, the only partner link created automatically by the wizard is the one for the client interface to this BPEL process.

<partnerLinks>
     <partnerLink name="client"
     <!-- comments... -->
          partnerLinkType="tns:SyncHelloWorld"
</partnerLinks>
          myRole="SyncHelloWorldProvider"/>

In BPEL, following the partner links, you next define any global variables that are accessible throughout the process. The New Project wizard automatically creates global variables for the input and output messages for the process. As you saw previously, the types for these two variables are defined in the WSDL for the process itself.

<variables>     <!-- Reference to the message passed as input during initiation -->
     <variable name="input"
          messageType="tns:SyncHelloWorldRequestMessage"/>
     <!-- Reference to the message that will be returned to the
          requester
          -->
     <variable name="output"
          messageType="tns:SyncHelloWorldResponseMessage"/>
</variables>

After the global variables comes the main body of the process, which is any single BPEL activity. This is typically a compound activity that contains subactivities. When you create a new synchronous process, the New Project wizard creates a sequence (which in BPEL is a set of activities executed sequentially) that contains a receive activity to get the input message from the client to start the process, followed by a reply activity to return the result synchronously to the client.

<sequence name="main">
     <!-- Receive input from requester.
          Note: This maps to operation defined in SyncHelloWorld.wsdl
          -->
     <receive name="receiveInput" partnerLink="client"
          portType="tns:SyncHelloWorld"
          operation="process" variable="input"
          createInstance="yes"/>
     <reply name="replyOutput"
          partnerLink="client"
          portType="tns:SyncHelloWorld"
          operation="process"
          variable="output"/>
</sequence>

Finally, the process tag is closed:

</process>

That completes the code review. Next, you begin to edit this BPEL process to add logic to convert the input into a greeting.

3.6.1 The Sequence Activity

A sequence activity contains one or more activities that are performed sequentially, in the order in which they are listed within the sequence element; that is, in lexical order. The sequence activity completes when the final activity in the sequence has completed.

 <sequence standard-attributes>
    standard-elements
    activity+
  </sequence>

Example:

<sequence>
  <flow>
    ...
  </flow>
  <scope>
    ...
  </scope>
  <pick>
    ...
  </pick>
</sequence>

3.6.2 The Assign Activity

The assign activity assigns values to variables. Copy rules are added to the assign to specify which data is being copied into which variable. The following code sample is from the HelloWorld.bpel file located at C:\orabpel\samples\tutorials\101.HelloWorld.

<assign>
     <copy>
        <from expression="concat('Hello ',bpws:getVariableData('input',
          'payload','/tns:name'))"/>
        <to variable="output" part="payload" query="/result"/>
     </copy>
</assign>

If you are using JDeveloper BPEL Designer, this sample is available in Oracle_Home\integration\orabpel\samples\tutorials\101.HelloWorld.

Hello World is the first sample application used in the tutorials. It accepts input from the user, then adds Hello with a trailing blank space to the beginning of the input payload and copies the result to the output payload.

3.7 Adding an Assign Activity to the Process Map

In this section, you learn how to add a new activity to the BPEL process.

To view the process map:

Switch back to BPEL Designer mode and make sure you are in Process Map view. You now see a graphical representation of the flow for the BPEL process. As described previously, the initial process created by the New Project wizard for a synchronous process just receives the input for the process operation from the client and returns the response with a synchronous reply, as you saw in the code review section.

To insert an assign activity:

You now insert an assign activity into the process. A BPEL assign activity provides a mechanism for doing simple data manipulation, using XPath expressions.

You use the assign to concatenate the string ÒHello Ò with the string name input message and copy the resulting string into the output message.

To insert a new activity into the process, you find it on the BPEL Palette on the right (you can click the More Activities link to see additional activities supported in BPEL Designer mode) and drag it onto a transition arrow in the flow at the location where you want to insert it.

  1. Drag an assign from the palette and drop it between the process receive activity and the reply response element:

    Description of hello10.gif follows
    Description of the illustration hello10.gif

    The new assign activity is initially selected. You can edit attributes for it in the BPEL Inspector window on the right.

  2. Enter a value for the optional name attribute, such as createReturnStr (followed by the Enter key).


    Note:

    The text field in which you enter the name is not selected until you click there.

    Description of hello11.gif follows
    Description of the illustration hello11.gif

To add a copy rule:

  1. In the tasks drop-down list (the down-arrow to the right of the assign activity heading), click Add Copy Rule.

    Description of hello12.gif follows
    Description of the illustration hello12.gif

    This brings up the Copy Rule window, which you now use to perform the data manipulation. In BPEL, an assign statement can have many copy rules, each using variable data, XPath queries, XPath expressions, and literals to do simple data manipulation and transformation.

    Description of hello13.gif follows
    Description of the illustration hello13.gif


    Note:

    Oracle recommends that more complex data transformation be done using XQuery, XSLT, Java, commercial toolkits, or as a service. See http://www.oracle.com/technology/bpel for more information.

Each copy rule for an assign activity has a From part, which specifies the source data, and a To part, which specifies a variable or element part as the destination for the data.

To define the From part (source) of the copy rule:

Click Expression in the From part and you can either enter the following expression in the text field:

concat( 'Hello ', bpws:getVariableData( 'input', 'payload',
 '/SyncHelloWorldRequest/input'))

Or you can use the XPath function wizard to complete this with the following steps:

Whether you enter it directly or use the wizard, this expression says:

concatenate the literal string Hello with the string element that is accessed by the XPath query /SyncHelloWorldRequest/input within the part payload of the variable input


See Also:

The following documentation for more information on XPath expressions and queries:

To define the To (destination) of the copy:

You now complete the To section of the Copy Rule form to copy the concatenated string into the helloString element in the reply message.

  1. In the To section, click the down arrow after the field.

  2. Select output > payload > SyncHelloWorldResponse > result string:

    Description of hello20.gif follows
    Description of the illustration hello20.gif

    This causes the BPEL Designer to automatically generate the XPath query string $output/payload/tns:SyncHelloWorldResponse/tns:result and enter it in the field.

    Again, you can always type queries directly into the field if you choose. Note that the wizard uses fully qualified names (including the namespaces) in the query string, but in both of these examples the namespaces are actually optional.

  3. Click Done.

3.8 Compile and Deploy the BPEL Process

In this section, you learn how to compile, deploy, and test this BPEL process.

To compile:

  1. Save the process.

  2. Click the Build BPEL Project button on the Workbench toolbar to compile and deploy the process.

    Description of hello14.gif follows
    Description of the illustration hello14.gif

This compiles the flow, packaging all its components into a BPEL suitcase JAR file. You can then deploy this JAR file to Oracle BPEL Server by copying it into the appropriate deployment directory. The build.xml file generated by the wizard automatically deploys the suitcase to the local server's default domain, in this case C:\orabpel\domains\default\deploy. (Note that this action is the same as running obant from the command line.)


Note:

To see the contents of the BPEL suitcase, open the file C:\orabpel\domains\default\deploy\bpel_SyncHelloWorld_1.0.jar with any tool for opening JAR files (for example, WinZip).

3.9 Testing the BPEL Process

As the final step, you test the BPEL process by using the automatically generated test interface in Oracle BPEL Console.

To initiate a test instance of the SyncHelloWorld BPEL process:

  1. Access the console at http://localhost:9700/BPELConsole. Note that you can also click the Open BPEL Console button on the Workbench toolbar to open a browser window that points to the console.

    Description of hello15.gif follows
    Description of the illustration hello15.gif

  2. Log in to the default domain to access the Dashboard tab:

    Description of hello16.gif follows
    Description of the illustration hello16.gif

  3. Click the SyncHelloWorld BPEL process link and then use the automatically generated HTML test form interface.

    Description of hello17.gif follows
    Description of the illustration hello17.gif

  4. Enter the name and click Post XML Message to initiate the process:

    Description of hello18.gif follows
    Description of the illustration hello18.gif

    You now see the results, because it is a synchronous operation.

  5. To see the visual audit trail for this completed instance, click the Visual Flow link.

    The visual audit trail displays a representation of the current state and history of execution of the instance (which in this case has completed), with the same look and feel as Eclipse BPEL Designer. You can select activities in the audit trail to see details about them. You can also click the Audit tab to see the text audit trail or the Debug tab to see the debugger for this instance.

    Description of hello19.gif follows
    Description of the illustration hello19.gif

  6. Click the reply client activity at the bottom of the audit trail to see the returned XML message for the process, as shown previously.

3.10 Summary

This chapter discusses some of the basic concepts of a BPEL process, and shows the steps necessary to create a BPEL process. These steps are shown in Eclipse BPEL Designer, but you can also use JDeveloper BPEL Designer. This process can be run from Oracle BPEL Console, and is a synchronous Web service that can be used as a building block for other BPEL processes or invoked using standard Web services interfaces.