<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Noa&#039;s blog &#187; Ruby on Rails</title>
	<atom:link href="http://noa.resare.com/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://noa.resare.com</link>
	<description>moderately interesting words about things going through my mind</description>
	<lastBuildDate>Fri, 29 Jan 2010 23:56:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>From Ruby on Rails to Java</title>
		<link>http://noa.resare.com/2008/12/ror-to-java/</link>
		<comments>http://noa.resare.com/2008/12/ror-to-java/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 21:25:59 +0000</pubDate>
		<dc:creator>noa</dc:creator>
				<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Spring Framework]]></category>

		<guid isPermaLink="false">http://noa.resare.com/?p=137</guid>
		<description><![CDATA[I have been tasked with making some extensions and changes to a system written i Ruby on Rails with some parts written in Java. For reasons I will not write about at this time we have decided that we want to move away from Ruby on Rails and instead develop using java and the excellent [...]]]></description>
			<content:encoded><![CDATA[<p>I have been tasked with making some extensions and changes to a system written i <a href="http://www.rubyonrails.org/">Ruby on Rails</a> with some parts written in Java. For reasons I will not write about at this time we have decided that we want to move away from Ruby on Rails and instead develop using java and the excellent Spring framework.</p>
<p>Leaving one development framework for another is often a painful experience, where lots of code needs to be thrown away and rewritten in one step. For this particular situation doing that massive rewrite, technology change has been something we wish to avoid and here are some info on how we plan to do that.</p>
<p>The first step was to move both the java and the ruby environment into the same namespace from the point of view of the web browser. Since we already use the <a href="http://httpd.apache.org/">Apache httpd</a> as a front end for the Ruby environment—executing it via mod_fcgid—this was a simple matter of configuring the same apache httpd instance to proxy all requests to the java environment. That way we can make relative links from pages created in he ruby environment to pages in the java environment.</p>
<p>The next problem to tackle was session management. More specifically, when a user logged in using Ruby on Rails we and then navigated to a page served by the java environment we needed to propagate the information about the logged in user to the java code, hopefully without doing any drastic changes to the ruby code.</p>
<p>It turns out that doing that was not that difficult. The way our Ruby on Rails environment is configured it uses Active Record to store session information associated with a specific cookie in the web brower in the database. Since both ruby and java lives on the same webserver from the point of view of the brower, any cookies set by rails is also sent by the browser as a part of the reqests that ends up in the java environment.</p>
<p>I have then written code that uses the cookie to look up the session data in the database from java. That data consists of a Base64-encoded binary data using the <tt>Marshal.dump()</tt> facility of Ruby. It turns out that data is not particularly difficult to parse relevant bits from. Looking for the ASCII string of the key of our user id value in the session object in Ruby, then look for the next double qoute char and parse all ASCII digits before the next double qoute occurs seems to be a fully workable solution.</p>
<p>The code to do this can be looked at in <a href="http://resare.com/noa/ref/RailsSessionIntegrationHelper.java">RailsSessionIntegrationHelper.java</a>. If you want to get rid of the Spring Framework dependency, just replace the method getSessionData() with one that does raw JDBC instead, and remember to close your connection when you're done.</p>
]]></content:encoded>
			<wfw:commentRss>http://noa.resare.com/2008/12/ror-to-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
