Hi I have a requirement for integrating one of our existing applications written in Ruby with another Java application. They need to appear seamless and thereby share the same information (e.g. session). At this stage, most of the information is available through a UI powered by Ruby. My migration idea is to migrate Ruby to JRuby and then integrate this with the Java app. Is migrating a Ruby application to JRuby a fairly trivial task? How easy is it for Java to be able to access the JRuby session information and vice-versa? I assume Ruby/JRuby doesn't encode the session information in a way that a Java app can't read it straightforwardly? (e.g. doesn't do what .NET does with the viewstate field) Are there any gotchas/pitfalls that you would look out for? Would it be possible to have an approach of dual running both in the same Java container, and then gradually rewriting one of the applications: e.g. eliminating the Java code or the Ruby code in favour of the other. Does one way cause more issues than the other? I'm more of a Java guy myself, so any information JRuby would be welcome. Chris
on 2012-05-18 00:10
on 2012-05-18 03:31
On Thu, May 17, 2012 at 5:08 PM, Chris Burrell <chris@burrell.me.uk> wrote: > Is migrating a Ruby application to JRuby a fairly trivial task? For the most part, yes, aside from a few gotchas (more below). You could look at this project as an example of blending Java and Rails. https://github.com/nicksieger/refactoring-to-rails, and the associated talk at http://www.confreaks.com/videos/572-scotlandruby20.... > How easy is it for Java to be able to access the JRuby session information > and vice-versa? I assume Ruby/JRuby doesn't encode the session information > in a way that a Java app can't read it straightforwardly? (e.g. doesn't do > what .NET does with the viewstate field) There's no viewstate in Rails, and (though I haven't tried it myself) I believe that jruby-rack (which you would be the glue between your servlet environment and the Rails environment) I believe it includes a backing store so that rails data is stored in the normal servlet session. Now, accessing that data from Java may be slightly cumbersome, since you'll have to cast them to the appropriate IRubyObject. But, accessing Java objects stored in the session from Ruby would be considerably more convenient. > Are there any gotchas/pitfalls that you would look out for? There are a few gotchas, but you could give jrlint (https://github.com/jruby/jruby-lint) a pass at your current application. It should warn you of some common cases. > Would it be possible to have an approach of dual running both in the same > Java container, and then gradually rewriting one of the applications: > e.g. eliminating the Java code or the Ruby code in favour of the other. Does > one way cause more issues than the other? The refactoring-to-rails app shows exactly this. Taking an existing Java app (the Pet Clinic sample spring app) and gradually migrating it to Ruby/Rails. Good luck!
on 2012-05-18 05:23
On May 17, 2012, at 5:08 PM, Chris Burrell wrote: > Is migrating a Ruby application to JRuby a fairly trivial task? I did a short screencast showing how to do this for an existing Rails app: http://youtu.be/C2gCi5DS_I8 I use Trinidad in that example, but you'll probably want to use Warbler+Tomcat/Jetty/etc if you're already running with an existing Java servlet container (although, you can deploy a WAR to Trinidad).
on 2012-05-18 07:35
On Fri, May 18, 2012 at 1:08 AM, Chris Burrell <chris@burrell.me.uk> wrote: > and vice-versa? I assume Ruby/JRuby doesn't encode the session information > in a way that a Java app can't read it straightforwardly? (e.g. doesn't do > what .NET does with the viewstate field) > > Are there any gotchas/pitfalls that you would look out for? > I've been experimenting with embedding JRuby in a Java application a bit lately and one gotcha I ran into is that in some cases you may need to implement your own data conversion code. First I tried passing data from Java code to Ruby code that's invoked using JavaEmbedUtils.invokeMethod. Initially I was using JavaEmbedUtils.javaToRuby for converting the arguments but as things didn't work properly this way, I had to implement a custom "deep convert" method. I'd guess the same could happen also in some cases when calling Java code from Ruby. marko
on 2012-05-21 23:33
I cannot speak to moving from Ruby to JRuby... I think the issue can be gem support, but it's getting better. I can talk about interop between Java/JRuby, however. I embedded JRuby in Apache PIg so that users could define UDF's (think of this like a user defined COUNT or SUM in the database world) using JRuby. I found the tools to be more than adequate, though the documentation is thin, and there are definitely some gotchas (and you will undoubtedly have to make your own conversion functions). Still, I think that the power of Ruby is worth it... a little pain on the internals is worth the expressivity of Ruby :) 2012/5/17 Marko Asplund <marko.asplund@ixonos.com>
on 2012-05-21 23:38
Thank you everyone for all your responses! And so complete. Much appreciated. It gives me a very good starting point :) Cheers Chris
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.