Developing BPEL and SOA Application
using Java EE
Contributed
by:
Hong Lin,
PCM Reddy Maintained by:
Hong Lin
SOA is the wave of the future, and the NetBeans IDE, in addition to
providing support for developing IDE plug-in modules and rich client
applications based on the NetBeans platform, contains the NetBeans
Enterprise Pack 5.5 software which in turn provides visual design tools
for service-oriented architecture (SOA) applications. It provides BPEL
Designer, XML schema designer, WSDL editor and Identity tools for
securing webservices.
This Hands-on Lab takes you through the basics of using the BPEL
Designer component of the NetBeans Enterprise Pack 5.5 (the IDE). It
includes Web Services Orchestration - Authoring, building, deploying,
and testing BPEL processes. During this lab you will explore ways in
which the IDE enables you to edit, compile and deploy BPEL code
compliant with the WS-BPEL 2.0 specification. To assist you in
performing these tasks, there is a new type of project in the IDE that
will support the authoring, building, deploying and testing of BPEL
processes. As BPEL processes enable you to orchestrate web services,
editing BPEL and using orchestration features are important. The BPEL
Designer provides a complete environment to enable you to quickly and
efficiently orchestrate web services.
For more information on working with NetBeans
5.5 IDE, see the Support and
Docs page on the NetBeans website.
For more information on BPEL Designer, see the following technical
articles:
Expected duration: 120 minutes
Prerequisites
This tutorial assumes you have some basic knowledge of, or
programming experience with, the following technologies.
- Three months of Java programming experience
- One month of Web application programming experience
- Introductory Knowledge about WSDL, BPEL and SOA
System requirements
This tutorial assumes your system meets the following requirements.
- Supported OS: Windows XP/2000, Solaris 9/10, Linux, Mac OS X
10.4.5
- Memory: 512M minimun, 1024M recommended
- Disk space: 300M bytes
Software Needed for the Tutorial
Before you begin, you need to install the following software on your
computer.
- Java SE Development Kit (JDK)5.0 (download)
or 6.0 (download).
- If NetBeans 5.5 is already installed in your machine, please
install NetBeans Enterprise Pack 5.5 (download).
Otherwise, please install Java EE 5 Tools Bundle (download).
Notations Used in the Tutorial
- <netbeans_install_directory> - directory into which you
install the NetBeans Enterprise Pack 5.5
- <lab_root> - directory into which lab zip file is unzipped.
- This document uses <lab_root> to denote the directory
under which you have unzipped the lab zip file of this hands-on lab.
The name of the lab zip file of this hands-on lab is 8126_nbebpel.zip.
- Once you have unzipped the lab zip file under
<lab_root>, you will obtain a subdirectory called nbebpel.
For example, under Windows, if you have unzipped the lab zip file in
the root of drive C:\, it will
create C:\nbebpel. If you are using the
Solaris/Linux operating system and have have unzipped the lab zip file
in the $HOME directory, the $HOME/nbebpel
directory will be created.
- WSDL is an XML-based service description Language.
- BPEL is a XML based orchestration language, not a choreography
language. Which can only communicates using WSDL interfaces.
- A composite application consists of functionality drawn from
several different sources within a service oriented architecture (SOA).
Tutorial Exercises
Questions,
Feedback, Forums
- To send feedback, get support, and receive updates and general
information about the NetBeans Enterprise Pack, please subscribe to nbentpack@netbeans.org.
- For specific technologies included in the NetBeans Enterprise
Pack,
please follow the links to the subproject's homepage in the table in NetBeans Enterprise Pack Project
Home and user the Mailing Lists link on the left of the
page to subscribe to the appropriate mailing lists.
- General questions
about NetBeans functionality can also be asked on the nbusers@netbeans.org mailing
list.
Exercise 0: Starting Netbeans IDE and Sun
Java System App Server (10 minutes)
In this exercise, you will learn how to start the Netbeans IDE and
how to start and configure Sun Java System Application Server as a
deployment platform.
Starting NetBeans IDE
- Under Windows, do one of the following:
- Double-click on the NetBeans 5.5 icon on the desktop
- Choose Start > Programs > NetBeans 5.5 >
NetBeans IDE.
- Under Solaris/Linux, type the following commands in a terminal
window:
- cd <netbeans_install_directory>/bin
- ./netbeans
- Under Mac OS, do one of the following:
- Double-click on the NetBeans 5.5 icon on the desktop
- Type the following commands in a terminal window:
- cd <netbeans_install_directory>/Contents/MacOS
- ./netbeans
Starting Sun Java
System Application Server
- In the IDE, click Runtime tab
and expand Servers node.
Right-click Sun Java System Application Server and choose Start.
If the Start option is disabled, Restart and Stop
options are enabled, your server is already running.
Figure-01 Application Server is Running
- Expand Servers > Sun Java System Application Server 9,
JBI node should be found.
Figure-02 JBI runtime is installed
- Start web browser and check for URL
http://localhost:<http_port>. Note: Default http_port should
be 8080.
Figure-03 Check server status
Exercise 1: Getting started with the BPEL
Designer (50 minutes)
The goal of this exercise is to learn how to create, build, deploy,
run and debug a SOA sample project using BPEL Designer.
Creating the
TravelReservationService sample project
- In the IDE, from the main menu, choose File > New
Project

Figure-04 Create a new project
- In the New Project dialog box, under Categories,
expand Samples, select Service Oriented Architecture.
Under Projects, select Travel Reservation Service
project and click Next.
Figure-05 Create Travel Reservation Service sample project (Click to Enlarge)
- Accept the default values for the Project Name, Project
Location and Project Folder fields. Click Finish.

Figure-06 Name and location of the TRS sample project (Click to Enlarge)
- The Projects window now contains two project nodes: one
for a BPEL project called TravelReservationService, and one for
a Composite Application project called TravelReservationServiceApplication.
Notice a Broken Reference in the TravelReservationServiceApplication
node. This is a normal behavior. The Composite Application has a
dependency on JBI Module. You will resolve the Broken Reference later
in the Running the TravelReservationService
project section.

Figure-07 TravelReservationService project is created
Exploring the
TravelReservationService BPEL project
- In the Projects window, expand the Process Files node
under TravelReservationService node, it contains the following
items:
* TravelReservationService.bpel,
the BPEL process.
* Some *.wsdl files, the process
web service interfaces.
* OTA_TravelItinerary.xsd, a XML
Schema document.
Figure-08 Structure of the TRS project
- Double-click the TravelReservationService.bpel node. The
IDE opens a Palette of BPEL elements, a Navigator view
and a multi-view editor. This editor contains two views: Design
View and Source View.

Figure-09 Multi-view editor, Navigator and BPEL Palette (Click to Enlarge)
- Click the Source tab in Source Editor window.
Figure-10 Source view
Examining the
TravelReservationService project
- Click the Design tab to switch back
to Design view. Double-click the TravelReservationService.bpel
tab to enlarge the editor.
Figure-11 Enlarged Design view (Click to Enlarge)
- In the Design view, at the top of the diagram, a client
initiates the process by sending a message containing a travel
itinerary document. TravelReservationService receives it.

Figure-12 Client sends a travel itinerary (Click to Enlarge)
- Scroll down to see the ReceiveItinerary activity in the
Main sequence activity. The HasAirline IF
element contains two assign activities.
If the client itinerary does not contain a pre-existing airline
reservation, the itinerary will be sent to the Receive element receiveAirline
in the Partner link Airline.

Figure-13 No airline reservation (Click to Enlarge)
- Scroll down to see the Invoke element ReserveAirline
on the right side of the diagram and the Receive element ReserveAirline
in the Partner Link Airline on the left side.
The airline is reserved and a modified itinerary is sent back to the Receive
element AirlineReserved.
Figure-14 Reserve airline and return new itinerary(Click to Enlarge)
- TravelReservationService contains similar
logic for the remaining items on the itinerary.
- Double-click the TravelReservationService.bpel tab in
the source editor window to reset the size of the editor.
Running the
TravelReservationService project
- Make sure the Application Server is running by doing the
following:
- Click the Runtime tab to open
the Runtime window.
- Right-click the Sun Java System Application Server
node, if the Start item in the context menu is
disabled, your server is already running. Otherwise, choose Start.
(Please check Figure-01 Application
Server is running)
- In the Projects window, select TravelReservationServiceApplication
node, right-click and select Add JBI Module from the context
menu.
Figure-15 Adding JBI Module
- In Select Project dialog select TravelReservationService
project and click Add Project JAR Files button.

Figure-16 Adding JBI Module dialog
- Expand the ReservationPartnerServicesApplication node,
then expand JBI Modules node. A subnode TravelReservationService@SEDeployment.jar
is added.
Figure-17 Added JBI Module
- Deploy the ReservationPartnerServicesApplication to the
Sun Java System Application Server.
- Deploy the TravelReservationServiceApplication to the
Sun Java System Application Server.
- Switch to Projects. Right-click the TravelReservationServiceApplication
project node, and choose Deploy Project from the context menu.
Figure-20 Deploy TravelReservationServiceApplication
- Warning - Select Server dialog pops up. Select Sun
Java System Application Server as the target application server.
Click OK button to close this dialog.
Figure-21 Select Target Server
- Wait until you see the BUILD SUCCESSFUL message in
the Output window. Select the Runtime tab. Expand Sun
Java System Application Server > JBI > Service Assemblies
node. A new subnode is added. If it is not listed, right-click the Service
Assemblies node and select Refresh.
Figure-22 Deployed Service Assembly
- Test the TravelReservationApplication.
Debugging the
TravelReservationService project
- Enable BPEL Debugger. (Note: Your firewall software needs to be
disabled or configured properly for the BPEL runtime to start and run
properly)
- Click Attach Debugger...
to establish a Debug
Session.

Figure-28 Start a Debug Session
- Attach dialog pops up. Select the BPEL Debugger
from the Debugger drop-down menu. Set the Host and Port
fields. The Port is the value of DebuggerPort property.
Figure-29 Attach Dialog
- In the Output window, a Debugger Console window and some
Debugging windows (Watches, Local Variables, Call Stacks, Processes,
...) are opened.

Figure-30 Running Debugger (Click to Enlarge)
Note : Make sure you selected BPEL Variables tab, so that you
can watch how BPEL variables are changed during debugging process.
- Click the TravelReservationService.bpel tab in the BPEL
Editor Design view window. Switch to Source view. If the source line
numbers are not visible, select View > Show Line Numbers in
the main menu. Click line 46 to set a Toggle Breakpoint.

Figure-31 Set Breakpoint from Source view
- In the BPEL Editor window, switch to Design view.
Select HasAirline [If] element, right-click and choose Toggle
Breakpoint from the context menu. A breakpoint is added.

Figure-32 Set Breakpoint from Design view
- Set one more breakpoint for ReserveAirline [Invoke]
element. Now 3 breakpoints are added. You can also view them at the Navigator
window and Breakpoints window.

Figure-33 View Breakpoints.(Click to Enlarge)
- In the Projects window, select
TravelReservationServiceApplication node, right-click and choose Test
Project from the context menu.

Figure-34 Run Test Project
- You reach the first breakpoint. Examine the changes in BPEL
Variables Debugging window, Bpel Editor window and Navigator
window.

Figure-35 Stopped at the first breakpoint (Click to Enlarge)
Note : You can debug your BPEL process in two modes: visual debugging
in Design view and source debugging Source view. You can switch between
the two editor views.
- Click Continue (Ctrl + F5)
. At line 69, you reach the
second breakpoint. Notice the BPEL Variables are updated.

Figure-36 Stopped at the second Breakpoint (Click to Enlarge)
- Select Finish Debugger Session
to complete this
debugger session.

Figure-37 Finish Debugger Session
- Check the Debugger Console window.

Figure-38 Debugger Session is finished
Cleaning up for the next
exercise
- In the Projects window, right-click the TravelReservationServiceApplication
node , choose Undeploy Project.

Figure-39 Undeploy TravelReservationServiceApplication Composite
Application
- In Runtime window, right-click ReservationPartnerServices
node under Servers > Sun Java System Application Server >
Applications > EJB Modules, choose Undeploy.

Figure-40 Undeploy ReservationPartnerServices
-
Close the BPEL Debugger Console window and JBI Console window
under Output window. Close all remaining Debugger Windows.
- In the Projects window, close all opened projects:
ReservationPartnerServices, TravelReservationService and
TravelReservationServiceApplication.

Figure-41 Close all opened projects
- Close all opened Editor windows.
Summary
In this exercise, you deployed, performed a
test run and debug a sample SOA BPEL Project. You learned how to
perform the following tasks:
Get to know about a BPEL project and a Composite Application.
Get to know about BPEL Editor/Navigator/Mapper.
Deploy and perform a test run of the BPEL project.
Debug the BPEL project.
Exercise 2: Developing BPEL and SOA using
Java EE (50 minutes)
The goal of this exercise is to learn how to develope a SOA Web
Application using Java EE.
Unzipping the
LoanProcessoring projects
- In your file
system, create a directory named LoanProcessing
under <lab_root>/BPELTut.
- Unzip the <lab_root>/BPELTut/LoanProcessing.zip
file into the directory.
Opening the
LoanProcessing projects
- In the IDE, from
the main menu, choose File > Open Project.
- Navigate to the LoanProcessing directory that you
just created and select the LoanProcessor
and LoanRequestorBpel
projects. Click Open Project Folder.

Figure-42 Open LoanProcessing projects (Click to Enlarge)
- A progress dialog box appears, and
then the project appears in the Projects window.

Figure-43 LoanProcessing projects are opened
Creating a Composite
Application Project
- From the IDE's
main menu, choose File >New Project.
- Under Categories select Service Oriented Architecture.
Under Projects, select Composite
Application.

Figure-44 Create a new Composite Application project (Click to Enlarge)
- Click Next.
- Type LoanProcessingCA in the Project
Name field. In the Project Location field, type the LoanProcessing directory that you
just created.
- Click Finish. The new project LoanProcessingCA appears in the Projects
window.

Figure-45 New Composite Application project is created
- Right-click the LoanProcessingCA node, select Add
JBI Module. The Select Project wizard appears.
- In the wizard, in the Look in field
select LoanProcessing
and then select LoanRequestorBpel
for the Project Name.

Figure-46 Add JBI Module
- Click Add
Project JAR Files button.
- In Projects window, expand LoanProcessingCA > JBI Modules.
Notice LoanRequestorBpel.jar
node is added.

Figure-47 JBI Module is added
Deploying the
LoanProcessor EJB Module
- In the Projects
window, right-click the LoanProcessor
project node and choose Deploy Project from the contextual menu.
- Wait until you see
the BUILD SUCCESSFUL
message in the Output window.
- Switch to Runtime, expand Servers > Sun Java System Application
Server > Applications > EJB Modules.
Notice LoanProcessor
node under EJB Modules.

Figure-48 LoanProcessor is deployed
Creating
LoanApplication Web Application
- From the IDE's
main menu, choose File >New Project.
- Under Categories select Web. Under Projects,
select Web Application.

Figure-49 Creating new Web Application
- Click Next.
- Type LoanApplication in the project
name and accept the defaults.

Figure-50 Set project name LoanApplicationWS ( Click to Enlarge)
- Click Finish.
- In the Projects window, the LoanApplication node is added.
Adding BPEL Web Service
Client to the Web Application
- In the Projects
window, right-click the LoanApplication
project node and choose New >File/Folder.
- In the wizard, under Categories
select Web Services.
Under File Types, select Web
Service Client.

Figure-51 New Web Service Client
- Click Next.
- In the wizard, under Specify the
WSDL file of the Web Service check the Local File radio
button, browse to the location of the LoanRequestor.wsdl file, which
is under LoanProcessing\loanProcessing\LoanRequestorBpel\src.
Under Specify a location for the client, type loanprocesswsclient in the Package
and accept the defaults.

Figure-52 Set WSDL and Client location (Click to Enlarge)
- Click Finish.
- Expand LoanApplication > Web Service References.
Notice LoanRequestor
node is added.

Figure-53 New Web Service Client is added
Creating and editing .jsp
files
- In the Projects
window, right-click the LoanApplication
project node and choose New >File/Folder.
- In the wizard, under Categories
select Web. Under File
Types, select JSP.
Click Next.

Figure-54 Creating a new JSP file
- In the wizard, type loanclient in the JSP File Name
field and accept the defaults. Click Finish.

Figure-55 Set file name and location (Click to Enlarge)
- Expand LoanApplication > Web Pages.
Notice loanclient.jsp
node is added. In Editor window, loanclient.jsp
file is opened.

Figure-56 loanclient.jsp is created
- In loanclient.jsp
source Editor window, right-click, select Web Service Client Resource > Call Web
Service Operation from the contextual menu.

Figure-57 Call Web Service Operation
- In the Select Option to Invoke
pop up dialog, expand LoanApplication
> LoanRequestor > LoanRequestorService > LoanRequestorPortName.
Select requestLoan
option.

Figure-58 Select Operation to Invoke
- Click OK.

Figure-59 Web Service invocation is added
- Now modify loanclient.jsp
file (you can also copy loanclient.jsp
to replace the one you just created):
- Replace
<title>JSP Page</title>
to:
<title>Loan Application Status</title>
- Replace
<h1>JSP Page</h1>
to:
<h1>Loan Application Status</h1>
- Replace
loanprocesswsclient.ProcessApplication requestPart = null;
to:
loanprocesswsclient.ProcessApplication requestPart = new
loanprocesswsclient.ProcessApplication();
- Add the following codes under // TODO process result here
requestPart.setSocialSecurityNumber(request.getParameter("ssn"));
requestPart.setApplicantName(request.getParameter("name"));
requestPart.setApplicantAddress(request.getParameter("address"));
requestPart.setApplicantEmailAddress(request.getParameter("email"));
requestPart.setApplicantAge(Integer.parseInt(request.getParameter("age")));
requestPart.setApplicantGender(request.getParameter("gender"));
requestPart.setAnnualSalary(Float.parseFloat(request.getParameter("salary")));
requestPart.setAmountRequested(Float.parseFloat(request.getParameter("loanamount")));
- Replace
out.println("Result = "+result);
to:
out.println("Result = "+result.getReturn());
- Add the following codes under // TODO handle custom
exceptions here
out.println("===>>>Exception : " + ex.toString());
- Add the following codes under // <%-- end web service
invocation --%><hr/>
<form action="index.jsp">
<input type="submit" value="Back To Loan Application"/>
</form>
- Now modify index.jsp file
(you can also copy index.jsp to
replace the one you just created):
- Add the following codes before </body>
<form action="loanclient.jsp">
<table>
<tr>
<td>SSN</td><td> <input type="text" name="ssn"
value="123456789"/></td><td></td>
</tr><tr>
<td>Name </td><td><input type="text" name="name"
value="ORCHBank User"/></td><td></td>
</tr><tr>
<td>Address</td><td><input type="text" name="address"
value="16 Network Circle, Menlo Park,CA" /></td><td></td>
</tr><tr>
<td>Email</td><td><input type="text" name="email"
value="orchbankuser@bankmail.com" /></td><td></td>
</tr><tr>
<td>Age</td><td><input type="text" name="age"
value="27" /></td><td>Age Limit : Min = 18, Max = 69,
</td>
</tr><tr>
<td>Gender</td><td><input type="text" name="gender"
value="male" /></td><td></td>
</tr><tr>
<td>Salary</td><td><input type="text" name="salary"
value="56789.10" /></td><td>Minimun Salary = 20000.00</td>
</tr><tr>
<td>Loan Amount</td><td><input type="text"
name="loanamount" value="19500.00" /></td><td>Requested Loan amount should not be more than 3 times Salary</td>
</tr><tr>
<td></td><td><input type="submit" value="submit"
name="Submit Application" /></td></tr><td></td>
</table>
</form>
- Click Save All.
Manipulating
LoanRequestor.bpel project
Next, we are going to introduce
additional business rule to existing BPEL process.
- In the Projects
window, expand LoanRequestorBpel
> Process Files. Double click LoanRequestor.bpel node to open
it into Editor window Design
view.
- From the Palette, drag an If activity to the design area
between the ReceiveFromCustomer
and AssignReceiveToEJBInput
activities.

Figure-60 Drag and drop an If activity (Click to Enlarge)
- From the Palette, drag a Sequence activity to the design
area between the the two large X icons in the If1 activity area.

Figure-61 Drag and drop a Sequence activity
- In the Design view, drag the existing
activities AssignReceiveToEJBInput,
InvokeEJBPartner and AssignEJBOutputToReply
in to the Sequence1
activity area.

Figure-62 Move existing activities into Sequence1
- In the Palette, drag an Assign activity to the design
area, place it to the right of the existing Sequence1 activity.

Figure-63 Add Assign1
activities
- In the Design view, click the If1 activity.
The Mapper appears at the button of the IDE. If the Mapper is not
visible, choose Window > BPEL Mapper in the main menu. You
use the Mapper Editor to define the Boolean condition.
Notice the sections at the top of the Mapper make up the Method Palette.

Figure-64 BPEL Mapper (Click
to Enlarge)
- Add Div operator in the middle pane.

Figure-65 Add Div operator
- Add Greater Than operator next to Div operator

Figure-66 Add Greater Than operator
- Add Number literal just below Greater Than
operator.

Figure-67 Add Number Literal operator
- Set the value to 3. This is the rule BPEL process allies on top
of EJB loan process.

Figure-68 Set value
- Add Boolean Not operator.

Figure-69 Add Not operator
- Connect All operators as shown below.

Figure-70 Connect all operators (Click to Enlarge)
- Click Save All.
Note : Now we are adding a business rule to BPEL process. Requested
Loan amount can not exceed 3 times the salary.
Deploying the
LoanApplication Web Application
- In Projects
window, right-click the LoanApplication
project node, choose Clean and Build Project.
- Right-click the LoanApplication
project node again, choose Deploy Project.
- Deployment has succeeds if you see BUILD SUCCESSFUL message appears
in the Output window, and LoanApplication
node is added under Sun Java System
Application Server > Applications > Web Applications
in Runtime window.

Figure-71 LoanApplication is deployed
Deploying the
LoanProcessingCA Composite Application
- In Projects
window, right-click the LoanProcessingCA
project node, and choose Deploy Project.
- In the Warning -
Select Server dialog box, make sure the Sun Java System Application
Server is selected and click OK.
- Deployment has succeeds if you see BUILD SUCCESSFUL message appears
in the Output window, and LoanProcessingCA
node is added under Sun Java System
Application Server > JBI > Service Assemblies in
Runtime window.

Figure-72 LoanProcessingCA is deployed
Running the index.jsp
- In the Projects
window, expand LoanApplicationWS
> Web Pages> WEB-INF. Select index.jsp node, right-click, and
choose Run File in the contextual menu.
- You will see BUILD SUCCESSFUL message appears
in the Output window, and the URL that the index.jsp is browsing.

Figure-73 Running index.jsp
- A browser should be brought up. If
not, bring up a browser and type in the URL that is listed in the
Output [LoanApplicationWS (run)] window.

Figure-74 Browsing index.jsp
- In the Browser, click the submit
button. Loan Application Status is displayed.

Figure-75 Loan Application Approved
- Click the Back To
Loan Application button.
- Modify the Loan
Amount in the Loan Application page from 19500.00 to 200000.00. Click submit button
again.
- Now the application is rejected.

Figure-76 Loan Application Rejected
Observe this message is coming from BPEL process.
Summary
In this exercise, you learned how to perform the following tasks:
Create a Composite Application project.
Create a Web Application.
Add BPEL Web Service Client to the Web Application.
Manipulate business rule in a BPEL process.
Verifying Communication between Web Application BPEL process.
Next Steps
To send comments and suggestions, get support, and keep informed on
the latest developments on the NetBeans IDE J2EE development features,
join the nbusers@netbeans.org
mailing list.