WebSphere software logo IBM Logo

JTA Extensions sample

The Java Transaction API (JTA) extensions notify an application of the completion of every transaction that runs on a server. Applications receive notification of each transaction beforeCompletion and afterCompletion events, by registering an implementation of the SynchronizationCallback interface. This sample comprises a servlet that registers for synchronization callbacks when it is initialized. The servlet displays a table detailing every completed transaction on the server since registration. For the user's convenience, an option is provided to run a new transaction that can either be commited or rolled back.

Time required to set up and configure this sample

10 minutes

Prerequisites for use

WebSphere Application Server. This sample was tested most recently with Version 8 of the product.

Copyright license

COPYRIGHT LICENSE: This information contains sample code provided in source code form. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample code is written. Notwithstanding anything to the contrary, IBM PROVIDES THE SAMPLE SOURCE CODE ON AN "AS IS" BASIS AND IBM DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND ANY WARRANTY OR CONDITION OF NON-INFRINGEMENT. IBM SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR OPERATION OF THE SAMPLE SOURCE CODE. IBM HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS TO THE SAMPLE SOURCE CODE.

About this task

The following key phrases are associated with this sample: ExtendedJTATransaction, "JTA Extensions", beforeCompletion, afterCompletion, SynchronizationCallback

ExtendedJTATransaction

This interface provides a WebSphere programming model extension to the Java EE JTA support. An object implementing this interface will be bound, by WebSphere product Java EE containers that support this interface, at java:comp/websphere/ExtendedJTATransaction.

The main features to note in the sample are the lookup of the ExtendedJTATransaction object and the registration of the SynchronizationCallback, both of which are performed in the init method of the TransactionTracker servlet.

The beforeCompletion and afterCompletion methods are the methods that are driven by the ExtendedJTATransaction functionality whenever a transaction undergoes completion, following the registration of a callback.

For more information, see the API documentation in the WebSphere Application Server Information Center.

Procedure

  1. Build the sample.
    1. Identify the directory structure
      Locate the JTA Extensions Sample in the following directories:
      samples_root/src Contains the sample source code for the JTA Extensions Sample.
      samples_root/installableApps Contains the EAR file comprising the built JTA Extensions sample application: JTAExtensionsSample.ear. This directory is created when the sample is built.
      samples_root/javadoc Contains the API documentation generated when the sample is built.
      samples_root/scripts Contains the script files used to build the sample.

    2. Run the samples build script.
      On Windows operating systems:
      In directory profile_root/bin type setupCmdLine at the the command line.
      In directory samples_root type samples_root/scripts/buildsamples.bat.

      On Linux and UNIX operating systems:
      In directory profile_root/bin type . ./setupCmdLine.sh at the the command line.
      In directory samples_root type samples_root/scripts/buildsamples at the command line.

      The buildsamples.bat and the buildsamples scripts in the samples_root/scripts directory run the Ant build utility. Ant reads the build.xml files, which describe how to build the sample. Refer to the Ant web site for additional documentation on Ant.

      During the build process, only class files that have changes are rebuilt. The remaining class files are repackaged into the new Enterprise Archive (EAR) file.

  2. Install and run the sample.
    1. Stop the application server.
    2. Install the sample application.
      1. Change to the samples_root/installableApps directory.
      2. Ensure profile_root/bin is in your path.
      3. Type the following command:
      4. On Windows operating systems:

        wsadmin -conntype none -lang jython -c "AdminApp.install('JTAExtensionsSample.ear')"

        On Linux and UNIX operating systems:
        wsadmin.sh -conntype none -lang jython -c "AdminApp.install('JTAExtensionsSample.ear')"

        On z/OS operating systems:
        wsadmin.sh -conntype none -lang jython -c "AdminApp.install('JTAExtensionsSample.ear)"

        On iSeries operating systems:
        wsadmin -conntype none -lang jython -c "AdminApp.install('JTAExtensionsSample.ear')"

    3. Start the application server.
    4. To run the sample application, open your web browser and enter the following web address:

      http://<hostname>:<port>/JTAExtensionsSample/TransactionsTracker/TransactionsTracker

      Where <hostname> and <port> are the hostname and port number of your application server.

  3. Uninstall the sample
    1. Stop the application server.
    2. Type the following command:

      On Windows operating systems:

      wsadmin -conntype none -lang jython -c "AdminApp.uninstall('JTA Extensions Sample')"

      On Linux and UNIX operating systems:
      wsadmin.sh -conntype none -lang jython -c "AdminApp.uninstall('JTA Extensions Sample')"

      On z/OS operating systems:
      wsadmin.sh -conntype none -lang jython -c "AdminApp.uninstall('JTA Extensions Sample')"

      On iSeries operating systems:
      wsadmin -conntype none -lang jython -c "AdminApp.uninstall('JTA Extensions Sample')"

    3. Start the application server.

Results

The following illustration shows the correctly running sample:

This is what the sample application page looks like.

Related information