A Quick Response
Returning an Immediate Response from an Asynch Process
I just got asked by a colleague how to return an immediate response from a BPEL process created using the template "Asynchronous BPEL Process". Often we want to return some data to the caller of a process to indicate that the request has been received and is being processed. To do this we need to add an immediate response to the caller in addition to calling them back later when the process is completed. For example consider a process to make a booking for some resource. The process might be lengthy and the caller may need some mechanism for canceling the process before it completes. In this case returning an immediate response could give the caller a handle allowing him to call back into the specific process instance to cancel it.So lets look at how we alter the template to allow for this immediate response.
Create the Project
First we create our process using File->New Project in JDeveloper and choose a BPEL PRocess Project and select the "Asynchronous BPEL Process" template.
Adding a Response Element
Once we have created our project we then need to add an immediate response element to the XSD. <element name="ImmediateResponseBPELProcessProcessImmediateResponse">
<complexType>
<sequence>
<element name="result" type="string"/>
</sequence>
</complexType>
</element>
<complexType>
<sequence>
<element name="result" type="string"/>
</sequence>
</complexType>
</element>
Adding a New Message Type
Having created a new immediate response element to the XSD we then need to use that element within a new message type in the WSDL. <message name="ImmediateResponseBPELProcessImmediateResponseMessage">
<part name="payload" element="client:ImmediateResponseBPELProcessProcessImmediateResponse"/>
</message>
<part name="payload" element="client:ImmediateResponseBPELProcessProcessImmediateResponse"/>
</message>
Adding an Output to the Initiate Operation
Within the port type for the process we need to modify the "initiate" operation to return an immediate response of the message type we just created. <operation name="initiate">
<input message="client:ImmediateResponseBPELProcessRequestMessage"/>
<output message="client:ImmediateResponseBPELProcessImmediateResponseMessage"/>
</operation>
<input message="client:ImmediateResponseBPELProcessRequestMessage"/>
<output message="client:ImmediateResponseBPELProcessImmediateResponseMessage"/>
</operation>
Adding a New Variable to the Process
We need to add a new variable to the process to hold the immediate return value.
Add a Reply to the Process
We can add the reply operation to the process and wire it up the client partner link.
Complete Process
Finally we need to complete the process. I will often return the process instance ID as a return value. This can then be used a correlation token if the client needs to call into the process again before it completes.
Once the process is finished being written it can be deployed and executed.

Comments (5)
Let's consider that it allows the client to make a call later. As you suggested, we could receive a Cancel before the 5 minutes have elapsed, and taking appropriate actions. For instance, you have WaitFor5 and a Receive activity under a Flow. The Receive activity would react from a Cancel action, but:
- how to you define this new cancel action? Under the same client partnerlink ? How would you do this? Or maybe with another partnerlink ?
- how BPEL PM is able to 'match' between the started instance and the instance you try to cancel? How do you use the token (instanceID) when you call Cancel ?
Thanks
Stephane
Posted by Stephane D. | October 1, 2007 10:42 AM
Posted on October 1, 2007 10:42
Obviously, it is not a Flow that must be created, but a Pick activity with:
- onAlarm: set the time to 5 min as per the example, and have the assign activity for the timed out process flow.
- onMessage: set to the cancel action with the related assign activity (cancelled process).
1) I have defined the new action 'cancel' and related message type and input variable, but I get "Cannot find operation in portType. The operation "cancel" is not found in portType"
2) How the call to "cancel" will be correlated to exactly reference this instance of the process we want the onMessage to be invoked ?
Posted by Stephane D. | October 2, 2007 8:43 AM
Posted on October 2, 2007 08:43
Hello Antony,
I just read your blog "A Quick Response". i have not tried deploying this But i got many doubts raised in my mind after reading this.
As per BPEL documentation, In Asynchronous case, client thread is immediately returnted after the message is given to the worker bean and a new thread is started.
How can Reply Activity returns the response to the same client that made the request.
Thanks/Chandra
Posted by Chandra | November 10, 2007 12:49 PM
Posted on November 10, 2007 12:49
You are confusing the message interaction pattern with the BPEL pattern. If you follow my entry you will see that we change the initial interaction pattern from a one-way to a two-way interaction. BPEL will processing this inline on the receiving thread rather than using a seperate worker thread which as you indicate is what happens with a one-way interaction.
BPEL figures out what to do based on the message interaction pattern.
I can assure you that it doies work as I said, try it yourself.
Hope that helps
Antony
Posted by Antony Reynolds | December 5, 2007 8:19 AM
Posted on December 5, 2007 08:19
This example does not mention updating the bindings to include and <output> in the soap:operation for the soapAction (initiate). I was able to incorporate your suggestions into my own project, as well as changes to the binding, and it worked great!
Thanks.
Posted by Dezi Siliezar | January 15, 2008 10:49 AM
Posted on January 15, 2008 10:49