HTTP Streaming with Ruby on Rails running with JRuby (on Tomcat)

Is there any way to utilize Rails HTTP Streaming, the conventional way provided in Ruby on Rails 3.1, with JRuby (running in Tomcat)?

I did not expect this to work, but I’ll post the error message anyway:

NameError (uninitialized constant ActionView::StreamingTemplateRenderer::Fiber):
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/streaming_template_renderer.rb:71:in delayed_render' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/abstract_renderer.rb:38:in instrument’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in instrument' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in instrument’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in instrument' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/abstract_renderer.rb:38:in instrument’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/streaming_template_renderer.rb:70:in delayed_render' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/streaming_template_renderer.rb:56:in render_template’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/streaming_template_renderer.rb:23:in call' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_view/renderer/streaming_template_renderer.rb:23:in each’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/rack-1.4.1/lib/rack/chunked.rb:23:in each' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_dispatch/http/response.rb:44:in send’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/actionpack-3.2.1/lib/action_dispatch/http/response.rb:44:in each' /path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/rack-1.4.1/lib/rack/body_proxy.rb:26:in send’
/path/to/tomcat/webapps/ROOT/WEB-INF/gems/gems/rack-1.4.1/lib/rack/body_proxy.rb:26:in method_missing' file:/path/to/tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.1.4.jar!/jruby/rack/response.rb:103:in send’
file:/path/to/tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.1.4.jar!/jruby/rack/response.rb:103:in write_body' file:/path/to/tomcat/webapps/ROOT/WEB-INF/lib/jruby-rack-1.1.4.jar!/jruby/rack/response.rb:50:in respond’

my controller looks like:
class ApplicationController < ActionController::Base
def index
render :stream => true
end
end

Thanks in advance for any pointers. Thanks again!

this feature needs Fiber and that you have only with ruby 1.9.x, i.e.
you need to use jruby in 1.9 mode. there is options setting in jruby-
rack (or in warbler).

Yes, just found that. This now works.

warble.rb:

Warbler::Config.new do |config|

stuff before

config.webxml.jruby.compat.version = “1.9”

stuff after

end

In addition to the content, It spits out some random numbers and letters as it streams, but I guess I’ll find the answer for that in due time too :slight_smile: