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"

(Deploying the ODE artifacts into the Swordfish)
(Deploying the ODE artifacts into the Swordfish)
Line 137: Line 137:
 
<li>ODE deploy.xml [http://ode.apache.org/deployxml.html http://ode.apache.org/deployxml.html] [http://ode.apache.org/jbi-deployment.html http://ode.apache.org/jbi-deployment.html]</li>
 
<li>ODE deploy.xml [http://ode.apache.org/deployxml.html http://ode.apache.org/deployxml.html] [http://ode.apache.org/jbi-deployment.html http://ode.apache.org/jbi-deployment.html]</li>
 
<BR/>'''Steps required:'''<BR/>
 
<BR/>'''Steps required:'''<BR/>
For deployment we will use spring osgi packaging. That means that some bundle or eclipse plugin needs to embed spring xml descriptor, that will be initialized when the OSGI environment starts [http://static.springsource.org/osgi/docs/1.2.0/reference/html-single/#bnd-app-ctx http://static.springsource.org/osgi/docs/1.2.0/reference/html-single/#bnd-app-ctx] <BR/>
+
For deployment we will use spring osgi packaging. This means that some bundle or eclipse plugin needs to embed spring xml descriptor, that will be initialized when the OSGI environment starts [http://static.springsource.org/osgi/docs/1.2.0/reference/html-single/#bnd-app-ctx http://static.springsource.org/osgi/docs/1.2.0/reference/html-single/#bnd-app-ctx] <BR/>
 
<ol>
 
<ol>
 
<li>Move all the artifacts listed in the "Prerequisites" section to the dedicated directory. Lets call its path "ode_artifacts_directory". It should contain  the following files: *.bpel(BPEL process files), *.wsdl (WSDL files for the patner links), deploy.xml(ODE deployment descriptor)</li>
 
<li>Move all the artifacts listed in the "Prerequisites" section to the dedicated directory. Lets call its path "ode_artifacts_directory". It should contain  the following files: *.bpel(BPEL process files), *.wsdl (WSDL files for the patner links), deploy.xml(ODE deployment descriptor)</li>
Line 167: Line 167:
 
</process>
 
</process>
 
</deploy></pre></li>
 
</deploy></pre></li>
<li>Deploy the ODE artifacts into the Swordfish. To do this we need define org.eclipse.swordfish.plugins.ode.support.BpelArtifactExporter spring bean along with the reference to ode_artifacts_directory <BR/>
+
<li>Deploy the ODE artifacts into the Swordfish. To do this we need define org.eclipse.swordfish.plugins.ode.support.BpelArtifactExporter spring bean along with the reference to ode_artifacts_directory in the spring osgi xml descriptor<BR/>
 
  <pre>     
 
  <pre>     
 
     <bean id="bpelArtifactExporter"  
 
     <bean id="bpelArtifactExporter"  

Revision as of 05:11, 10 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 tutorial describes detailed steps for generating services using Swordfish, creating BPEL process using BPEL Editor and deploying and executing the BPEL process within ODE engine. In this tutorial we will create 2 Swordfish services, Flight Reservation Service and Payment Processing Service. We will create an Orchestration Service called Flight Booking Service which will invoke the 2 Swordfish services based on logic defined in a BPEL process.

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. Press Finish.
  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. Deploy the generated ODE artifacts into the Swordfish (see section How to deploy ODE artifacts into the Swordfish)
  5. Start the BPEL process by invoking it from the Web Service Explorer


Deploying the ODE artifacts into the Swordfish

We anticipate the Swordfish Tooling to automate all the steps described below in the nearest future.


Prerequisites:

  • The BPEL process file has been created
  • WSDL files for all the partner links
  • ODE deploy.xml http://ode.apache.org/deployxml.html http://ode.apache.org/jbi-deployment.html

  • Steps required:
    For deployment we will use spring osgi packaging. This means that some bundle or eclipse plugin needs to embed spring xml descriptor, that will be initialized when the OSGI environment starts http://static.springsource.org/osgi/docs/1.2.0/reference/html-single/#bnd-app-ctx

    1. Move all the artifacts listed in the "Prerequisites" section to the dedicated directory. Lets call its path "ode_artifacts_directory". It should contain the following files: *.bpel(BPEL process files), *.wsdl (WSDL files for the patner links), deploy.xml(ODE deployment descriptor)
    2. For the Flight Reservation Tutorial the deploy.xml should look like this
      <deploy xmlns="http://www.apache.org/ode/schemas/dd/2007/03"
      	xmlns:process="http://www.eclipse.org/swordfish/samples/FlightBookingProcess"
      	xmlns:booking="http://www.eclipse.org/swordfish/samples/FlightBooking/"
      	xmlns:reservation="http://www.eclipse.org/swordfish/samples/FlightReservation/"
      	xmlns:payment="http://www.eclipse.org/swordfish/samples/PaymentProcessing/">
      	<process name="process:FlightBookingProcess">
      		<active>true</active>
      		<in-memory>true</in-memory>
      		<process-events generate="none" />
      		<provide partnerLink="FlightBooking">
      			<service
      				name="booking:FlightBookingService"
      				port="FlightBookingSOAP" />
      		</provide>
      		<invoke partnerLink="FlightReservation">
      			<service
      				name="reservation:FlightReservationService"
      				port="FlightReservationSOAP" />
      		</invoke>
      		<invoke partnerLink="PaymentProcessing">
      			<service
      				name="payment:PaymentProcessingService"
      				port="PaymentProcessingSOAP" />
      		</invoke>
      	</process>
      </deploy>
    3. Deploy the ODE artifacts into the Swordfish. To do this we need define org.eclipse.swordfish.plugins.ode.support.BpelArtifactExporter spring bean along with the reference to ode_artifacts_directory in the spring osgi xml descriptor
          
          <bean id="bpelArtifactExporter" 
              class="org.eclipse.swordfish.plugins.ode.support.BpelArtifactExporter"
              p:bpelArtifactDirectory="classpath:ode_artifacts_directory/"/> 
      
      
    4. Also we need to deploy inbound and outbound http endpoints for the partner links
      To be able to invoke the bpel process outside the nmr, we need to declare an outbound http endpoint:
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:http="http://servicemix.apache.org/http/1.0"       
             xmlns:osgi="http://www.springframework.org/schema/osgi"
             xmlns:swordfishCxf="http://cxf.samples.swordfish.eclipse.org/"       
             xmlns:paymentProcessing="http://www.eclipse.org/swordfish/samples/PaymentProcessing/"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:flightReservation="http://www.eclipse.org/swordfish/samples/FlightReservation/"
             xmlns:flightBooking="http://www.eclipse.org/swordfish/samples/FlightBooking/"
             xsi:schemaLocation="
      	 http://www.springframework.org/schema/beans
      	 http://www.springframework.org/schema/beans/spring-beans.xsd
      	 http://www.springframework.org/schema/osgi
      	 http://www.springframework.org/schema/osgi/spring-osgi.xsd
      	 http://servicemix.apache.org/http/1.0
      	 http://servicemix.apache.org/http/1.0/servicemix-http.xsd">  
      	<bean class="org.apache.servicemix.common.osgi.EndpointExporter" />  
        	
          
          <http:endpoint                  
                       endpoint="FlightBookingSOAP"                 
                       service="flightBooking:FlightBookingService"                 
                       soap="true"
                       role="consumer"                 
                       defaultMep="http://www.w3.org/2004/08/wsdl/in-out" 
                       locationURI="http://localhost:8198/FlightBooking_Service/"
                       wsdlResource="classpath:ode_artifacts_directory/FlightBooking.wsdl"/>
      

      The FlightBooking BPEL process uses the FlightReservation and the PaymentProcessing partner links. We need to specify outbound http endpoints for them:

         <http:endpoint                  
                       endpoint="FlightReservationSOAP"                 
                       service="flightReservation:FlightReservationService"                 
                       soap="true"
                       role="provider"                 
                       defaultMep="http://www.w3.org/2004/08/wsdl/in-out" 
                       locationURI="http://localhost:8197/FlightReservation_Service/"
                       wsdlResource="classpath:ode_artifacts_directory/FlightBooking.wsdl"/>              
         <http:endpoint                  
                       endpoint="PaymentProcessingSOAP"                 
                       service="paymentProcessing:PaymentProcessingService"                 
                       soap="true"
                       role="provider"                 
                       defaultMep="http://www.w3.org/2004/08/wsdl/in-out" 
                       locationURI="http://localhost:8197/PaymentProcessing_Service/"
                       wsdlResource="classpath:ode_artifacts_directory/PaymentProcessing.wsdl"/>
          

    Swordfish Documentation Home

    Swordfish Wiki Home

Back to the top