6 Replies Latest reply on Apr 22, 2013 5:41 AM by tomjenkinson

    JTA support for Servlet container ?

    dlmiles

      Hello this question must have been asked by many people before, but there does not seem to be a useful reply I can find.

       

      I am looking to add JTA support to Tomcat7 ideally using JBoss TS (since my intended upgrade path is to move towards JBoss AS).

       

       

      * Webapp uses Spring Framework 3.2.x with Hibernate 4

      * Webapp currently uses Tomcat7 built in JDBC connection pooling (I think maybe I can continue to use this as-is?)

      * Webapp works great with a single JDBC connection in use at a time.

       

      * Need to add support for multiple JDBC connections to be in use at the same time by the same thread in a single transaction.

      * No advanced JBossTS features are needed (at least I don't think I need them), no recovery, no CORBA/ORB/WS support, no multi/cross JVM transaction support.  No nothing that is outside of the scope set here..  All this stuff can be shutdown/disabled.

      * No need to support extended transactions, all transactions occur synchronously within the thread that started and owns them to completion.

       

      * Must support multiple JDBC transactions (for drivers MSSQL/MySQL/PostgreSQL)

      * Would like to support remote EJB, remote JMS transactions

      * Would like to support XA (if that is an optional aspect, otherwise this is a 'Must' support XA)

       

      * Would like to have a unit test suite to verify XA ACID claims of the setup and final configuration and/or highlight potential areas of concern.

       

      * As it is running on Tomcat7 the JNDI support is limited, some limitations on JNDI use may exist, such as only being able to write to JNDI object during container startup from server.xml config (not from inside a WAR deployment)

       

      * Need to be debuggable, I turned logging upto TRACE level in my attempt so far and got no useful information out of JBoss TS to resolve not being able to establish a Transaction object.

       

      To me the various specifications are very mature, so this should be straightforward right, there is enough open-source around reuse by now right ?

       

       

      I am trying to understand the details, such as where XA JDBC sources fit in and the problems in solving that issue within Tomcat.

      From my point of view it looks like I can continue to use the Tomcat built in JDBC connection pooler but I simply change the Driver/DataSource class implementation to the vender provided XA version ?  I presume that interface.

      I am expecting some wrapper between JTA implementation and the connection pooler that irons out all the quirks that may exist to provide XA support.

       

      It maybe necessary for this connection wrapper to support faking 2-phase commit when the underlying Connection/SQL database does not support it (turned off, or feature not available), this should be something I authorize and set via configuration, it should not do this by default.

       

      Some part of the system might needs to be in the Tomcat container's server classpath (not inside the WAR) that would be ok too.  Maybe by doing this it would be possible get standard JNDI lookups for JTA to exist.

       

       

      At this time I can not use JBossAS 7 or EAP 6 due to issues I need to work through (AS bugs not my app bugs) and the fact I am already using Tomcat 7.0.3x WebSockets that no JBoss AS supports yet.  I can restructure my application to put the web-app part on Tomcat and use remote EJB to a JBoss AS instance and this is probably what I shall do in the future until JBoss AS support WebSockets.

        • 1. Re: JTA support for Servlet container ?
          jhalliday

          The key is ensuring that getConnection() has the side effect of enlisting the corresponding XAResource with the transaction manager. That's a JCA problem (see rant at http://jbossts.blogspot.co.uk/2012/01/connecting-dots.html ) and tomcat doesn't have one of those. Specifically, its built-in conn pool won't handle it - it's not XA aware.  The transactional driver bundled with JBossTS does the right thing, but it's conn pooling frankly aint up to handling a high volume web app. You really, seriously need to consider JBossAS, but if you're set on reinventing the wheel then embed IronJacamar or take a look at http://anonsvn.jboss.org/repos/labs/labs/jbosstm/workspace/jhalliday/tomcat-integration/ - the integration work is not hard, we just don't put much effort in to it because, well, we already have a perfectly good app server :-)

          • 2. Re: JTA support for Servlet container ?
            dlmiles

            Thanks for your reply, I have read the blog reference your cite.  Spring is great what they release is quaulity and well documented and works in a consistent way.  But sure it is not an EE spec replacement, but then sometimes you don't actually needs EE spec as written, but if it happens to also solve a similar problem then thats ok.

             

            Re the XAResource matter, but you don't have your webapp talking directly to the Tomcat pool do you, you have your JCA layer.  You have your webapp talking to the other side of the JCA layer.  This is what I mean when I refer to "I am expecting some wrapper between..." this I guess is a fake JCA that supports just what is needed in the above requirements.  It takes care of abuse from the webapp and also quirks in XA support of JDBC drivers.  I don't get why the Tomcat connection pool needs to support XA itself, it just needs to support pooling of objects that happen to be JDBC connections, the JCA layer will proxy/wrapper the pool and deal with the impedence mismatch.

             

            I don't think I am reinventing the wheel just looking to stitch together existing open-source aspects (ideally to then be able to reduce the JAR size down).

             

            The problem in this area I guess is that it is boring and not interesting work so no one really solved it in a tidy way.

             

             

            Re JBoss AS is too buggy right now to use as-is (tooling has issues, OSGi support sucks).  In fact every community edition has suffered the same problem since JBoss 4, I hope the new EAP schedule will see bug fixes and maintainence work end up in the community edition, but I fear AS8 work as already begun and somehow I am expected to work with that.  There is TomEE and it appears to use geronimo-transaction-3.1.1 a 72k JAR (and is based on tomcat 7.0.39 so has websocket support) so maybe they already solved this problem for tomcat in a nicely packaged solution (where I can strip out other unecessary EE features).  I really do want to use JBoss AS as the sub-module parts taken on their own are great just the AS community release has always had known issues that never get fixed in the 7 years I've been trying, reporting, waiting.

            • 3. Re: JTA support for Servlet container ?
              jhalliday

              umm, you're trying to reinvent JBossAS, since it basically joins together existing open source projects: tomcat (jboss web), the JCA (ironjacamar) and the TS (jbossts/narayana). How is that not reinventing the wheel? You'll be able to cobble together something that kinda almost works most of the time for most of your use cases. It will take longer than you think, will be amazingly tricky to test (especially crash recovery) and will be more buggy than JBossAS. On the other hand by then you'll know enough about how it works to be able to fix it yourself, rather than buying an EAP support contract from Red Hat. Good luck.

              • 4. Re: JTA support for Servlet container ?
                gytis

                You could take a look at the quickstart I am currently working on. It shows how to integrate Tomcat, IronJacamar, and JBossTS. It is not completelly finished yet and therefore not in Narayana quickstarts repository.

                However, all its funtionality works. It uses one Postgres XA datasource and one dummy XAResource. It also has crash recovery. Currently it is in my github repository: https://github.com/Gytis/quickstart/tree/master-JBTM-1479/jca-and-tomcat.

                Hope it will be helpful.

                1 of 1 people found this helpful
                • 5. Re: JTA support for Servlet container ?
                  dlmiles

                  Thanks for the link to the github project.

                   

                  Yes this is just the kind of thing I am looking for, how to take existing open-source technolgies and piece them together to provide JTA support to tomcat (given a set of contraints I can live with, but maybe strict specification conformance couldn't).

                  • 6. Re: JTA support for Servlet container ?
                    tomjenkinson

                    Hi Darryl,

                     

                    You can track Gytis' work here too: https://issues.jboss.org/browse/JBTM-1479

                     

                    I do have one question, when you say this in your initial query:

                     


                    Darryl Miles wrote:

                     

                    no recovery

                     

                    Can you elaborate on that? Recovery is a key aspect to the transaction manager as it is responsible for resolving state in the presence of component failures.

                     

                    Tom