Thursday, September 12, 2013

Apache ODE on Tomcat 7 with Bitronix Transaction Manager



With the coming release of Apache ODE 1.3.6 and there on, one would need to integrate a transaction manager in Tomcat in order to use  an external database configuration for ODE.

Here I will list down the steps to integrate one of the open source transaction managers called Bitronix in tomcat and the associated changes in ODE web application.

Step 1: Download latest bitronix archive from here.

Step 2: Copy these jars available in the bitronix archive to Tomcat\lib 
  • btm-2.1.4.jar
  • btm-tomcat55-lifecycle-2.1.4.jar
  • geronimo-jta_1.1_spec-1.1.1.jar
  • slf4j-api-1.6.4.jar
  • slf4j-jdk14-1.6.4.jar 

Step 3: Follow Step 2 as instructed in the original guide of bitronix.

Step 4: Configure data sources
Create a file name named resources.properties under <tomcat>/conf/ directory with the below contents:
This config is for MYSQL database
 resource.ds2.className=bitronix.tm.resource.jdbc.lrc.LrcXADataSource  
 resource.ds2.uniqueName=jdbc/ode  
 resource.ds2.minPoolSize=10  
 resource.ds2.maxPoolSize=50  
 resource.ds2.driverProperties.driverClassName=com.mysql.jdbc.Driver  
 resource.ds2.driverProperties.url=jdbc:mysql://localhost:3306/ode  
 resource.ds2.driverProperties.user=root  
 resource.ds2.driverProperties.password=mysql  
 resource.ds2.allowLocalTransactions=true  
 resource.ds2.shareTransactionConnections=true  

Step 5: Associate the datasource created in the previous step for ODE
Create a file named ode.xml under <tomcat>/conf/Catalina/localhost/ directory with the below given contents:
 <Context reloadable="true" crossContext="true">    
      <Resource   
           name="jdbc/ode"   
           auth="Container" type="javax.sql.DataSource"   
           factory="bitronix.tm.resource.ResourceObjectFactory"   
           uniqueName="jdbc/ode" />  
 </Context>  

Step 6: Change the web.xml of ODE
Add these lines in the web.xml,
 <resource-ref>  
     <res-ref-name>jdbc/ode</res-ref-name>  
     <res-type>javax.sql.DataSource</res-type>  
     <res-auth>Container</res-auth>  
     <res-sharing-scope>Shareable</res-sharing-scope>  
 </resource-ref>  

Step 7: Remove duplicate jars
Remove geronimo-jta_1.1_spec-1.1.jar files from ode web application lib directory

Step 8: Edit ode-axis2.properties
 ode-axis2.tx.factory.class=org.apache.ode.axis2.util.TomcatFactory  
 ode-axis2.db.mode=EXTERNAL  
 ode-axis2.db.ext.dataSource=java:comp/env/jdbc/ode