Tuesday, 18 October 2011

Generating SwitchYard BPEL applications

With the release of Savara Eclipse Tools 2.0.0.M5, it is now possible to generate BPEL projects that can be deployed to the new jboss.org ESB called SwitchYard. This post explains how to generate an example application and deploy it to the ESB. BPEL support will be available in version 0.3 of SwitchYard, due to be released early November 2011.

Setting up your Eclipse environment

First step is to set up your Eclipse environment. If you don't already have an Eclipse environment, then we suggest downloading the JEE version of Indigo from http://www.eclipse.org/downloads/.

Once you have installed Eclipse, run it up and go to the Help->Install New Software menu item. Enter the Savara Update Site (http://downloads.jboss.org/savara/releases/updates/2.0.x) location into the top text field and press the return key. In the main panel it will show a tree with the categories Savara and Savara Dependencies at the top level. Select both of these categories, and then press the Finish button. Follow the instructions presented by the update manager until you will be requested to restart your Eclipse environment.

Importing the Purchasing Example project

The purchasing example can be found here: http://downloads.jboss.org/savara/examples/purchasing.zip

Once this file has been downloaded, go to the Eclipse environment and select the context menu from within the Project Explorer. Select the "Import ...->General->Existing Projects into Workspace" menu item, then when the dialog is displayed, choose the "Select archive file" radio button and use the "Browse" button to locate the downloaded purchasing.zip file.

When the 'Finish' button is pressed, the purchasing project will be imported into the Project Explorer.

Generate the SwitchYard BPEL Projects

When the purchasing project is expanded, you will find a choreography file in the top level folder called PurchaseGoods.cdm. Select the context menu for this file, and choose the menu item "Savara->Generate->Service", as shown in the following image:


This menu item will cause the following dialog to be displayed:


Select the 'Switchyard BPEL' Service Type for each of the service roles, and then press the 'OK' button to generate the three projects.

If you expand the PurchaseGoodsProcess-Store project, you will see that the artifacts for the Switchyard BPEL application are primarily contained within the src/main/resources folder:


Adding Implementation Details

The generated project contains an 'abstract' version of the BPEL process definition, outlining how it interacts with any consumers, or external services. However it does not contain all of the implementation logic, as this is not available within the choreography description from which the BPEL process was generated.

As a short cut, we have provided a version of the BPEL processes for this example, with the implementation details fully completed. This can be downloaded from here: http://downloads.jboss.org/savara/examples/purchasing_bpel_impl.zip

In this zip you will find three BPEL processes. These should be used to replace the generated versions - although if curious, first copy them to another location in your Eclipse environment, and perform a comparison to see the differences. For example, select the PurchaseGoodsProcess_Store.bpel from the generated project, and the version obtained from the downloaded zip, and use the "Compare With->Each Other" menu item and you will see:


The generated version on the left contains the main structure of the process, and the interaction statements (e.g. receive, reply, invoke). The 'one we prepared earlier' version on the right adds assignment and condition statements.

Running the Example

The final step is to package and deploy the SwitchYard applications. The SwitchYard version we will be using is the 0.3 AS7 based distribution. (Note: version 0.3 will be released early November 2011).

For each of the generated projects, from the project node in the explorer select "Export ..." from the context menu. From the dialog select "Java->JAR file", and in the next dialog specify the location of where the Jar should be stored. For example, you could create a Store.jar, CreditAgency.jar and Logistics.jar.

Once the SwitchYard server has been started, using the "./standalone.sh" command in the bin folder, copy the three SwitchYard BPEL applications into the $AS7/standalone/deployments folder.

When a service has been successfully deployed, you will see messages similar to the following associated with the LogisticsService:

14:46:48,820 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-2) Setting the server's publish address to be http://127.0.0.1:18001/LogisticsService
14:46:48,858 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployed "Logistics.jar"

Lastly, using your favourite SOAP client (e.g. SOAPUI), send the following message to http://127.0.0.1:18001/StoreService:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stor="http://www.jboss.org/examples/store">   <soapenv:Header/>
<soapenv:Body>
<stor:BuyRequest id="1" product="bike" customer="Joe"/>
</soapenv:Body>
</soapenv:Envelope>

you will get a response:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<soap-env:Body>
<BuyConfirmed id="1" xmlns="http://www.jboss.org/examples/store" />
</soap-env:Body>
</soap-env:Header>
</soap-env:Envelope>

If you now change the request so the customer is "Fred", then you will receive an 'AccountNotFound' fault.