Oracle® SOA Suite Developer's Guide 10g (10.1.3.1.0) Part Number B28764-01 |
|
|
View PDF |
The starting point for data manipulation in BPEL is the assign activity, which builds on the XPath standard. As shown in Figure 7-10, you use the assign activity to copy data from one XML variable to another, or to calculate the value of an expression and store it in a variable.
Figure 7-10 Assign Dialog for Copy Operations
A copy element within the activity specifies the source and target of the assignment (what to copy from and to), which must be of compatible types.
You can use XPath queries, expressions, and functions to manipulate data as follows:
XPath queries: An XPath query selects a field within a source or target variable part. The from
or to
clause can include a query attribute whose value is an XPath query string. For example:
<from variable="input" part="payload" query="/p:CreditFlowRequest/p:ssn">
For XPath version 1.0, the value of the query attribute must be an absolute location path that selects exactly one node.
XPath expressions: You use an XPath expression (specified in the expression
attribute of the from
clause) to indicate a value to be stored in a variable. For example:
<from expression="100"/>
The expression can be any general expression—that is, an XPath expression that evaluates to any XPath value type.
Within XPath expressions, you can call the following types of functions:
Core XPath functions
BPEL extension functions (bpws:
)
BPEL XPath extension functions (ora:
)
Custom functions
See Oracle BPEL Process Manager Developer's Guide for more information about these functions.
Sophisticated data manipulation can be difficult to perform with the BPEL assign activity and the core XPath functions. However, you can perform complex data manipulation and transformation by using XSLT or Java, or as a web service. For XSLT, Oracle BPEL Process Manager includes XPath functions that execute these transformations. See the following for information about transformations:
You use the copy operation within the assign activity to specify which data is being copied into which variable, as shown in Figure 7-10. In the SOA Order Booking application, the BPEL process uses an assign activity, InitializeRequest, (within the CreditService scope) to copy the value of the creditcardtype
variable to the ccType
variable, and to copy the value of the creditcardnumber
variable to the value of the ccNum
variable. The variable names ccType
and ccNum
are specified in the WSDL of the CreditValidatingService partner link.
To copy variables using an assign activity:
Drag and drop an Assign activity inside a Scope activity.
Double-click the Assign icon.
Use the General tab of the Assign dialog to enter a name for the Assign activity.
Click Apply.
Click the Copy Operation tab.
From the Create list, select Copy Operation.
Use the Create Copy Operation dialog, shown in Figure 7-8, to copy the contents of one variable to another. This Assign activity takes the client's purchase order as input and contacts the Rapid Manufacturer web service for a price quote.
Browse for the From Variable by expanding the tree until you find the client input variable name (as defined in the BPEL process WSDL file).
Browse for the To Variable by expanding the tree until you find the input variable name used by the web service (as defined in the message type definition of the web service WSDL).
Close the Create Copy Operation and Assign windows.
Save the file.
Example 7-4 shows the source code for the InitializeRequest assign activity in the SOA Order Booking application.
Example 7-4 Source Code for the InitializeRequest Assign Activity
<scope name="CreditService"> <variables> <variable name="validateRequest" messageType="ns6:CreditCardValidationRequestMessage"/> <variable name="validateResponse" messageType="ns6:CreditCardValidationResponseMessage"/> </variables> <sequence name="Sequence_5"> <assign name="InitializeRequest"> <copy> <from variable="customerServiceResponse" query="/ns3:findCustomerByIdResponse/ns3:return/ns3:creditcardtype" part="parameters"/> <to variable="validateRequest" part="CreditCard" query="/ns21:CreditCard/ccType"/> </copy> <copy> <from variable="customerServiceResponse" query="/ns3:findCustomerByIdResponse/ns3:return/ns3:creditcardnumber" part="parameters"/> <to variable="validateRequest" part="CreditCard" query="/ns21:CreditCard/ccNum"/> </copy> </assign