To create an application component that
uses the business activity
support, you 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. You 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 that is implemented as an enterprise
bean.
Before you begin
For information about editing deployment descriptors
by using Rational® Application
Developer, refer to the Rational Application Developer
information.
About this task
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 that is required by the compensation process to a
compensation
handler indirectly, by using the business activity API. The data that
is required
by the compensation process can be in the form of either a serializable
object
or a Service Data Object (SDO).
Procedure
- 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.
- Using the information from your 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 that is 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
you 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.
Results
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 WebSphere Application Server
runtime environment.