Take control with WS-BPEL

Page: 1 2 3 4 5 6 7 December 11th, 2009 by Henri Bezemer

Here is the WS-BPEL code:

createCustomer.bpel

<?xml version="1.0" encoding="UTF-8"?>
<process
    name="createCustomer"
    targetNamespace="http://www.zienit.com/front-office/bpel"
    xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:xsd=http://www.w3.org/2001/XMLSchema
    xmlns:tns="http://www.zienit.com/front-office/wsdl"
    xmlns:type=http://www.zienit.com/front-office/schema
    xmlns:ns0="http://www.zienit.com/front-office-crm/wsdl" xmlns:ns1="http://xml.netbeans.org/schema/back-office">

	<import namespace="http://www.zienit.com/front-office/wsdl" location="front-office.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
	<import namespace="http://www.zienit.com/front-office-crm/wsdl" location="front-office-crm.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
	<import namespace="http://www.zienit.com/front-office-callback/wsdl" location="front-office-callback.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
	<import namespace="http://simpleejb.zienit.com" location="localhost_8080/CRMService/CRMPortType.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
	<import namespace="http://j2ee.netbeans.org/wsdl/Front-office/back-office" location="back-office.wsdl" importType="http://schemas.xmlsoap.org/wsdl/"/>
	<partnerLinks>
		<partnerLink name="FOCRMServiceLink" xmlns:tns="http://www.zienit.com/front-office-crm/wsdl" partnerLinkType="tns:FOCRMServiceLT" myRole="FrontOffice" partnerRole="CRM"/>
		<partnerLink name="FrontOfficeServiceLink" xmlns:tns="http://www.zienit.com/front-office/wsdl" partnerLinkType="tns:FrontOfficeServiceLT" myRole="FrontOffice"/>
		<partnerLink name="BackOfficeServiceLink" xmlns:tns="http://j2ee.netbeans.org/wsdl/Front-office/back-office" partnerLinkType="tns:BackOfficeServiceLT" partnerRole="BackOffice"/>
	</partnerLinks>
	<variables>
		<variable name="WriteIn" xmlns:tns="http://j2ee.netbeans.org/wsdl/Front-office/back-office" messageType="tns:WriteInputMessage"/>
		<variable name="NotifyEmailConfirmedIn" xmlns:tns="http://www.zienit.com/front-office-callback/wsdl" messageType="tns:notifyEmailConfirmedRequest"/>
		<variable name="CreateCustomerOut" xmlns:tns="http://www.zienit.com/front-office/wsdl" messageType="tns:createCustomerResponse"/>
		<variable name="CreateCustomerIn" xmlns:tns="http://www.zienit.com/front-office/wsdl" messageType="tns:createCustomerRequest"/>
	</variables>
	<correlationSets>
		<correlationSet name="email" properties="ns0:email"/>
	</correlationSets>
	<sequence>
		<receive name="Receive1" createInstance="yes" partnerLink="FrontOfficeServiceLink" operation="createCustomer" xmlns:tns="http://www.zienit.com/front-office/wsdl" portType="tns:FrontOfficePT" variable="CreateCustomerIn"/>
		<scope name="Scope1">
			<variables>
				<variable name="CreateCustomerOut1" xmlns:tns="http://simpleejb.zienit.com" messageType="tns:createCustomerResponse"/>
				<variable name="CreateCustomerIn1" xmlns:tns="http://simpleejb.zienit.com" messageType="tns:createCustomer"/>
			</variables>
			<sequence name="Sequence1">
				<assign name="Assign2">
					<copy>
						<from>$CreateCustomerIn.part1/type:name</from>
						<to>$CreateCustomerIn1.parameters/name</to>
					</copy>
				</assign>
				<invoke name="InvokeCreateCustomer" partnerLink="FOCRMServiceLink" operation="createCustomer" xmlns:tns="http://simpleejb.zienit.com" portType="tns:CRMPortType" inputVariable="CreateCustomerIn1" outputVariable="CreateCustomerOut1"/>
				<assign name="Assign3">
					<copy>
						<from>$CreateCustomerOut1.parameters/customer/id</from>
						<to>$CreateCustomerOut.part1/type:id</to>
					</copy>
				</assign>
			</sequence>
		</scope>
		<scope name="Scope2">
			<variables>
				<variable name="AddEmailOut" xmlns:tns="http://simpleejb.zienit.com" messageType="tns:addEmailResponse"/>
				<variable name="AddEmailIn" xmlns:tns="http://simpleejb.zienit.com" messageType="tns:addEmail"/>
			</variables>
			<sequence name="Sequence2">
				<assign name="Assign4">
					<copy>
						<from>$CreateCustomerIn.part1/type:email</from>
						<to>$AddEmailIn.parameters/address</to>
					</copy>
					<copy>
						<from>$CreateCustomerOut.part1/type:id</from>
						<to>$AddEmailIn.parameters/id</to>
					</copy>
					<copy>
						<from>'HOME'</from>
						<to>$AddEmailIn.parameters/type</to>
					</copy>
				</assign>
				<invoke name="InvokeCreateAddress" partnerLink="FOCRMServiceLink" operation="addEmail" xmlns:tns="http://simpleejb.zienit.com" portType="tns:CRMPortType" inputVariable="AddEmailIn" outputVariable="AddEmailOut">
					<correlations>
						<correlation set="email" initiate="yes" pattern="response"/>
					</correlations>
				</invoke>
			</sequence>
		</scope>
		<reply name="Reply1" partnerLink="FrontOfficeServiceLink" operation="createCustomer" xmlns:tns="http://www.zienit.com/front-office/wsdl" portType="tns:FrontOfficePT" variable="CreateCustomerOut"/>
		<receive name="Receive2" createInstance="no" partnerLink="FOCRMServiceLink" operation="notifyEmailConfirmed" xmlns:tns="http://www.zienit.com/front-office-callback/wsdl" portType="tns:FrontOfficeCBPT" variable="NotifyEmailConfirmedIn">
			<correlations>
				<correlation set="email" initiate="no"/>
			</correlations>
		</receive>
		<assign name="Assign5">
			<copy>
				<from>$CreateCustomerOut.part1/type:id</from>
				<to>$WriteIn.part1/ns1:id</to>
			</copy>
			<copy>
				<from>$CreateCustomerIn.part1/type:name</from>
				<to>$WriteIn.part1/ns1:name</to>
			</copy>
		</assign>
		<invoke name="InvokeBackOffice" partnerLink="BackOfficeServiceLink" operation="write" xmlns:tns="http://j2ee.netbeans.org/wsdl/Front-office/back-office" portType="tns:BackOfficePT" inputVariable="WriteIn"/>
	</sequence>
</process>

This program can also be opened in the graphical editor, but even this relatively simple process will look like spaghetti, because of the many (bezier) curves drawn on the screen. Let’s see what is going on in this program. At lines 11 – 15, all five WSDL’s are imported. At lines 16 – 20, three partner links are defined. The partner link called FOCRMServiceLink is bidirectional and therefore both myRole and partnerRole need to be set. At line 21 – 26 a number of variables are declared. Variables in WS-BPEL are not unlike the ones familiar from Java. In this example all variables are of a certain WSDL message type, but it is also possible to have variables of (complex or simple) XML schema types. WS-BPEL also has the concept of scope, in which one can declare scoped variables. I’ve created two scopes in this program to demonstrate this.

In lines 27 - 29 a correlation set is defined for this process. It consists of only the email property. In the remaining lines the actual program – a sequence of activities – is found. It is not difficult to recognize and understand the different steps of this program. What does need a bit of explanation is the correlation mechanism. On line 75, a property value is being set to a scraped value (notice initiate=”true”). Actually, the value is scraped from the response message in this synchronous call (notice pattern=”response”). On line 83, the correlation mechanism is used to route a message to the correct process instance (notice initiate=”false”).

Now lets put this program to the test!

Previous pageNext page

One Comment

December 15, 2009 at 11:12 am BPEL_evaluator

1

Thanks for the example. I now heve a better understanding of correlation Keep up th good work!