IF and Else in BPEL

Hi All, its long time i wrote on SOA technologies so this week end decided to write on BPEL again. In this post i will start explaining on how to create BPEL process programmatically rather using GUI tool (Drag and Drop).

First lets create BPEl project and process as explained below.

1. Create a new BPEL project named “BpelTest” by selecting File→New→Others→BPEL 2.0→BPEL Project. Select Next. Type the project name as “BpelTest”. Click Finish.

2. Create a new BPEL process file named “BpelTestProcess” by right clicking on the BpelTest/bpelContent folder, select New→Others→BPEL 2.0→New BPEL Process File. Click Next. Fill in BPEL Process Name the string “BpelTestProcess”, and in the Namespace the string “http://spark.bpel.test.process”. Select the Template as Synchronous BPEL Process. Click Finish.

Note : Please rename the WSDL that is create as shown in the screen shot below.
image

Once the BPEL process is created let us change it as show as below. BPEL process file contain 5 major sections.
1. BPEL Process namespace.
2. Client WSDL import.
3. Specifying Partner Links.
4. Declaring Variables.
5. Orchestrating the Process Logic.

The Bpel Process name space and Client WSDL import are shown as below.

<bpel:process name="BpelTestProcess" targetNamespace="http://spark.bpel.test.process"
	suppressJoinFailure="yes" xmlns:tns="http://spark.bpel.test.process"
	xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema">

	<!-- Import the client WSDL -->
	<bpel:import location="BpelTestProcess.wsdl" namespace="http://spark.bpel.test.process"
		importType="http://schemas.xmlsoap.org/wsdl/" />

Now its time to specify the partner links and declare variables as shown below.

<bpel:partnerLinks>
		<bpel:partnerLink name="client" partnerLinkType="tns:BpelTestProcess"
			myRole="BpelTestProcessProvider" />
	</bpel:partnerLinks>


	<bpel:variables>
		<bpel:variable name="input" messageType="tns:BpelTestProcessRequestMessage" />
		<bpel:variable name="output" messageType="tns:BpelTestProcessResponseMessage" />
		<bpel:variable name="tmpInput" type="xsd:string"></bpel:variable>
	</bpel:variables>

Here we come with the exact orchestration logic.

<bpel:sequence name="main">
		<bpel:receive name="receiveInput" partnerLink="client"
			portType="tns:BpelTestProcess" operation="process" variable="input"
			createInstance="yes" />

		<bpel:assign validate="no" name="Assign">
			<bpel:copy>
				<bpel:from variable="input" part="payload"></bpel:from>
				<bpel:to variable="tmpInput"></bpel:to>
			</bpel:copy>
		</bpel:assign>
		<bpel:if>
			<bpel:condition>string($tmpInput)=string("sample passowrd")</bpel:condition>
			<bpel:assign name="working">
				<bpel:copy>
					<bpel:from>
						<bpel:literal>password matched</bpel:literal>
					</bpel:from>
					<bpel:to variable="output" part="payload"></bpel:to>
				</bpel:copy>
			</bpel:assign>
			<bpel:else>
				<bpel:assign name="failed">
					<bpel:copy>
						<bpel:from>
							<bpel:literal>Security Breach !</bpel:literal>
						</bpel:from>
						<bpel:to variable="output" part="payload"></bpel:to>
					</bpel:copy>
				</bpel:assign>
			</bpel:else>

		</bpel:if>
		<bpel:reply name="replyOutput" partnerLink="client"
			portType="tns:BpelTestProcess" operation="process" variable="output" />
	</bpel:sequence>

combining the sequence of xmls, final resultant BPEL Process code is as below.

<!-- BpelTestProcess BPEL Process [Generated by the Eclipse BPEL Designer] -->
<!-- Date: Sat May 24 19:07:43 IST 2014 -->
<bpel:process name="BpelTestProcess" targetNamespace="http://spark.bpel.test.process"
	suppressJoinFailure="yes" xmlns:tns="http://spark.bpel.test.process"
	xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema">

	<!-- Import the client WSDL -->
	<bpel:import location="BpelTestProcess.wsdl" namespace="http://spark.bpel.test.process"
		importType="http://schemas.xmlsoap.org/wsdl/" />


	<bpel:partnerLinks>
		<bpel:partnerLink name="client" partnerLinkType="tns:BpelTestProcess"
			myRole="BpelTestProcessProvider" />
	</bpel:partnerLinks>


	<bpel:variables>
		<bpel:variable name="input" messageType="tns:BpelTestProcessRequestMessage" />
		<bpel:variable name="output" messageType="tns:BpelTestProcessResponseMessage" />
		<bpel:variable name="tmpInput" type="xsd:string"></bpel:variable>
	</bpel:variables>


	<bpel:sequence name="main">
		<bpel:receive name="receiveInput" partnerLink="client"
			portType="tns:BpelTestProcess" operation="process" variable="input"
			createInstance="yes" />

		<bpel:assign validate="no" name="Assign">
			<bpel:copy>
				<bpel:from variable="input" part="payload"></bpel:from>
				<bpel:to variable="tmpInput"></bpel:to>
			</bpel:copy>
		</bpel:assign>
		<bpel:if>
			<bpel:condition>string($tmpInput)=string("06b81a04a1")</bpel:condition>
			<bpel:assign name="working">
				<bpel:copy>
					<bpel:from>
						<bpel:literal>password matched</bpel:literal>
					</bpel:from>
					<bpel:to variable="output" part="payload"></bpel:to>
				</bpel:copy>
			</bpel:assign>
			<bpel:else>
				<bpel:assign name="failed">
					<bpel:copy>
						<bpel:from>
							<bpel:literal>Security Breach !</bpel:literal>
						</bpel:from>
						<bpel:to variable="output" part="payload"></bpel:to>
					</bpel:copy>
				</bpel:assign>
			</bpel:else>

		</bpel:if>
		<bpel:reply name="replyOutput" partnerLink="client"
			portType="tns:BpelTestProcess" operation="process" variable="output" />
	</bpel:sequence>
</bpel:process>

the result of this process code in GUI looks as below
image2

Now lets code our client WSDl as follows

<?xml version="1.0"?>
<definitions name="BpelTestProcess"
        targetNamespace="http://spark.bpel.test.process"
        xmlns:tns="http://spark.bpel.test.process"
        xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype"
        xmlns="http://schemas.xmlsoap.org/wsdl/"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        >

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     TYPE DEFINITION - List of types participating in this BPEL process 
     The BPEL Designer will generate default request and response types
     but you can define or import any XML Schema type and use them as part 
     of the message types.
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->    
    <types>
        <schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
                targetNamespace="http://spark.bpel.test.process" 
                xmlns="http://www.w3.org/2001/XMLSchema">

            <element name="BpelTestProcessRequest">
                <complexType>
                    <sequence>
                        <element name="input" type="string"/>
                    </sequence>
                </complexType>
            </element>

            <element name="BpelTestProcessResponse">
                <complexType>
                    <sequence>
                        <element name="result" type="string"/>
                    </sequence>
                </complexType>
            </element>
        </schema>
    </types>


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     MESSAGE TYPE DEFINITION - Definition of the message types used as 
     part of the port type defintions
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->    
    <message name="BpelTestProcessRequestMessage">
        <part name="payload" element="tns:BpelTestProcessRequest"/>
    </message>
    <message name="BpelTestProcessResponseMessage">
        <part name="payload" element="tns:BpelTestProcessResponse"/>
    </message>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     PORT TYPE DEFINITION - A port type groups a set of operations into
     a logical service unit.
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->    

    <!-- portType implemented by the BpelTestProcess BPEL process -->
    <portType name="BpelTestProcess">
        <operation name="process">
            <input  message="tns:BpelTestProcessRequestMessage" />
            <output message="tns:BpelTestProcessResponseMessage"/>
        </operation>
    </portType>   
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     PARTNER LINK TYPE DEFINITION
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->    
    <plnk:partnerLinkType name="BpelTestProcess">
        <plnk:role name="BpelTestProcessProvider" portType="tns:BpelTestProcess"/>
    </plnk:partnerLinkType>
    

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     BINDING DEFINITION - Defines the message format and protocol details
     for a web service.
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
    <binding name="BpelTestProcessBinding" type="tns:BpelTestProcess">
    	<soap:binding style="document"
    		transport="http://schemas.xmlsoap.org/soap/http" />
    	<operation name="process">
    		<soap:operation
    			soapAction="http://spark.bpel.test.process/process" />
    		<input>
    			<soap:body use="literal" />
    		</input>
    		<output>
    			<soap:body use="literal" />
    		</output>
    	</operation>
    </binding>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     SERVICE DEFINITION - A service groups a set of ports into
     a service unit.
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
    <service name="BpelTestProcessService">
    	<port name="BpelTestProcessPort" binding="tns:BpelTestProcessBinding">
    		<soap:address location="http://localhost:8080/BpelTestProcess" />
    	</port>
    </service>
</definitions>

also the deploy.xml looks as below.

<?xml version="1.0" encoding="UTF-8"?>
<deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03" xmlns:pns="http://ode/bpel/unit-test" xmlns:spark.bpel.test.process="http://spark.bpel.test.process" xmlns:wns="http://ode/bpel/unit-test.wsdl">
  <process name="spark.bpel.test.process:BpelTestProcess">
    <process-events generate="all"/>
    <provide partnerLink="client">
      <service name="spark.bpel.test.process:BpelTestProcessService" port="BpelTestProcessPort"/>
    </provide>
  </process>
</deploy>

Download WSO2 BPS server(BPEL Process Server) from this link : http://wso2.com/products/business-process-server/. once the server is downloaded we start it by running the wso2server.bat file located in “YourDownloadLocation\$BPS_Home\bin”. Once the server is up and running we can open the management console by typing the below URL “https://localhost:9443/carbon/admin/login.jsp&#8221; and login with the admin/admin user and password.

BpsLogin

now Zip only the source files, wsdl and deploy.xml and then upload the zip archieve to BPS server. in “Main->Process->add”, when the process gets successfully uploaded it will be shown under “Main -> Process -> list”
once the deployment is complete its time for us to test our BPEL process. BPS provice a tool internally to test the process or we can use SOAP UI to test it(I prefer to use BPS Tool ‘TryIt’)

click on the process name this will take us to the process specific page and there we can find TryIt tool. please follow the screens as below.

process after deploy

try it

once we click on the try it. this will open a testing tool where we can send request and response will be shown.
Testing

In my next write up we will see how to call Java Code from BPEL Process.
Happy BPEL coding 🙂

Advertisements

One thought on “IF and Else in BPEL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s