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

BPEL HelloWorld Example with Eclipse and Apache ODE

Hi Guys as i explained in my previous post how to install Apache ODE and Eclipse BPEL Designer now im here to explain how to deploy the first BPEL process flow

Objective: deploying a BPEL process which receives an input string from a client and responses it exactly that input.
Tools: Eclipse 3.6.2, BPEL Designer 0.5.0 Plugin, Tomcat 7.0.12, ODE 1.3.5

step1.Create new BPEL project: File→New→Others→BPEL 2.0→BPEL Project.
step2.Name it BPEL_HelloWorld. Select the Target Runtime as Apache ODE 1.x Runtime and Configuration as Defaut Configuration for Apache ODE 1.x Runtime. Click Finish.

bpel_hello_world

step3.In the folder BPEL_HelloWorld\bpelContent, File → New → Other → BPEL 2.0 → New BPEL process file.
step4.Name it HelloWorld, Namespace http://helloworld.localhost and select Template Synchronous BPEL Process. Click Next.

bpel_hello_world1

step5.Edit the Service Address to : http://localhost:8080/ode/processes/HelloWorld (suppose that your Tomcat environment runs at port 8080) and keep other default declarations. Click Finish.

bpel_hello_world2

step6. Three files are created in the folder bpelContent and the HelloWorld.bpel is opened for editing the BPEL process.
step7. Click to open the Palette panel on the right of the canvas. (or right click on the canvas, select Show Pallette on Palette View)

bpel_hello_world3

step8. Drag the Assign action next to the receiveInput action and delete the FIX_ME-Add_Business_Logic_Here.

bpel_hello_world7

step9. Right click on the Assign activity. Select Show in properties.
step10.In the Properties tab, select Details. Click on the New button to define an assign operator.
step11.Assign from input→payload→input to output→payload→result. An Initializer popup dialog appear. Click Yes to initialize the output variable and save the process.

3ca9f195f7403fcc0bcb9f5a3029db16.media.900x433

step12. It’s time now to deploy the BPEL project. Click on the folder bpelContent, select File→New→Others→BPEL 2.0→Apache ODE Deployment Descriptor.
step13. Click Next. Verify the BPEL Project name as BPEL_HelloWorld. Click Finish.

bpel_hello_world5

step14 .Double click on the deploy.xml file in the bpelContent folder.
step15. In the Inbound Interfaces table, select the Partner Link as client, Associate Port as HelloWorldPort. Click on Related Service then other fields will be automatically filled. Save the deploy.xml file.

bpel_hello_world6

step16. To deploy the project on the server, right click on the Ode v1.x Server at localhost, select Add and Remove Projects.
step17.Select the BPEL_HelloWorld/HelloWorld in the Available projects box and click Add. Then, click Finish

bpel_hello_world8

step18. Start the ODE server. If the deployment was successful, you will see the following output in the console tab.

bpel_hello_world9

step19. We will test the project with Web Services Explorer provided by Eclipse. Right click on the HelloWorldArtifacts.wsdl file. Select Web Services→Test with Web Services Explorer.
step20. Select the operation process. Then, type Hello ODE in the input textbox. If your deployment was success, you will get the same string in the SOAP response.

bpel_hello_world10

We are Done
Happy Coding 🙂

SOA part-1 Installing BPEL Designer and Apache ODE

Hi all, in my last project i was trying some BPEL process to execute from Eclipse and Apache ODE and finally i made the process to work so here is my experience and my tutorial to install BPEL designer in Eclipse3.6 and Apache ODE

Installing Eclipse BPEL designer
1.Suppose that you have already downloaded and installed your Eclipse > v3.6.2(Helios,or Indigo), version for Java EE Developers and JDK (version > 1.5).
2.Open the Eclipse, go to the menu Help→Install New SoftWare.
3.Click on the button Add and define a new Eclipe update site with the location:
http://download.eclipse.org/bpel/site/
4.Now you have the update-site of BPEL available on the eclipse. Select the check box to BPEL Visual Designer and click on the button Next.
5.Follow the installation windows, you will now have your BPEL installed on Eclipse. Note that: the BPEL dependencies(WTP, EMF, GEF, JEM) should be installed before the BPEL designer. Fortunately, with Eclipse Helios for JavaEE, you have all.
6.After finishing the installation, restart it.
7.To verify the installation was successful, after the restart, click on File→New→Other, you will see the BPEL 2.0 is on the list.
The BPEL designer is now ready to use. However, to run the BPEL process, you should have the server’s environment. Now, we are going to install the Apache ODE for the BPEL deployment.

Installing Apache ODE

1.Download and extract the latest ODE from the Apache web site. The current stable version is the ODE 1.3.5.
2.Inside the “apache-ode-war-1.3.5” folder, you will see an “ode.war” file. Deploy this file on your Tomcat server.
3.The simple way to do this is extracting the “ode.war” file to get the ode folder.
4.Copy this ode folder to your TOMCAT_DIR/webapps directory.
That’s all.

Setting up the ODE server on Eclipse
1.Show the “Servers” view by selecting the menu Windows→Show View→Servers.
2.Right click on the empty space of the “Servers” view, select New→Server.
3.Leave the server host name as localhost and select the server type as the Apache→Ode v1.x Server. Rename the server’s name if you want. In my installation, I keep the default name. Then click on the button Next.
4. Show the “Servers” view by selecting the menu Windows→Show View→Servers.
Right click on the empty space of the “Servers” view, select New→Server.
Leave the server host name as localhost and select the server type as the Apache→Ode v1.x Server. Rename the server’s name if you want. In my installation, I keep the default name. Then click on the button Next.

Note that: the ODE Runtime configuration above can also be added or editted using the menu Windows→Preferences→Server→Runtime Environments.

5. Click Finish. You now have the ODE server which is ready to run on the Eclipse. You can see this server on the Server View.
6.Now, you should test the server’s configuration by right click on the ODE server entry and select Start. Or you can click on the Start button on the Server View. If the server is sucessfully started, you will see the status like this.

Note:If you are using Tomcat v.6 or v.7, you probably get the error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
  at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
  at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
  ... 1 more
Could not find the main class: org.apache.catalina.startup.Bootstrap. Program will exit.

7. This error occurs maybe because it misses the tomcat-juli.jar in the Launch environment.
8. To fix this, double click on the installed Ode v1.x Server in the Server View to see the configuration.
9. k on Open launch configuration → Classpath tab → Add External JARs → [your TOMCAT_DIR]\bin\tomcat-juli.jar. Then Ok
10. Now try to start your ODE server in the Server View.
11.Terminate the server by clicking on the Stop button or right click on the server and select Stop. Every thing is

Ready now for the first BPEL program. i will be teaching the first HelloWorld BPEL Process in SOA-2 tutorial
Happy Coding 🙂