Flow and Web Services
(Page 1 of 5 )
Last week, we looked at process lifecycles. This week, we'll take a look at the assign and other basic activities, and study flow. This article, the fourth in a series, is excerpted from chapter 12 of
Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418).
The assign Activity
Now let's look at how data can be manipulated and assigned as part of the process logic. BPEL provides a special activity type for updating variables: the assign activity. It lets you copy type-compatible data from one variable to another; you can also construct and insert new data using general XPath expressions. Expressions also provide for simple computations—for example, to prepare data for the invocation of Web services.
The following snippets depict samples of various usages of assign activities. The first shows the copying of an entire variable:
<assign>
<copy>
<from variable="poSubmissionRequest"/>
<to variable="trueCopyOfPoSubmissionRequest"/>
</copy>
</assign>
The next sample only copies a selected part from one variable to another variable:
<assign>
<copy>
<from variable="poSubmissionRequest"
part="purchaseOrder"/>
<to variable="orderSuppliesRequest"
part="orderSupplies"/>
</copy>
</assign>
In the following, you see a more complex assign activity that copies two selected elements from one variable to another. This assignment is performed as an atomic operation. The selection of elements involves queries expressed in XPath as the query language:
<assign>
<copy>
<from variable="poSubmissionRequest"
part="purchaseOrder"
query="/billTo/id"/>
<to variable="poSubmissionFaultInvalidPO"
part="customerID"/>
</copy>
<copy>
<from variable="poSubmissionRequest"
part="purchaseOrder"
query="/id"/>
<to variable="poSubmissionFaultInvalidPO"
part="orderNumber"/>
</copy>
</assign>
The next snippet initializes a variable using a literal value:
<assign>
<copy>
<from><xsd:integer>0</xsd:integer></from>
<to variable="itemCount"/>
</copy>
</assign>
The final assign sample uses an expression to perform a simple computation:
<assign>
<copy>
<from
expression="bpws:getVariableData('itemCount')+1"/>
<to variable="itemCount"/>
</copy>
</assign>
The assign activity can also copy endpoint references to and from partner links. This aspect is useful whenever endpoint references are to be treated as data—for example, to exchange endpoint references with business partners as part of messages, or to compute endpoint references.
SkatesTown uses this feature to send its endpoint reference to the supplier. It requests additional supplies using the orderSupplies operation. As part of this request, SkatesTown provides its endpoint reference. This enables the supplier to asynchronously respond to the request without the need to be statically bound to one particular seller. The supplier uses this endpoint reference to submit its response—for example, to invoke the seller's orderSuppliesOk operation. The following BPEL snippet depicts how SkatesTown's endpoint reference is copied to the request message. The assign activity copies the endpoint reference from role myRole of partner link supplier to the orderSuppliesRequest variable. This variable then serves as input for the orderSupplies operation:
<assign>
<copy>
<from partnerLink="supplier"
endpointReference="myRole"/>
<to variable="orderSuppliesRequest"
part="endpointReferenceOfSeller"/>
</copy>
</assign>
Next: XPath Extension Functions >>
More Web Services Articles
More By Sams Publishing
|
This article is excerpted from chapter 12 of Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418). Check it out today at your favorite bookstore. Buy this book now.
|
|