While we were at it, we also wanted to check out the jndi data source support of ARJDBC as well as Rails-Integration projects.
After spending some time, we discovered that the ARJDBC v0.2.3 had a bug in jndi_adapter.rb. The method "Jndi_Connection" was not present and instead there was a method called "Jdbc_Connection". I had to correct the same before getting the ARJDBC to support JNDI Data source. Apparently, I also found that this issue does not exist in the trunk version of ARJDBC.
Rails-Integration comes with rake tasks to create a war file for the rails app and configure jetty
web server. To configure JNDI support, the following changes are required to be done...
1. Add the data source configuration to the jetty.xml file. However, Please note that everytime you run the rake task - war:standalone:run, the jetty.xml is recreated. Therefore, I suggest that you modify the rails-integration war plugin library, called run.rb and add the below entries in the appropriate place.
For instance, for oracle data source,
<new id="MyApp1" class="org.mortbay.jetty.plus.naming.Resource">
<arg>jdbc/MyApp</arg>
<arg>
<new class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
<set name="URL">jdbc:oracle:thin:@192.168.2.23:1521:swami</set>
<set name="User">myapp</set>
<set name="Password">myapp</set>
</new>
</arg>
</new>
Please note that, as per jetty documentation, the above entries can be updated in jetty-env.xml or jetty-web.xml as well. The scope of this configuration depends on where you put this configuration information.
2. Now, search for the section
<New class="org.mortbay.jetty.webapp.WebAppContext">
in your jetty.xml(or the run.rb file) and add the following entries after the two <Arg> entries...
<Set name="ConfigurationClasses">
<Array id="plusConfig" type="java.lang.String">
<Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
<Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
<Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>
</Set>
3. Now, we need to specify the JNDI Logical Name for our web application, add the following entries in your web.xml under WEB-INF folder of your war file. However, Please note that every time you run the rake task - war:standalone:run, web.xml is recreated. Therefore, I suggest that you modify the rails-integration war plugin library, called create_war.rb and add the below entries in the appropriate place.
<resource-ref>
<description>My DataSource Reference</description>
<res-ref-name>jdbc/MyApp</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
The best way to do this is to modify the rails-integration war plugin library, called war_config.rb. Search for the word add_jetty_library and append the following lines telling the war_config to download the two libraries as well.
add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-plus', '6.1.1'))5. Now for the final step, modify your database.yml to use jndi...
add_jetty_library(maven_library('org.mortbay.jetty', 'jetty-naming', '6.1.1'))
production:Thats it! Your rails web application is ready to run with JNDI Data source.
adapter: jndi
jndi: java:comp/env/jdbc/MyApp
driver: oracle
0 comments:
Post a Comment