- BPEL and Java Cookbook
- Jurij Laznik
- 690字
- 2021-08-06 16:58:19
Invoking the asynchronous web service
The asynchronous web service is opposite to the synchronous request-response mechanism, as the asynchronous web services use a one-way mechanism. This type of invocation is recommended for long-running web services. The asynchronous web service invocation is especially handy in scenarios where we cannot expect the response in a reasonable time constraint such as the integration of payment systems between banks where confirmations are sent according to the contracts and can take from a few seconds to a few days. In this recipe, we will explore how to invoke the asynchronous web service from the BPEL process.
Getting ready
Before we start with the recipe, we need access to the asynchronous web service. Since the BPEL processes also have the possibility to be exposed as the web services endpoints, we will use the asynchronous BPEL process for this recipe. That way we will also show how to call one BPEL process from another BPEL process.
How to do it…
The following steps show how to invoke the asynchronous web service from the BPEL process:
- We start the recipe by modeling the SOA composite. We add the web service, in our case, the asynchronous BPEL process to the SOA composite, and it should look as follows:
- In the BPEL process, we first assign the parameters for the web service. Next, we invoke web service with the
<invoke>
activity as follows:<invoke name = "InvokeAsyncWS" inputVariable = "InvokeAsyncWS_process_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcess" operation = "process" bpelx:invokeAsDetail = "no"/>
- In order to receive the response from the called web service, we need to use the
<receive>
activity, which presents an entry point for the web service callback method as follows:<receive name = "ReceiveAsyncWS" createInstance = "no" variable = "ReceiveAsyncWS_processResponse_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcessCallback" operation = "processResponse"/>
- Now, we are ready to deploy the BPEL process and test it inside the Oracle Enterprise Management Console. In the excerpt of Audit Trail, we observe that the web service was invoked in an asynchronous way as follows:
How it works…
As with the synchronous web services, the asynchronous web services are also defined by the WSDL documents. If we check the port type, we spot the difference. Opposite to the synchronous web service, the asynchronous web service defines two port types as follows:
<wsdl:portType name = "HelloWorldAsyncProcess"> <wsdl:operation name = "process"> <wsdl:input message = "client:HelloWorldAsyncProcessRequestMessage"/> </wsdl:operation> </wsdl:portType> <wsdl:portType name = "HelloWorldAsyncProcessCallback"> <wsdl:operation name = "processResponse"> <wsdl:input message = "client:HelloWorldAsyncProcessResponseMessage"/> </wsdl:operation> </wsdl:portType>
The port type definition comes out of the asynchronous nature of the web service. The two port types define the two one-way operations.
We call the asynchronous web service from BPEL with the <invoke>
activity as follows:
<invoke name = "InvokeAsyncWS" inputVariable = "InvokeAsyncWS_process_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcess" operation = "process"/>
Note
Due to the one-way mechanism, only the input variable is specified and no output variable.
To receive the reply from the web service call, we use the <receive>
activity as follows:
<receive name = "ReceiveAsyncWS" createInstance = "no" variable = "ReceiveAsyncWS_processResponse_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcessCallback" operation = "processResponse"/>
The <receive>
activity is different from the <invoke>
activity. Based on the WS-Addressing (address and conversation ID) mechanism, the <receive>
activity picks up the correct message from the web service. Although we are using the <receive>
activity, the BPEL process will wait until it receives the response. We need to define the name of the variable
, partnerLink
, portType
, and operation
.
There's more…
We can also declare the fault in the asynchronous web service port type. Due to the one-way operation of the web service, we can only define the faults in the callback port type. Again, the faults are used when the web service cannot complete its operation successfully. The port type definition then states as follows:
<wsdl:portType name = "HelloWorldAsyncProcessCallback"> <wsdl:operation name = "processResponse"> <wsdl:input message = "client:HelloWorldAsyncProcessResponseMessage"/> </wsdl:operation> <wsdl:operation name = "processFault"> <wsdl:input message = "client:ProcessFaultMessage"/> </wsdl:operation> </wsdl:portType>
We see that the fault is modeled as an additional operation. The faults in the BPEL process are then modeled via the <pick>
activity as follows:
<pick name = "PickMsg"> <onMessage variable = "OnMessage_processResponse_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcessCallback" operation = "processResponse"> <assign name = "AssignOK"> <copy> <from expression = "string('OK')"/> <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:result"/> </copy> </assign> </onMessage> <onMessage variable = "OnMessage_processFault_InputVariable" partnerLink = "AsyncWS" portType = "ns1:HelloWorldAsyncProcessCallback" operation = "processFault"> <assign name = "AssignFault"> <copy> <from expression = "string('FAULT')"/> <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:result"/> </copy> </assign> </onMessage> </pick>
The graphical presentation of the BPEL process is as follows:

Based on the type of the message returned from the asynchronous web service, we can decide on how to proceed with the BPEL process execution.
Another approach of modeling the asynchronous web service call from the BPEL process is usage of the event handlers to react on occurring of the message or alarm event.
Tip
More information on the event handlers can be found in the official Oracle documentation available at http://docs.oracle.com/cd/E19182-01/821-0539/ggbyb/index.html.
See also
- For calling the synchronous web services, see the previous recipe Invoking the synchronous web service
- In cases when the fault handling needs to be implemented, see the Handling the faults thrown from the web service recipe
- We have covered the asynchronous transport in Chapter 1, Calling the asynchronous BPEL process from Java
- Getting Started with oVirt 3.3
- Linux Mint Essentials
- Windows Server 2012 Hyper-V Cookbook
- Linux Shell編程從入門到精通(第2版)
- Windows Server 2012網絡操作系統企業應用案例詳解
- Linux自動化運維:Shell與Ansible(微課版)
- Mobile First Design with HTML5 and CSS3
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- Mastering Reactive JavaScript
- Windows 10從新手到高手
- Learn SwiftUI
- 鴻蒙HarmonyOS應用開發入門
- Linux指令從初學到精通
- Gradle Effective Implementations Guide(Second Edition)
- 樹莓派+傳感器:創建智能交互項目的實用方法、工具及最佳實踐