fromParts and toParts


Consider the following scenario:

  1. You issue a receive activity that accepts data into a variable.

  2. You issue an invoke activity that submits the same data to another service.

In general, you cannot use the same variable to receive and submit data. Even if the message structure is the same (two strings and an integer, for example), messages in most cases are defined in different WSDL namespaces, as shown in a later example. If a variable based on one message definition is expected but a variable based on another message definition is used, a validation error occurs at design or run time.

One way around the problem is to use an assign activity between the receive and invoke activities. A second way, however, lets you avoid defining a variable that is specific to a message:

  1. Define a variable that holds only the business data that you want to transfer into and out of your BPEL process. That variable is based on an XSD element or type.

  2. Reference the variable in each activity that transfers data.

The fromParts and toParts syntax makes the second alternative possible.

Imagine, for example, a BPEL process that accepts a greeting for subsequent distribution by mail. An operation in that service might use the message definition shown in Listing 8.6.

Listing 8.6: ReceiveNotice message definition

image from book
 <wsdl:definitions    name="ReceiveNotice"    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"    targetNamespace="http://com.highlight/policy/"    xmlns:highlightXSD="http://com.highlight/policy/xsd/">    .    .    <wsdl:types>       <xsd:schema>          <xsd:import namespace="http://com.highlight/policy/xsd/"                      schemaLocation="PolicyDefinitions.xsd">          </xsd:import>       </xsd:schema>    </wsdl:types>    .    .    <wsdl:message name="receiveMsg">       <wsdl:part element="highlightXSD:transferElement"                  name="receivePart"/>    </wsdl:message> </wsdl:definitions> 
image from book

Also imagine the BPEL process invoking a mailing service that uses the message definition shown in Listing 8.7.

Listing 8.7: SendNotice message definition

image from book
 wsdl:definitions    name="SendNotice"    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"    targetNamespace="http://com.highlight/printer/"    xmlns:highlightXSD="http://com.highlight/policy/xsd/">    .    .    <wsdl:types>       <xsd:schema>          <xsd:import namespace="http://com.highlight/policy/xsd/"                      schemaLocation="PolicyDefinitions.xsd">          </xsd:import>       </xsd:schema>    </wsdl:types>    .    .    <wsdl:message name="sendMsg" >       <wsdl:part element="highlightXSD:transferElement"                  name="sendPart"/>    </wsdl:message> </wsdl:definitions> 
image from book

Our assumption is that the message part in each definition uses the same XSD element (in this case, transferElement), as defined in the same namespace (in this case, http://com.highlight/policy/xsd/). Use of the same namespace prefix (highlightXSD) is a convention.

The purpose of the process outlined in Listing 8.8 is to transfer data from the inbound message (the greeting) to the outbound message (the mail content). You may be unfamiliar with some of the syntax, which demonstrates use of a receive, assign, and invoke activity. Be aware that in the invoke activity, inputVariable provides data for transmission to the service being invoked.

Listing 8.8: BPEL process that accepts and distributes a greeting

image from book
 <process    .    .    xmlns:tns1="http://com.highlight/policy/"    xmlns:tns2="http://com.highlight/printer/">    <!- import of a third WSDL         that holds partner link type is not shown ->    <import namespace="http://com.highlight/policy/"         location="../highlight/policy/ReceiveNotice.wsdl"         importType="http://schemas.xmlsoap.org/wsdl/" />   <import namespace=" http://com.highlight/printer/"         location="../highlight/printer/SendNotice.wsdl"         importType="http://schemas.xmlsoap.org/wsdl/" />    <variables>       <variable name="receiveVariable"                 messageType="tns1:receiveMsg" />       <variable name="sendVariable"                 messageType="tns2:sendMsg" />    </variables>    <sequence>       <receive name="receiveNotice"                partnerLink="receiveNoticePL"                portType="tns1:noticePT"                operation="receiveNoticeOp"                variable="receiveVariable">       </receive>       <assign name="copyNotice">          <copy>             <from variable="receiveVariable" part="receivePart" />             <to variable="sendVariable" part="sendPart" />          </copy>       </assign>       <invoke name="sendLetter"               partnerLink="sendLetterPL"               portType="tns2:sendLetterPT"               operation="sendLetterOp"               inputVariable="sendVariable" />    </sequence> </process> 
image from book

An alternative is to use a variable that is based on an XSD element and to use fromParts and toParts syntax. Listing 8.9 demonstrates this approach.

Listing 8.9: BPEL process that uses toParts and fromParts instead

image from book
 <process    .    .    xmlns:tns1="http://com.highlight/policy/"    xmlns:tns2="http://com.highlight/printer/"    xmlns:tns3="http://com.highlight/policy/xsd/">    <!- XSD import is required. WSDL imports are not shown. ->    <import namespace=" http://com.highlight/policy/xsd"         location="../highlight/policy/xsd/PolicyDefinitions.xsd"         importType="http://www.w3.org/2001/XMLSchema" />    <variables>       <variable name="transferVariable"                 element="tns3:transferElement" />    </variables>    <sequence>       <receive name="receiveNotice"                partnerLink="receiveNoticePL"                portType="tns1:noticePT"                operation="receiveNoticeOp"          <fromParts>             <fromPart part="receivePart"                       toVariable="transferVariable" />             </fromPart>          </fromParts>       </receive>       <invoke name="sendLetter"              partnerLink="sendLetterPL"              portType="tns2:sendLetterPT"              operation="sendLetterOp"          <toParts>             <toPart part="sendPart"                     fromVariable="transferVariable" />             </toPart>          </toParts>       </invoke>    </sequence> </process> 
image from book

The toParts and fromParts syntax supports multi-part messages. As noted earlier, however, the best practice is to define single-part messages.

In summary, when identifying the target of an inbound message (for example, in a receive activity), you have a choice: either specify a variable to receive all the data or use the fromParts syntax. In the latter case, you specify a set of variables, each based on an XSD element or type, along with a message part for each. You can exclude some message parts to avoid accepting data that the process does not use. Each message part is described in the WSDL message element for the operation.

Similarly, when identifying the target of an outbound message in an invoke or reply activity, you have a choice: either specify a variable that contains all the data or use the toParts syntax. In the latter case, you specify a set of variables, each based on an XSD element or type, along with a message part for each. You must ensure that each variable has content. The message part is described in the WSDL message element for the operation.




SOA for the Business Developer. Concepts, BPEL, and SCA
SOA for the Business Developer: Concepts, BPEL, and SCA (Business Developers series)
ISBN: 1583470654
EAN: 2147483647
Year: 2004
Pages: 157
Authors: Ben Margolis

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net