WS-BPEL 2.0 Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Time for action – developing the book warehousing process

Let's start with the implementation of the BookWarehousingBPEL process. We should follow these steps:

  1. We will start with the XML schema definition. To do this, we need to double-click on the BookWarehousingBPEL.xsd file (in the Schemas folder) and write the following schema, as shown:
  2. Now we can switch back to the BPEL tab (BookWarehousingBPEL.bpel). First, we will add an <assign> activity to prepare a request for both the bookstore BPEL processes. In <assign>, we will copy the whole BookData element from inputVariable to a new variable, which we will create on the fly. We should do the following:
    1. Drag-and-drop <assign> to the BPEL process between the <receive> and <reply> activities.
    2. Double-click on the <assign> activity to open the dialog window.
    3. To hold and store the request for both bookstore BPEL processes, we need a new variable. Therefore, we will right-click on Variable and select the Create Variable option from the context menu:
    4. A new window will appear where we will name the variable BookstoreARequest. As the type, we will choose Message Type, as we will prepare the whole message, which will be sent as a request message to BookstoreABPEL. We will click on the magnifier icon to browse the message types and select BookstoreABPELRequestMessage, as shown:
    5. We also need a variable, which will hold the response from BookstoreABPEL. We will repeat the same steps as before. We will name the variable BookstoreAResponse:
    6. We will create two more variables, BookstoreBRequest and BookstoreBResponse. In order to do this, we will repeat steps 3-5.
    7. We are now ready to create a copy of the BookData element from inputVariable to the BookData element of the BookstoreARequest variable. We need to do the copy element by element, as BookData from inputVariable belongs to a different namespace rather than the BookData element from the BookstoreARequest variable. Therefore, we will need to do four drag-and-drops. In the next chapter, we will explain how we could use the same namespace and simply copy the whole complex element as one, as shown in the following screenshot:
    8. We should do exactly the same copy for the BookstoreBRequest variable.
    9. Finally, let's rename the <assign> activity from Assign1 to PrepareRequest.
  3. We are now ready to invoke both the bookstore services. First, we will invoke BookstoreABPEL. To invoke an external service, we will use the <invoke> activity. We will drag the Invoke activity from the right-hand side toolbar and drop it on the process flow after <assign>, which we've just added.
  4. Then, we will connect the <invoke> activity with the BookstoreABPEL service, listed in the right-hand side of the canvas (under the Partner Links section):
  5. A window will open and we will need to specify a few parameters. First, we will name it BookstoreAInvoke. The partner link, the port type, and the operation are already selected. We should leave the default values. The operation name is getBookData, which is exactly what we are looking for.
  6. We will need to specify the input and output variables. The input variable is the variable holding the request message. In our case, this is the BookstoreARequest variable. The output variable is the variable that stores the invocation response. This is BookstoreAResponse. Let's select both variables, as shown in the following screenshot:
  7. We shall do the same for the second invocation. The difference is that this time, we will invoke BookstoreBBPEL and use the corresponding BookstoreB variables. This should bring us to the following BPEL process flow:
  8. The final step is to add the <if> activity to compare the response from both the bookstore BPELs and select the bookstore with the lower stock to ship the purchased books.
  9. We have already learned how to use the <if> activity in the previous chapter. First, we add the <if> activity:
  10. Then, we right-click on the new <if> activity and select Edit, as shown in the following screenshot. In the opened dialog box, we create a condition such that BookstoreAResponse stock quantity is lower than the BookstoreBResponse stock quantity. In this case, we select Bookstore A:
  11. Otherwise, we select Bookstore B. In both cases, we add <assign> to set the appropriate response for the book warehousing BPEL process:
  12. The final part of the BPEL process should look like the following screenshot:

What just happened?

We implemented the process flow logic for the BookWarehousingBPEL process. It actually orchestrated two other services. It invoked the BookstoreA and BookstoreB BPEL processes that we developed in the previous chapter. Here, these two BPEL processes acted like services.

First, we created the XML schema elements for the request and response messages of the BPEL process. We created four variables: BookstoreARequest, BookstoreAResponse, BookstoreBRequest, and BookstoreBResponse. The BPEL code for variable declaration looks like the code shown in the following screenshot:

Then, we added the <assign> activity to prepare a request for both the bookstore BPEL processes. Then, we copied the BookData element from inputVariable to the BookstoreARequest and BookstoreBRequest variables. The following BPEL code has been generated:

Next, we invoked both the bookstore BPEL services using the <invoke> activity. The BPEL source code reads like the following screenshot:

Finally, we added the <if> activity to select the bookstore with the lowest stock quantity:

With this, we have concluded the development of the book warehousing BPEL process and are ready to deploy and test it.

Deploying and testing the book warehousing BPEL process

We will deploy the project to the SOA Suite process server the same way we did in the previous chapter, by right-clicking on the project and selecting Deploy. Then, we will navigate through the options. As we redeploy the whole SOA composite, make sure the Overwrite option is selected. You should check if the compilation and the deployment have been successful.

Then, we will log in to the Enterprise Manager console, select the project bookstore, and click on the Test button. Be sure to select bookwarehousingbpel_client for the test. After entering the parameters, as shown in the following screenshot, we can click on the Test Web Service button to initiate the BPEL process, and we should receive an answer (Bookstore A or Bookstore B, depending on the data that we have entered).

Remember that our BookWarehousingBPEL process actually orchestrated two other services. It invoked the BookstoreA and BookstoreB BPEL processes. To verify this, we can launch the flow trace (click on the Launch Flow Trace button) in the Enterprise Manager console, and we will see that the two bookstore BPEL processes have been invoked, as shown:

An even more interesting view is the flow view, which also shows that both bookstore services have been invoked. Click on BookWarehousingBPEL to open up the audit trail: