JRuby Rack

From JRubyWiki

Jump to: navigation, search

JRuby-Rack is a lightweight adapter for the Java servlet environment that allows any Rack-based application to run unmodified in a Java servlet container. JRuby-Rack supports Rails, Merb, as well as any Rack-compatible Ruby web framework.

For more information on Rack, visit http://rack.rubyforge.org.

Contents

Download

JRuby-Rack 0.9 is the first public release. Download it:

http://repository.codehaus.org/org/jruby/rack/jruby-rack/0.9/jruby-rack-0.9.jar

JRuby-Rack is also bundled with Warbler 0.9.9, which is available as a Ruby gem (jruby -S gem install warbler).

Features

Servlet Filter

JRuby-Rack's main mode of operation is as a servlet filter. This allows requests for static content to pass through and be served by the application server. Dynamic requests only happen for URLs that don't have a corresponding file, much like many Ruby applications expect.

Goldspike-compatible Servlet

JRuby-Rack includes a stub RailsServlet and recognizes many of Goldspike's context parameters (e.g., pool size configuration), making it interchangeable with Goldspike, for convenience of migration. One caveat is that static content is served by Rack, which requires acquisition of a JRuby runtime. Your throughput with static files will be much lower than when JRuby-Rack is configured as a servlet filter. You have been warned!

Servlet environment integration

  • Servlet context is accessible to any application both through the global variable $servlet_context and the Rack environment variable java.servlet_context.
  • Servlet request object is available in the Rack environment via the key java.servlet_request.
  • Servlet request attributes are passed through to the Rack environment.
  • Rack environment variables and headers can be overridden by servlet request attributes.
  • Java servlet sessions are used as the default session store for both Rails and Merb. Session attributes with String keys and String, numeric, boolean, or java object values are automatically copied to the servlet session for you.

JRuby Runtime Management

JRuby runtime management and pooling is done automatically by the framework. In the case of Rails, runtimes are pooled. For Merb and other Rack applications, a single runtime is created and shared for every request.

Building

Ensure you have JRuby with the buildr and rack gems installed.

 jruby -S gem install buildr rack

Checkout the JRuby Rack code and cd to that directory

 svn co http://svn.codehaus.org/jruby-contrib/trunk/rack
 cd rack

Resolve dependencies, compile the code, and build the jar file.

 jruby -S buildr package

The generated jar should be found in target/jruby-rack-*.jar.

Personal tools