Stephen Connolly / OpenEjb, Jetty and Maven - Transaction Management

Created Mon, 01 Mar 2010 00:00:00 +0000 Modified Mon, 01 Mar 2010 00:00:00 +0000

I’ve been meaning to blog about getting transaction management working with OpenEjb and Jetty using jetty:run… it’s still an on-going story… but the following might get you going…First off, in your pom.xml you need to add the configuration for maven-jetty-plugin… we need to dance around the various activemq/activeio versions and ensure that we get the correct version of ant… <project xmlns=“http://maven.apache.org/POM/4.0.0" xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">     4.0.0    org.apache.openejb.examples    jetty-openejb    war     1.0-SNAPSHOT    jetty-openejb Maven Webapp    http://maven.apache.org                        junit            junit            3.8.1            test                         ${project.artifactId}                                    org.mortbay.jetty                 maven-jetty-plugin                6.1.22                                                            org.apache.activemq                         activemq-core                        4.1.1                                                                                    commons-logging                                commons-logging                                                                                        commons-logging                                commons-logging-api                                                                                        org.apache.activemq                                activeio-core                                                                                                                     org.apache.activemq                         activemq-ra                        4.1.1                                                                                    commons-logging                                commons-logging                                                                                        commons-logging                                commons-logging-api                                                                                        org.apache.activemq                                activeio-core                                                                                                                     org.apache.activemq                         activeio-core                        3.1.2                                                                                    commons-logging                                commons-logging                                                                                        commons-logging                                commons-logging-api                                                                                                                    org.apache.openejb                        openejb-core                         3.1.2                                                                                    org.apache.activemq                                 activemq-core                                                                                        org.apache.activemq                                 activemq-ra                                                                                        org.apache.activemq                                 activeio-core                                                                                        junit                                 junit                                                                                                                                        org.mortbay.jetty                        jsp-2.1-jetty                         6.1.22                                                                                    ant                                 ant                                                                                                                            ${basedir}/src/main/jetty/jetty.xml                                        Next we need to configure a src/main/jetty/jetty.xml to bind the UserTransaction instance into jetty…                                                             java.naming.factory.initial                    org.apache.openejb.client.LocalInitialContextFactory                                                         openejb:TransactionManager                                                                                                                And presto-chango, now jetty has a transaction manager provided by openejb.  (Note: if we don’t mind storing that in a jetty-env in /WEB-INF, you can put the same config in WEB-INF/jetty-env.xml) OK, so here are the issues:Reloading does not work (because org.apache.openejb.core.ivm.naming.IvmContext does not support the destroySubcontext(Context) methodWe are using jetty’s JNDI provider in the web-app and openejb’s JNDI provider for the EJBs… this is because When jetty binds names to JNDI (using org.mortbay.jetty.plus.naming.Resource or org.mortbay.jetty.plus.naming.Transaction) it binds the object to JNDIName and it also binds a NamingEnrtry for the object to __/JNDIName Unfortunately, openejb’s JNDI implementation seems to be somewhat strange in this regard… if we add the SystemProperties to jetty to have it use openejb’s JNDI implementation, e.g. add the following to /project/build/plugins/plugin[maven-jetty-plugin]/configuration/systemProperties                                                     java.naming.factory.initial                            org.apache.openejb.client.LocalInitialContextFactory                         Then when we bind /UserTransaction it gets bound to openejb:/UserTransaction but when we lookup /UserTransaction openejb looks up openejb:local//UserTransaction And that is just for starters… there seems to be a whole host of other JNDI strangeness between jetty’s side and openejb’s sideThe side effect of all this is that if you want resource refs to work correctly, you need to fish them out of openejb’s JNDI context and push them into jetty’s JNDI context In any case this is at least a start!