JOTM can be integrated with Tomcat 4.1.x to provide distributed transactional acces to resources from Servlets or JSP.// As for the jdbc example, the Tomcat one can work with any database providing a JDBC driver. It uses XAPool to take care of the transactional behaviors and the pooling of JDBC objects.
The scenario of the Tomcat is very simple. It is based on the example
provided by Tomcat in their JNDI Datasource
HOW-TO
with the addition of some transaction code.
The user send a request to a JSP file (test.jsp) which asks
to commit or rollback the incrementation of an integer stored in a database.
The JSP delegates the JDBC and transaction code to a JavaBean
(foo.DBTest class).
The code of foo.DBTest is simple:
The tomcat example uses Tomcat 4.1.18. It can be downloaded from http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/bin/.
There's no setup needed for Tomcat. You just have to unzip it to use it.
The database setup for the Tomcat example is exactly the same than for the JDBC example. Please refer to the Database setup of the JDBC example.
You also need to copy the JDBC driver jar file of your database in the common/lib/ directory of Tomcat.
In example/tomcat/ directory, type
$ ant warto compile Java files and creates a WAR file (examples/tomcat/output/dbtest.war) containing your web application and all that is needed to use JOTM.
Also copy example/tomcat/dbtest.xml XML file to the
webapps/ directory of Tomcat.
This files describes the context associated with your web
application. In this file, you set the properties to access your
database:
This file also described the resource factories (JDBC and Transaction) used by your web application.
You've also to copy the file in config/
# lmi stands for Local Method Invocation carol.protocols=lmi # do not use CAROL JNDI wrapper carol.start.jndi=false # do not start a name server carol.start.ns=falseThese files have to be placed in common/classes/ directory of Tomcat.
Go to the bin/ directory of Tomcat and type
$ ./catalina.sh runUse your favorite browser to go to the URL
http://localhost:8080/dbtest/test.jsp
Choose if you want to commit or rollback the
incrementation of the value of the integer and click on the
completion button.
If you've chosen commit, the integer value displayed on the
page should have been incremented by one.
If you've chosen rollback, the integer value displayed on the
page should be the same as before.
For a more technical explanation on the integration of JOTM in Tomcat, please refer to the Tomcat/JOTM HOW-TO.