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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s