Glassfish Clustering – NullPointerException while creating JMS RA

Didn’t I tell you that we had an exciting experience enabling cluster support for our applications using Glassfish.

Even though the entire setup worked fine in our local environment, life was not the same when trying to deploy our application on Amazon EC2 Cloud. We were greedy enough to pick a large machine with 8GB RAM and quad-core processors…and attempted to deploy our applications on the Glassfish Cluster there…
Our Server Instances would never start, failing with a whole bunch of NullPointerExceptions while creating JMS RA. I gave up after googling for couple of hours. And as usual, Venkat came to my rescue. He took over from me and spent some midnight oil and figured out the trick…
We had to add an unsupported property to the JVM…


Check out this link from Ramesh Parthasarathy for more useful information related to this issue

Glassfish v2.1.1 Cluster Session Replication inconsistent behavior

Everytime I take up a task on adding Cluster Support to my j2ee application, the whole experience gets quite exciting with new kinds of challenges 🙂

In the past, it was with Weblogic, Websphere etc…and this time it was Glassfish 🙂
Ok, like many of you, I managed to setup the cluster environment in glassfish and deployed “ClusterJsp” application to check out Session Failover, Load balancing etc…
What I found was that, if I keep refreshing the ClusterJsp page 5 to 10 times, my Session Id keeps changing…going to say that Glassfish lost my session somewhere in between these requests.
After googling and bing’ing a lots, I managed to find this link, which explained the issue in detail.
Basically, we should add the following snippet in sun-web.xml
After adding the above entry, Glassfish started behaving as expected.
Now what I donot quite understand is, why was this behavior not made a default behavior !!!
I am sure there is a good reason for it, will update If I get to know.

Our First iPhone App

After being an user of iPhone for past one year, we got inspired to write an app for iPhone 🙂

We were thinking if we should write a simple Game or Puzzle Application, and then came this idea of publishing a Panchangam data for 2010. Venkat came up with the data for all the days for year 2010 and we put together an application called “Panchangam Lite 2010”. The reason for this “Lite” is the fact that this Panchangam provides data (timings) specific to Bangalore. We have plans to make a Panchangam Pro (?!) which allows you to choose the city and lookup the panchangam data…and even further, automatically figure out the location of the iPhone using the “Location service” of iPhone.

And guess what, within 5 days of our launch of this app, we have found more than 300 downloads of this application. We are all the more motivated to come out with more such useful apps in the near future 🙂

Want to check out countries from where our app was downloaded till date…go to Venkat’s blog post here

Glassfish v2 Create Domain – Keytool

Yesterday night, I had to work on some interesting stuff with my application’s deployment tool. We have a Ruby RakeFile to automatically create glassfish domain and deploy apps. As I was running the tool creating domains atleast 10 times or so, suddenly at one stage I got an error while creating glassfish domain…the error was “keytool error:”. I thought some evil spirits has got into my laptop at the wee hours…hence gave up and went off to sleep.

Today morning, I thought let me give this a fresh look…
And I learnt that you can turn on debug logging by adding -DDebug in the asadmin script. This helped me to say that there is something wrong with a keystore that Glassfish was looking for while creating the domain.

After couple of rounds of googling, I realized that the keystore is stored in my home folder with the name .asadmintruststore. Apparently the file size was just 1 byte. I just deleted the file and now the creation of domain went thru fine 🙂

On thinking what could have corrupted the keystore, I realized once when the creation of domain was going thru, I had abruptly killed the operation by Ctrl+C, which could possibly have corrupted the keystore!

Hope this helps someone who bumps on this issue 🙂

Moral of the story : Dont try to stay late and work…sleep early 🙂

Ubuntu : On Hibernate , machine restarts

Uff! I have been trying to get Hibernate (Suspend-to-disk) option work properly with Ubuntu in my home PC, versions after versions, starting from Dapper Drake (v6.04) to the recent Karmic Koala(v9.10).

Even though the actual hibernation(meaning, dumping the memory content into the Swap partition of my disk) happens fine, my machine suddenly restarts within 3 seconds after a complete halt. I have been going crazy to even figure out the sentence to help google find what I am looking for from the net.

Finally, at 9:45pm with half sleepy eyes, I managed to find some help after going thru lines and lines of posts from various forums…that I had to add a file to my /etc/pm/conf.d and add the following line to the file


the hibernation happens properly and my machine goes to sleep happily thereafter 🙂
Thanks to this post
PS: Folks, also please ensure that you specify where your hibernate file is present to Grub to ensure it wakes up instead of booting afresh. You have to add resume=/dev/sda5(swap partition). But I also noticed recently in my dad’s netbook, without this resume option, GRUB properly wakes up from Hibernation. God knows how!…Something to research on sometime later….Will post my findings if any 🙂

Unexpected behavior in Mysql JDBC Driver 3.x

Till very recently, we have been using v3.x of Mysql JDBC Driver in our application. Our application stores serialized objects as bytes in a blob field in Mysql. When we tried to read the data from the field using resultset.getObject(), Mysql Driver threw a ClassNotFoundException as at that particular instance, the class of the serialized object was not present in the classpath.

On investigating further, we learnt that Mysql reads the first 2 bytes of the data in the field and if it finds that it is a byte array representation of a serialized object, it AUTOMATICALLY attempts to deserialize the object, which is quite unexpected of Mysql to do because there is no guarantee that the serialized object’s class would be present in the classpath.

Thankfully, what we found is that the latest version of Mysql JDBC Driver v5.1.6 does not have this problem. And the behaviour is controlled by a property that is available in the mysql connection object called “autoDeserialize”. Thankfully, the default value of the property is “false”.

A sample Presenter Implementation for Rails

Recently, my friend Venkat introduced me to the Presenter Pattern and we were discussing on its advantages and the situations where using a Presenter would be useful.

Thanks to Jay Fields for elaborating on the Presenter and also providing a sample Presenter implementation in one of his blogs.

I have modified the sample Presenter class provided by Jay, fixed a few minor issues and have made it available here.

Adding JNDI DataSource support for Rails-Integration

In the past few weeks, we have been working on getting our rails application to run on JRuby. Ofcourse, we were successful in packaging our application as a J2EE .WAR archive, thanks to Rails-Integration and ARJDBC, without which this would not have been possible.

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,




For the full list of configuration details for various databases, please go here.

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

in your jetty.xml(or the run.rb file) and add the following entries after the two entries…


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.

My DataSource Reference

4. Lastly, to add JNDI support, jetty requires two more libraries Jetty-Naming and Jetty-Plus.
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’))
add_jetty_library(maven_library(‘org.mortbay.jetty’, ‘jetty-naming’, ‘6.1.1’))

5. Now for the final step, modify your database.yml to use jndi…

adapter: jndi
jndi: java:comp/env/jdbc/MyApp
driver: oracle

Thats it! Your rails web application is ready to run with JNDI Data source.

Rails Integration – Session Restore restores symbols as Strings

In the last one week, our focus was to deploy our rails app as a war file and run on jetty, with the help of Rails Integration plugin.

We noticed that we had problems with respect to accessing our session variables across pages. We narrowed down the problem to “JavaServletStore” class bundled as part of the Rails Integration plugin.

Since Java is not aware of Ruby Symbol objects, these symbols are converted to string and updated into the Session Object. And now, when the session is restored, the data stored as symbols originally in rails would be available as Strings. Hence if we look for the symbols we would not find them in the session.

As a temporary work around, we modified the restore method to convert the keys as symbols. This would just work for us as we use symbols all thru when writing and reading from Session.

Our temporary fix is given below :

# Restore session state from the Java session
def restore
@session_data = {}
java_session = @java_request.getSession(false)
if java_session
names = java_session.getAttributeNames
while names.hasMoreElements
name = names.nextElement
@session_data[name.to_sym] = java_session.getAttribute(name)

The proper fix should ensure that “update-session” method stores some info about the type of the object and appropriately convert them during the “restore-session”. May be there is a better solution.

JRuby and Rails-Integration

I must acknowledge that am one of the fortunate folks to have got bitten by the Ruby bug lately…and we have been developing applications with Ruby on Rails in our organization. Though we are excited about Ruby and Ruby On Rails, we always had that concern as to how do we convince the IT Team in the Banks(this is where our applications are deployed) to deploy Ruby application in Production.

We were quite excited about the JRuby momentum and were following the progress in the Rails-Integration Project recently. Now, we certainly have an opportunity to develop in Rails and deploy in the well established J2EE platform. Kudos to JRuby team and the Rails-Integration team to make this a reality 🙂

Last week, we took our Rails application and played around with Rails-Integration to create a .war archive of our app and deployed successfully in Jetty with some minor hiccups, which I would further describe in my future posts.