Jump to: navigation, search

Swordfish Documentation: Service Development

Service Development

This topic shows you how to create and run service providers.

Creating and Running Service Providers

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

Creating the service and invoke the service provider

To create and invoke the service provider using WSDL-first:

  1. In Eclipse menu, select File > New > Others > Swordfish > JAX-WS Service from WSDL
  2. Provide a project name for the service you are creating, for example FlightReservationService and click Next.
  3. Clear the option, Generate 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 [1])
  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 the 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. Edit the FlightReservationService/META-INF/spring/cxf-endpoint.xml file and fix the locationURI attribute of the endpoint element. The generated value is "http://0.0.0.0:8197/FlightReservationService/", which is wrong because the endoint in the WSDL is "http://0.0.0.0:8197/FlightReservation_Service/". This is a known issue, will be fixed soon.
  10. Run Providers launch configuration, your newly created service should be up and running.
  11. 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.

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. Edit the PaymentProcessingService/META-INF/spring/cxf-endpoint.xml file and fix the locationURI attribute of the endpoint element. The generated value is "http://0.0.0.0:8197/PaymentProcessingService/", which is wrong because the endoint in the WSDL is "http://localhost:8197/PaymentProcessing_Service/". This is a known issue, will be fixed soon.
  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 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: Do not use a year less than 2000, we have a Y2K problem in the sample implementation :) .

</ol>


Swordfish Documentation Home
Swordfish Wiki Home