Erlang talking to apache via AJP mod_jkPosted on February 20th, 2009 6 comments
Where have I been all this time since Onam? Its been 5 months since I wrote something, things have been busy at work and I have been exploring a new language, Erlang.
I was first exposed to Erlang via blog posts popping up on HackerNews and Lambda the Ultimate. Lots of good things were said there and I have had a liking to recursive functions since my Pascal days. So did a deep dive, got the Erlang Bible by Joe Armstrong on my London trip and the book was a revelation. The syntax was weird at first but then I have begun to like it. The pattern matching function syntax is just the one for writing recursive functions. And yeah bit manipulation with pattern matching is like absolute heaven if you want to do some protocol implementation.
Coupling Erlang to provide a web interface is essential, and I was hacking around with the scgi adapter, which was in disco and lighttpd. But then I needed a plugin to apache and scgi was not an option. Other options cgi, fcgi, ajp. Of these ajp was the best fit since mod_jk is pretty widely used for coupling servlet containers. I could not find an official spec for AJP and Apache’s documentation was the best available. The protocol is pretty straight forward and getting it working from an Erlang implementation was quick. I have a working version up and is available on github. This is the first time I’m putting something out in public domain so forgive any obvious mistakes and feel free to point out or jump in and fix things.
There is lot of scope for improvement in there, this is just a working skeleton to serve requests from Erlang. I have tried to give it a bit order by having a behaviour defined for any module to plugin. Have your module confirm to the gen_ajp_handler behaviour and call back to gen_ajp_handler methods send_headers, send_data, request_data, end_request for obvious functionality. The dispatch mechanism is not yet filled out. Watch out here and on git hub for updates.