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.

System requirements

This tutorial assumes your system meets the following requirements.

Software Needed for the Tutorial

Before you begin, you need to install the following software on your computer.

Notations Used in the Tutorial

Tutorial Exercises

Questions, Feedback, Forums


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

  1. Under Windows, do one of the following:


  2. Under Solaris/Linux, type the following commands in a terminal window:

  3. Under Mac OS, do one of the following:

Starting Sun Java System Application Server

  1. 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

  2. Expand Servers > Sun Java System Application Server 9, JBI node should be found.


    Figure-02 JBI runtime is installed

  3. 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

  1. In the IDE, from the main menu, choose File > New Project


    Figure-04 Create a new project

  2. 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)

  3. 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)

  4. 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

  1. 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

  2. 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)

  3. Click the Source tab in Source Editor window.


    Figure-10 Source view

Examining the TravelReservationService project

  1. 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)

  2. 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)

  3. 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.

  4. Figure-13 No airline reservation (Click to Enlarge)

  5. 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)

  6. TravelReservationService contains similar logic for the remaining items on the itinerary.

  7. Double-click the TravelReservationService.bpel tab in the source editor window to reset the size of the editor.

Running the TravelReservationService project

  1. Make sure the Application Server is running by doing the following:
  2. In the Projects window, select TravelReservationServiceApplication node, right-click and select Add JBI Module from the context menu.


    Figure-15 Adding JBI Module

  3. In Select Project dialog select TravelReservationService project and click Add Project JAR Files button.


    Figure-16 Adding JBI Module dialog

  4. Expand the ReservationPartnerServicesApplication node, then expand JBI Modules node. A subnode TravelReservationService@SEDeployment.jar is added.


    Figure-17 Added JBI Module

  5. Deploy the ReservationPartnerServicesApplication to the Sun Java System Application Server.

  6. Deploy the TravelReservationServiceApplication to the Sun Java System Application Server.
  7. Test the TravelReservationApplication.

Debugging the TravelReservationService project

  1. Enable BPEL Debugger. (Note: Your firewall software needs to be disabled or configured properly for the BPEL runtime to start and run properly)

  2. Click Attach Debugger... to establish a Debug Session.


    Figure-28 Start a Debug Session

  3. 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

  4. 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)

  5. Note : Make sure you selected BPEL Variables tab, so that you can watch how BPEL variables are changed during debugging process.

  6. 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

  7. 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

  8. 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)

  9. In the Projects window, select TravelReservationServiceApplication node, right-click and choose Test Project from the context menu.


    Figure-34 Run Test Project

  10. 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)

  11. 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.

  12. 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)

  13. Select Finish Debugger Session to complete this debugger session.


    Figure-37 Finish Debugger Session

  14. Check the Debugger Console window.


    Figure-38 Debugger Session is finished

Cleaning up for the next exercise

  1. In the Projects window, right-click the TravelReservationServiceApplication node , choose Undeploy Project.


    Figure-39 Undeploy TravelReservationServiceApplication Composite Application

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


    Figure-40 Undeploy ReservationPartnerServices

  3. Close the BPEL Debugger Console window and JBI Console window under Output window. Close all remaining Debugger Windows.

  4. In the Projects window, close all opened projects: ReservationPartnerServices, TravelReservationService and TravelReservationServiceApplication.


    Figure-41 Close all opened projects

  5. 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

    1. In your file system, create a directory named LoanProcessing under <lab_root>/BPELTut.
    2. Unzip the <lab_root>/BPELTut/LoanProcessing.zip file into the directory.

    Opening the LoanProcessing projects

    1. In the IDE, from the main menu, choose File > Open Project.
    2. 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)

    1. 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

    1. From the IDE's main menu, choose File >New Project.
    2. Under Categories select Service Oriented Architecture. Under Projects, select Composite Application.

    3. Figure-44 Create a new Composite Application project (Click to Enlarge)

    4. Click Next.
    5. Type LoanProcessingCA in the Project Name field. In the Project Location field, type the LoanProcessing directory that you just created.
    6. Click Finish. The new project LoanProcessingCA appears in the Projects window.

    7. Figure-45 New Composite Application project is created

    8. Right-click the LoanProcessingCA node, select Add JBI Module. The Select Project wizard appears.
    9. In the wizard, in the Look in field select LoanProcessing and then select LoanRequestorBpel for the Project Name.

    10. Figure-46 Add JBI Module

    11. Click Add Project JAR Files button.
    12. In Projects window, expand LoanProcessingCA > JBI Modules.
      Notice LoanRequestorBpel.jar node is added.


      Figure-47 JBI Module is added

    Deploying the LoanProcessor EJB Module

    1. In the Projects window, right-click the LoanProcessor project node and choose Deploy Project from the contextual menu.
    2. Wait until you see the BUILD SUCCESSFUL message in the Output window.
    3. 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

    1. From the IDE's main menu, choose File >New Project.
    2. Under Categories select Web. Under Projects, select Web Application.

    3. Figure-49 Creating new Web Application

    4. Click Next.
    5. Type LoanApplication in the project name and accept the defaults.

    6. Figure-50 Set project name LoanApplicationWS ( Click to Enlarge)

    7. Click Finish.
    8. In the Projects window, the LoanApplication node is added.

    Adding BPEL Web Service Client to the Web Application

    1. In the Projects window, right-click the LoanApplication project node and choose New >File/Folder.
    2. In the wizard, under Categories select Web Services. Under File Types, select Web Service Client.


    Figure-51 New Web Service Client

    1. Click Next.
    2. 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)

    1. Click Finish.
    2. Expand LoanApplication > Web Service References.
      Notice LoanRequestor node is added.


    Figure-53 New Web Service Client is added

    Creating and editing .jsp files

    1. In the Projects window, right-click the LoanApplication project node and choose New >File/Folder.
    2. In the wizard, under Categories select Web. Under File Types, select JSP. Click Next.


    Figure-54 Creating a new JSP file

    1. 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)

    1. Expand LoanApplication > Web Pages.
      Notice loanclient.jsp node is added. In Editor window, loanclient.jsp file is opened.


    Figure-56 loanclient.jsp is created

    1. 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

    1. In the Select Option to Invoke pop up dialog, expand LoanApplication > LoanRequestor > LoanRequestorService > LoanRequestorPortName. Select requestLoan option.


    Figure-58 Select Operation to Invoke

    1. Click OK.


    Figure-59 Web Service invocation is added

    1. Now modify loanclient.jsp file (you can also copy loanclient.jsp to replace the one you just created):
    1. Now modify index.jsp file (you can also copy index.jsp to replace the one you just created):
    1. Click Save All.

    Manipulating LoanRequestor.bpel project

    Next, we are going to introduce additional business rule to existing BPEL process.

    1. In the Projects window, expand LoanRequestorBpel > Process Files. Double click LoanRequestor.bpel node to open it into Editor window Design view.
    2. From the Palette, drag an If activity to the design area between the ReceiveFromCustomer and AssignReceiveToEJBInput activities.

    3. Figure-60 Drag and drop an If activity (Click to Enlarge)

    4. From the Palette, drag a Sequence activity to the design area between the the two large X icons in the If1 activity area.

    5. Figure-61 Drag and drop a Sequence activity

    6. In the Design view, drag the existing activities AssignReceiveToEJBInput, InvokeEJBPartner and AssignEJBOutputToReply in to the Sequence1 activity area.

    7. Figure-62 Move existing activities into Sequence1

    8. In the Palette, drag an Assign activity to the design area, place it to the right of the existing Sequence1 activity.

    9. Figure-63 Add Assign1 activities

    10. 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.

    11. Figure-64 BPEL Mapper (Click to Enlarge)

    12. Add Div operator in the middle pane.


      Figure-65 Add Div operator

    13. Add Greater Than operator next to Div operator


      Figure-66 Add Greater Than operator

    14. Add Number literal just below Greater Than operator.


      Figure-67 Add Number Literal operator

    15. Set the value to 3. This is the rule BPEL process allies on top of EJB loan process.


      Figure-68 Set value

    16. Add Boolean Not operator. 


      Figure-69 Add Not operator

    17. Connect All operators as shown below.


      Figure-70 Connect all operators (Click to Enlarge)

    18. 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

    1. In Projects window, right-click the LoanApplication project node, choose Clean and Build Project.
    2. Right-click the LoanApplication project node again, choose Deploy Project.
    3. 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

    1. In Projects window, right-click the LoanProcessingCA project node, and choose Deploy Project.
    2. In the Warning - Select Server dialog box, make sure the Sun Java System Application Server is selected and click OK.
    3. 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

    1. In the Projects window, expand LoanApplicationWS > Web Pages> WEB-INF. Select index.jsp node, right-click, and choose Run File in the contextual menu.
    2. 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

    1. 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

    1. In the Browser, click the submit button. Loan Application Status is displayed.


    Figure-75 Loan Application Approved

    1. Click the Back To Loan Application button.
    2. Modify the Loan Amount in the Loan Application page from 19500.00 to 200000.00. Click submit button again.
    3. 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.