Time for action – developing the book warehousing process
Let's start with the implementation of the BookWarehousingBPEL
process. We should follow these steps:
- We will start with the XML schema definition. To do this, we need to double-click on the
BookWarehousingBPEL.xsd
file (in theSchemas
folder) and write the following schema, as shown: - 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 wholeBookData
element frominputVariable
to a new variable, which we will create on the fly. We should do the following:- Drag-and-drop
<assign>
to the BPEL process between the<receive>
and<reply>
activities. - Double-click on the
<assign>
activity to open the dialog window. - 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:
- 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 toBookstoreABPEL
. We will click on the magnifier icon to browse the message types and selectBookstoreABPELRequestMessage
, as shown: - We also need a variable, which will hold the response from
BookstoreABPEL
. We will repeat the same steps as before. We will name the variableBookstoreAResponse
: - We will create two more variables,
BookstoreBRequest
andBookstoreBResponse
. In order to do this, we will repeat steps 3-5. - We are now ready to create a copy of the
BookData
element frominputVariable
to theBookData
element of theBookstoreARequest
variable. We need to do the copy element by element, asBookData
frominputVariable
belongs to a different namespace rather than theBookData
element from theBookstoreARequest
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: - We should do exactly the same copy for the
BookstoreBRequest
variable. - Finally, let's rename the
<assign>
activity fromAssign1
toPrepareRequest
.
- Drag-and-drop
- 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. - Then, we will connect the
<invoke>
activity with theBookstoreABPEL
service, listed in the right-hand side of the canvas (under the Partner Links section): - 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 isgetBookData
, which is exactly what we are looking for. - 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 isBookstoreAResponse
. Let's select both variables, as shown in the following screenshot: - We shall do the same for the second invocation. The difference is that this time, we will invoke
BookstoreBBPEL
and use the correspondingBookstoreB
variables. This should bring us to the following BPEL process flow: - 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. - We have already learned how to use the
<if>
activity in the previous chapter. First, we add the<if>
activity: - 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 thatBookstoreAResponse
stock quantity is lower than theBookstoreBResponse
stock quantity. In this case, we select Bookstore A: - Otherwise, we select Bookstore B. In both cases, we add
<assign>
to set the appropriate response for the book warehousing BPEL process: - 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: