I got the Ape running on JRuby and wired Jing back in, which is really useful (some of the so-called Service Docs out there are canine fecal matter). I was pretty damn impressed when the now-2400+ lines of Ape code totally just worked in JRuby. Then, I was irritated by the realization that my primitive CGI setup for running the Ape is just not gonna fly if I have to start up a JVM and JRuby for each request. So I thought “this is what servlets are for, right?” and the good news is that It Can Be Done.

Of course, there were those who told me “We’re working on this, just make the Ape a Rails app and our magic Web Integration will solve the problem!” “Feh” I said. “Camping?” “Bah.” I cast aspersions at frameworks near and far, I’m a PORO kinda guy; if you have Builder::XmlMarkup and a pure heart you’re good to go IMHO. Templates? Scaffolds? ActiveWhatever? No, use the Web Architecture, Luke!

It turns out that Marcin Mielżyński had already constructed a RubyServlet with some inspiration from Jython’s PyServlet. It didn’t work with 0.9.8, but Marcin was hanging out on #jruby and heard me whining and morphed it then & there, and now it does. It took a whole lot of string and glue and reading source code but now I have it running here on my Mac and I have to say it’s cool to point my browser at some JRuby code and have it refresh like instantly, whether because the output is dynamic or because I went and edited the script.

This is not quite ready for prime time; we need to have a bunch of debates. Should RubyServlet be part of the core JRuby.jar? Should you have to copy all eleven (!) JRuby .jar files into your app server? And, most important and fun, how should you map URIs into JRuby method calls? Oh yeah, and once we’ve finished arguing, a little documentation wouldn’t hurt so you don’t have to plow through Marcin’s Java code to figure out how to connect A to B.

Humorous side-note; I was talking this over with Charles Nutter and he wondered if Marcin had done anything about the new Java integration in 0.9.8, and I didn’t even know. Gimme something that claims to be an HttpServletResponse and I’ll call getWriter on it and then I’ll call println whatever comes back and it all Just Works. Duck Typing and Java, sittin’ in a tree... we make progress.


Comment feed for ongoing:Comments feed

From: Christian Neukirchen (Mar 22 2007, at 05:20)

Feel like writing a Servlet adapter for Rack, a Ruby webserver interface?



From: Roberto Chinnici (Mar 22 2007, at 10:02)

You can use Phobos (https://phobos.dev.java.net/).

We figured out how to hook scripting engines to servlets and how to pool them so you don't end up with creating a new JRuby runtime on every call. You can edit any scripts on the fly while the application is running on a servlet container and they'll be recompiled automatically.

Check out this sample written in Ruby:


The "something that claims to be an HttpServletResponse" is the $response global. Easy, isn't it?


From: Michael Daines (Apr 01 2007, at 11:51)

I suspect I'm missing something pretty huge here, but if I seem naive, so be it!

Do you really have to use Jing (and therefore go back to JRuby)? As an alternative, you mention that program RNV in a previous post and something about porting it. (I assume to Ruby?) I'm wondering why porting it would really be necessary, since it's a command-line application, and Ruby is great for calling out to other things, why can't you do just that? RNV even includes a program called RVP specifically for calling its validation stuff from somewhere else. (I do admit I have not used RVP at all.)

If it's an issue of features, like Jing has something special you need that RNV doesn't, (I also admit I sort of just glanced over ape's validator.rb) then ignore me!


author · Dad · software · colophon · rights
picture of the day
March 21, 2007
· Technology (77 fragments)
· · Java (123 more)
· · Open Source (82 more)
· · Ruby (93 more)

By .

I am an employee
of Amazon.com, but
the opinions expressed here
are my own, and no other party
necessarily agrees with them.

A full disclosure of my
professional interests is
on the author page.