You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Fabrizio Giudici <Fa...@tidalwave.it> on 2002/02/02 22:34:14 UTC

Tyrex transactions: a workaround

Hi.

After some investigations about tyrex problems with
transactions and messing up with tyrex and catalina
sources I was able to analyze the problem (actually
two different bugs) and to find a quick and dirty workaround.


THE PROBLEM 1
=============

Tyrex defines, among others, two kinds of DataSources:

- tyrex.jdbc.xa.EnabledDataSource
  is not aware of pooling and it does not register
  its connections with the transaction manager
- tyrex.jdbc.ServerDataSource
  is aware of pooling and registers its connections
  with the transaction manager

Guess what, it happens that tomcat 4 is giving us
the FORMER DataSource, so transactions are not working
(and pooling neither).

The factory for Tyrex datasources is
org.apache.naming.factory.TyrexDataSourceFactory
which lives in %CATALINA_HOME%/lib/naming-factory.jar.

The logics inside the factory create a
tyrex.jdbc.ServerDataSource only if the resource class
type is explicitly set to tyrex.jdbc.ServerDataSource.

It appears that the problem should be solved by properly
setting the 'type' attribute of Resource in server.xml:

<Resource name="jdbc/adi" auth="Container"
type="tyrex.jdbc.ServerDataSource"/>

Unfortunately this does not work, and I believe this is a
tomcat bug (in facts, try to set 'type' to "I.DO.NOT.EXIST"
and you'll discover that catalina doesn't notice it).
The Resource gets always bound in JNDI with type
javax.sql.DataSource.

I haven't checked the bug archive yet to find if this is
a known bug; in the meantime I found a workaround that
works. I consider it a quick-and-dirty fix to help us
working with our applications until apache staff fixes the
problem.


THE WORKAROUND
==============

Unfortunately we have to patch catalina :-(
Download catalina sources (I worked with 4.0.2-b2 but it
works well also with 4.0.1) and edit
\src\share\org\apache\naming\factory\TyrexDataSourceFactory:


 214                     if (ref.getClassName().equals
 215                         ("tyrex.jdbc.ServerDataSource")) {
 216
 217                         ServerDataSource sds =
 218                             new
ServerDataSource((javax.sql.XADataSource) ds);
 219
 220                         currentRefAddr = ref.get(DESCRIPTION);
 221                         if (currentRefAddr != null)
 222                             sds.setDescription
 223
(currentRefAddr.getContent().toString());
 224
 225                         return sds;
 226
 227                     }
 228
 229                     return ds;

REMOVE LINES 214,215 and 227, 228, 229 so that the ServerDataSource is
always created.

To compile the code, if you don't want to do a complete build of
catalina, do the following:


1. get the %CATALINA_HOME%\server\lib\catalina.jar
2. compile TyrexDataSourceFactory.java including catalina.jar, servlet.jar
   and jdbc2_0-stdext.jar in the classpath
3. replace the TyrexDataSourceFactory.class in catalina.jar with the
   compiled one.


THE PROBLEM 2
=============

A this point, you will find that every transaction operation
fails with catalina complaining about a org.omb.corba.XXX
missing class. The problem is that tyrex depends on a couple
of corba classes (even if you don't use them working locally).
To solve this, you must download tyrex distribution from
tyrex.exolab.org, find ots.jar and add it into
%CATALINA_HOME%\common\lib. At this point I was succesful in
having my transaction works!!!

Summing up, the bugs are:

  1. the type attribute for Resource does not work
  2. apache should include ots.jar with its distribution

Neither is a tyrex bug.

PS. There is a third, small problem that you can live with.
tyrex-0.9.7.0 misses a message resource file, so you will find
a complaining warning (and in case of problems you won't get
the correct diagnostic). If you want to fix it, download tyrex
sources from exolab, and add to the .jar the file
tyrex\utils\resources\message.properties. I sent an email to
the tyrex mailing list a couple of weeks ago, asking them if
it possible to quickly release a 0.9.7.1 with the missing file
added... but I got no reply.


If you manage in following my instructions and the thing
works for you, please let me know (to confirm my analisys).
If my analisys gets confirmed, I will post a message to the
tomcat-dev m.l. (and/or register a bug with the damn bug tracking
thing if I understand how to use it :-)


--
Fabrizio Giudici, Ph.D. - Senior Consultant
Java(TM) Architect, Mentor, Senior Writer
email  Fabrizio.Giudici@tidalwave.it
mobile +39 348 1506941 - fax +39 02 700510536
Member of ADI (Italian Ph.D. Association)


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Tyrex transactions: a workaround

Posted by Remy Maucherat <re...@apache.org>.
> Hi.
> 
> After some investigations about tyrex problems with
> transactions and messing up with tyrex and catalina
> sources I was able to analyze the problem (actually
> two different bugs) and to find a quick and dirty workaround.

Ok, I'll fix both.

Thanks,
Remy


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: Tyrex transactions: a workaround

Posted by Remy Maucherat <re...@apache.org>.
> > Unfortunately this does not work, and I believe this is a
> > tomcat bug (in facts, try to set 'type' to "I.DO.NOT.EXIST"
> > and you'll discover that catalina doesn't notice it).
> > The Resource gets always bound in JNDI with type
> > javax.sql.DataSource.
>
> Remy make me understand that this is not a bug in the way
> I described it. My problem was that I had declared the resource
> twice, both in server.xml and web.xml; in the latter I used
> javax.sql.DataSource and it overrode the former.

Well, that's a (small, but quite annoying to fix, so it probably won't be in
4.0.2) bug, because the one in server.xml is the one set by the admin. So it
is the Law ;-)

> Nevertheless, removing the entry from web.xml and using
> tyrex.jdbc.ServerDataSource doesn't work, so it seems that
> the workaround is still needed. I will try again tomorrow.

You may need to use a ResourceParams element to specify the factory.

Remy


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Tyrex transactions: a workaround

Posted by Fabrizio Giudici <Fa...@tidalwave.it>.
> Nevertheless, removing the entry from web.xml and using
> tyrex.jdbc.ServerDataSource doesn't work, so it seems that
> the workaround is still needed. I will try again tomorrow.

Thanks to Remy, I've finally discovered that we don't need to
patch catalina for tyrex transaction to work. Finally, both
with 4.0.1 and 4.0.2-b2, you just need to configure your JDBC
resources as follows (excerpt from server.xml):

 <Context path="/newadi" docBase="webapps" debug="0" privileged="false">
   <Resource name="jdbc/adi" auth="Container"
type="tyrex.jdbc.ServerDataSource"/>
   <ResourceParams name="jdbc/adi">
     <parameter>
       <name>factory</name>
       <value>org.apache.naming.factory.TyrexDataSourceFactory</value>
     </parameter>
     <parameter>
       <name>user</name>
       <value>system</value>
     </parameter>
     <parameter>
       <name>password</name>
       <value>manager</value>
     </parameter>
     <parameter>
       <name>driverClassName</name>
       <value>oracle.lite.poljdbc.POLJDBCDriver</value>
     </parameter>
     <parameter>
       <name>driverName</name>
       <value>jdbc:polite:adi</value>
     </parameter>
   </ResourceParams>
</Context>

The important things are:

  1. the attribute type="tyrex.jdbc.ServerDataSource" for the Resource
  2. the 'factory' parameter set for ResourceParams to
     org.apache.naming.factory.TyrexDataSourceFactory

I remind you that you will still need to put ots.jar from
tyrex sources into %CATALINA_HOME%/common/lib, and that
tyrex-0.9.7.0 will complain about a missing message.properties
file (but it will work).

That's all.

--
Fabrizio Giudici, Ph.D. - Senior Consultant
Java(TM) Architect, Mentor, Senior Writer
email  Fabrizio.Giudici@tidalwave.it
mobile +39 348 1506941 - fax +39 02 700510536
Member of ADI (Italian Ph.D. Association)



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: Tyrex transactions: a workaround

Posted by Fabrizio Giudici <Fa...@tidalwave.it>.
> Unfortunately this does not work, and I believe this is a
> tomcat bug (in facts, try to set 'type' to "I.DO.NOT.EXIST"
> and you'll discover that catalina doesn't notice it).
> The Resource gets always bound in JNDI with type
> javax.sql.DataSource.

Remy make me understand that this is not a bug in the way
I described it. My problem was that I had declared the resource
twice, both in server.xml and web.xml; in the latter I used
javax.sql.DataSource and it overrode the former.

Nevertheless, removing the entry from web.xml and using
tyrex.jdbc.ServerDataSource doesn't work, so it seems that 
the workaround is still needed. I will try again tomorrow.

--
Fabrizio Giudici, Ph.D. - Senior Consultant
Java(TM) Architect, Mentor, Senior Writer
email  Fabrizio.Giudici@tidalwave.it
mobile +39 348 1506941 - fax +39 02 700510536 
Member of ADI (Italian Ph.D. Association)


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>