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:

  1. 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:
    How to do it…
  2. 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"/>
  3. 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"/>
  4. 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 to do it…

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:

There's more…

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset