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.