Create an application that uses the Web Services Business Activity support
To create an application component that uses the business activity support, we must set Run EJB methods under a Business Activity scope in the deployment descriptor of the relevant application component, and if required, create and specify a compensation handler for the application to use if there is an error. We then build the component into the application and deploy the application onto a server that has the business activity support enabled. The application component can be either an enterprise bean or a web service implemented as an enterprise bean.
For information about editing deployment descriptors using Rational Application Developer, refer to the Rational Application Developer information.
Complete this task for an application that runs on a business-activity-enabled sever to use the business activity support at run time, and to undertake work that might later be compensated by a compensation handler. If the application requires compensation when a business activity scope ends, the application passes the data required by the compensation process to a compensation handler indirectly, using the business activity API. The data required by the compensation process can be in the form of either a serializable object or a Service Data Object (SDO).
Tasks
- Design the application component that requires the business activity support. In particular, define the application component requirements for compensation and close activities. If the application component requires compensation, define the nature of the data in the serializable object or the SDO that the application component passes to the compensation handler.
- Use the information from the application design, create the compensation handler for the application component, if required. This handler defines the close and compensation logic that runs upon completion of a business activity scope that has the handler added to it through an application component.
- Open your chosen WebSphere Application Server assembly tool.
- Create a new Java class that implements the appropriate interface, depending on the format of the data required by the compensation process:
- For a serializable object, implement the com.ibm.websphere.wsba.serializable.CompensationHandler interface.
- For an SDO, implement the com.ibm.websphere.wsba.CompensationHandler interface.
- Implement the close and compensate methods on the new compensation handler object, to take appropriate actions depending on the serializable or SDO data that passes to the handler when it is invoked.
The compensation handler class is now ready for the application component to reference, and for assembly into an application.
- Open the application component in the assembly tool.
- Open the deployment descriptor for the application component in the deployment descriptor viewer.
- Scroll to the Compensation section and select the Run EJB methods under a Business Activity scope check box.
- In the Compensation handler class text field, type the fully qualified class name of the compensation handler class that we created earlier.
- Save the deployment descriptor.
- Build the application, including both the application component and the compensation handler. If the application is a web service, the application must be compliant with the Java Specification Request (JSR) 109 standard.
- Deploy the application onto an application server that is business-activity-enabled.
The application is now business-activity-enabled, and can use the business activity support at run time through the business activity API. The application component has a compensation handler associated with it, and can therefore call the setCompensationDataImmediate and setCompensationDataAtCommit methods at run time to add the compensation handler to the business activity scope. For more information about these methods, see the topics about the Business activity API. If the unit of work with which the business activity scope is associated fails, the compensation handler performs actions to compensate for the error.
What to do next
Ensure that the compensation handler class is on the application class path for the WAS runtime environment.
Subtopics
- Business activity API
Use the business activity application programming interface (API) to create business activities and compensation handlers for an application component, and to log data required to compensate an activity if there is a failure in the overall business activity.
Related:
Web Services Business Activity support in the application server Transaction compensation and business activity support Development and assembly tools Configure a server to use business activity support Use the transaction service Business activity API