Example: Booking Service - Exposing a Workflow Rule as a Web Service

This example shows how to expose Web Central Workflow Rule as a Web Service. It illustrates the following use case: booking room reservations requests from an external source, such as a flat-panel display device that sits beside a conference room.

Configuration

The configuration files for the Booking Service remoting configuration are in the /WEB-INF/config/context/remoting/examples/webservices-cxf folder. To use this example, configure WebCentral according to instructions in the readme.txt , located in this folder. This configuration includes both remoting (Web Services support) and rendering (Web Central and Smart Client forms and reports support).

Limitations

The current implementation of Booking Service does not use any authentication or security. For production deployment, you need to configure WebService to use security, which is appropriate for your deployment (for example, WS-Security: http://en.wikipedia.org/wiki/WS-Security).

Example Files

The example consists of the following files in the /schema/ab-products/solutions/common/src/main/com/archibus/eventhandler/webservice folder:

  • BookingService.java . The BookingService class defines interface of the service that is implemented in BookingServiceImpl.java :
    • getBookings()
    • addBooking()
    • editBooking()
    • deleteBooking() .
  • Booking.java . The Booking object is a POJO (for Plain Old Java Object, i.e. an ordinary Java class) business object, implementing constructors and property access methods for the properties of the booking.
  • BookingServiceHandler.java . This is just a skeleton of the workflow rule event handler. It illustrates how parameters can be passed from the web service to the workflow rule.
  • BookingServiceImpl.java . Implementation of the BookingService .

Implementation

The bookingService-remote bean is defined in /WEB-INF/config/context/remoting/examples/webservices-cxf/webservices.xml .

Each invocation is intercepted by the RemotingFilter , which prepares the Web Central context: it uses the specified project ID to find and attach the project to the context. RemotingFilter also attaches the core user session to the context.

When the BookingServiceImpl object is initialized, its init() method is called. This method can perform instance initialization using the supplied context (which provides access to servlet context).

BookingServiceImpl implements BookingService business methods addBooking() , deleteBooking() , etc.

Each BookingServiceImpl business method converts the business method parameters into key/value pairs in a Java Map , and passes that Map to the ServiceHelper.WorkflowRuleInContext() method. The business method also supplies the ServiceHelper with the Web Central context and workflowRuleName .

ServiceHelper.WorkflowRuleInContext() returns an EventHandlerContext , which holds any return parameters from the workflow rule. If the return parameter is required, you can extract it from the EventHandlerContext using the getParameter() method. The getBookings() method in the example illustrates this technique.

BookingServiceHandler is a workflow rule event handler, which is called from the Web Service. It demonstrates how method names and parameters can be passed between the Web Service and the workflow rule.