Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Swordfish Documentation: Service Development
Contents
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:
- In Eclipse menu, select File > New > Others > Swordfish > JAX-WS Service from WSDL
- Provide a project name for the service you are creating, for example FlightReservationService and click Next.
- Clear the option, Generate an activator, a Java class that controls the plug-in's life cycle and click Next.
- Select FlightReservation.wsdl from the file system and click finish. (This wsdl can be found under [1])
- 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.
- Copy the sample implementation for reserveFlight method. Use the sample implementation described below:
- 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)
- 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.
- Run Providers launch configuration, your newly created service should be up and running.
- 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.
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;
Create Payment Processing Service using the WSDL-first approach.
- Use Eclipse menu, File - New - Others - Swordfish - JAX-WS Service from WSDL
- Provide project name for the service you are creating,for example PaymentProcessingService and click next.
- Uncheck the option "Generator an activator, a Java class that controls the plug-in's life cycle" and click next.
- 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)
- 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.
- Copy sample implementation for processPayment method. Use the sample implementation described below:
- 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.
- Run Providers launch configuration, your newly created service should be up and running.
- 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 :) .
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)); }
</ol>