Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Swordfish Documentation: Flight Reservation Tutorial"

(Prerequisites)
Line 1: Line 1:
==Flight Reservation Tutorial==
+
==Flight Booking Tutorial==
 
<pre>Everything in this section is still in draft state. It will be subject to review and editing by the Swordfish team members.</pre>
 
<pre>Everything in this section is still in draft state. It will be subject to review and editing by the Swordfish team members.</pre>
 
===What this tutorial covers===
 
===What this tutorial covers===

Revision as of 09:33, 4 August 2009

Flight Booking Tutorial

Everything in this section is still in draft state. It will be subject to review and editing by the Swordfish team members.

What this tutorial covers

This is a short tutorial describing detailed steps for generating services using Swordfish, creating BPEL process using BPEL Editor and deploying and executing the BPEL process within ODE engine.

What it does not cover

This tutorial assumes that the user is familiar with the Eclipse IDE and Java programming. This tutorial does not provide an introduction to the Eclipse IDE, Eclipse runtime projects or to the Java programming language.

Prerequisites

  • Java 6 runtime enviornment.
  • Eclipse Galileo (Eclipse 3.5) build or later. The examples described here are based on Eclipse 3.5.
  • Swordfish Runtime Framework
  • Swordfish Tooling
  • ODE bundles from the Swordfish update site

Getting Started

Before you start, download and install Swordfish Tooling in Eclipse IDE from http://soaswordfishdemo.googlecode.com/svn/trunk/SOADemoSite/ Update site. Next you have to create a target platform.
For instructions, see Swordfish User Guide, section "Getting Started with Swordfish" within the Eclipse IDE Help.

Service Development


Creating and Running Service Providers

This topic contains instructions on how to create service providers with WSDL-first approach (Flight reservation and Payment processing).


To create the service and invoke the service provider:

  1. Create Flight Reservation Service using the WSDL-first approach.
    1. Use Eclipse menu, File - New - Others - Swordfish - JAX-WS Service from WSDL
    2. Provide project name for the service you are creating,for example FlightReservationService and click next.
    3. Uncheck the option "Generator an activator, a Java class that controls the plug-in's life cycle" and click next.
    4. Select FlightReservation.wsdl from the file system and click finish. (This wsdl can be found under http://code.google.com/p/odeintegration/source/browse/trunk/EclipseSOADemo/wsdls/FlightReservation.wsdl)
    5. FlightReservationService project will be created with an empty implementation. You can find the empty implementation in FlightReservationService/src/org.eclipse.swordfish.samples.flightreservation/FlightReservationImpl java class. Inside this class, have a look at the implementation for the method reserveFlight, the empty implementation returns an empty string.
    6. Copy sample implementation for reserveFlight method. Use the sample implementation described below:
    7.         LOG.info("Executing operation reserveFlight");
              String _return;
              StringBuffer strbuf = new StringBuffer();
              strbuf.append("Received reservation request for flight ");
              strbuf.append(flightData.flightNumber);
              strbuf.append(" on ");
              strbuf.append(flightData.date.toXMLFormat());
              if (flightData.flightNumber.startsWith("LH")) {
                  strbuf.append(", flight reservation OK");
              	_return = "OK";
              } else {
                  strbuf.append(", flight reservation FAILED (unknown flight number)");
              	_return ="FAIL/unknown flight";        
          	}
              System.out.println(strbuf);
              return _return;
      

    8. Create a new Run configuration using Eclipse menu, Run - Run Configurations - OSGI Framework - New (Name for example Providers). This new launch configuration should include your workspace and Swordfish target platform (For instructions, see Swordfish User Guide, section "Getting Started with Swordfish" within the Eclipse IDE Help)
    9. Run Providers launch configuration, your newly created service should be up and running.
    10. Use an external Webservice invocation tool like for example SOAPUI, and invoke the reserveFlight operation of your FlightReservationService. If the flight number in request starts with "LH" you should get a success response else a fail response.
  2. Create Payment Processing Service using the WSDL-first approach.
    1. Use Eclipse menu, File - New - Others - Swordfish - JAX-WS Service from WSDL
    2. Provide project name for the service you are creating,for example PaymentProcessingService and click next.
    3. Uncheck the option "Generator an activator, a Java class that controls the plug-in's life cycle" and click next.
    4. Select PaymentProcessing.wsdl from the file system and click finish.(This wsdl can be found under http://code.google.com/p/odeintegration/source/browse/trunk/EclipseSOADemo/wsdls/PaymentProcessing.wsdl)
    5. PaymentProcessingService project will be created with an empty implementation. You can find the empty implementation in PaymentProcessingService/src/org.eclipse.swordfish.samples.paymentprocessing/PaymentProcessingImpl java class. Inside this class, have a look at the implementation for the method processPayment, the empty implementation returns an empty string.
    6. Copy sample implementation for processPayment method. Use the sample implementation described below:
    7.        public java.lang.String processPayment(org.eclipse.swordfish.samples.paymentprocessing.PaymentData paymentData) { 
             LOG.info("Executing operation processPayment");
             String _return;
             StringBuffer strbuf = new StringBuffer();
             strbuf.append("Received payment processing request for card number ");
             strbuf.append(paymentData.creditCardNumber);
             strbuf.append(" expiring ");
             strbuf.append(paymentData.creditCardExpiry);
             String parts[] = paymentData.creditCardExpiry.split("/");
             if (isValid(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]))) {
                 strbuf.append(", payment OK");
             	_return = "OK";
             } else {
                 strbuf.append(", payment FAILED (card expired)");
             	_return ="FAIL/credit card expired";        
         	}
             System.out.println(strbuf);
             return _return;
         }
      


         private boolean isValid (int month, int year) {
             Calendar today = GregorianCalendar.getInstance();
         	return (year >= (today.get(Calendar.YEAR)-2000)) && (month >= today.get(Calendar.MONTH));
         }
      

    8. Run Providers launch configuration, your newly created service should be up and running.
    9. Use an external Webservice invocation tool like for example SOAPUI, and invoke the processPayment operation of your PaymentProcessingService. If the credit card expiry date in request is of current or future, you should get a success response else a fail response (The format to be used for the date is MM/YY, NOTE: Plz do not use a year less than 2000, we have a Y2K problem in the sample impl :) ).


Service Orchestration

Creating and Running a BPEL Process

To create and run a BPEL process:

  1. Go to the SOPERA update site http://soaswordfishdemo.googlecode.com/svn/trunk/SOADemoSite/ and install Eclipse BPEL Designer.
  2. Install ODE
    1. Go to Eclipse Menu, Eclipse - Preferences - Plug-in Development - Target Platform. Select Swordfish Target platform and click "Edit".
    2. Click "Add", select "Software Site" and press "Next". Use "http://soaswordfishdemo.googlecode.com/svn/trunk/SOADemoSite/" Update site and install "Swordfish ODE Integration".



  3. Create a target platform provisioning tool. Include Swordfish runtime and ODE.
  4. Create a new BPEL process project (for the Flight Booking use case scenario)
    1. Design your BPEL process by dragging process element icons from the context menu and dropping it onto the design pane.
    2. For each step you create, define a corresponding partner link
    3. Start an Ant task to create a deployment package (ensure that the Service Units for Binding Components are ready).
    4. Copy the deployment package into the ODE deployment directory
    5. Alternatively, you can generate it into the workspace and deploy the bundle into a target platform.
  5. Start the BPEL process by invoking it from the Web Service Explorer



Swordfish Documentation Home
Swordfish Wiki Home

Back to the top