Jruby/Rack sendfile on Tomcat

I’m having an interesting issue when deploying an app to Tomcat. I’m
using the Acts_as_flying_saucer gem to convert html to PDF. What the
gem/plugin does is render an html view and then uses a java SAX
processor to render a standard PDF/1.4 compliant file in the server’s
TMP directory.

The problem I’m having is when the plugin makes the call to send the
file to the browser. It sends a 0 Byte file. Looking at the Rails log,
it DOES say that it sent /tmp/41c986f5e6249ce24c7698b6494796e0.pdf

Tomcat log shows a 200 status as if it sent the file. But the file in
the /tmp/ directory has info in it and the one sent to the browser is
empty.

The best guess I have is that there is something flaky in the send_file
method.

It works great from webrick. I’ve deployed a WAR on a few different
Tomcat instances on both Linux and Windows… the logs all seem to show
things working fine.

Let me know if more info is needed or if anyone has any ideas on how I
could track down this problem.

Thanks,
-Jim

Jim W. wrote in post #996897:

I’m having an interesting issue when deploying an app to Tomcat. I’m
using the Acts_as_flying_saucer gem to convert html to PDF. What the
gem/plugin does is render an html view and then uses a java SAX
processor to render a standard PDF/1.4 compliant file in the server’s
TMP directory.

The problem I’m having is when the plugin makes the call to send the
file to the browser. It sends a 0 Byte file. Looking at the Rails log,
it DOES say that it sent /tmp/41c986f5e6249ce24c7698b6494796e0.pdf

Tomcat log shows a 200 status as if it sent the file. But the file in
the /tmp/ directory has info in it and the one sent to the browser is
empty.

The best guess I have is that there is something flaky in the send_file
method.

It works great from webrick. I’ve deployed a WAR on a few different
Tomcat instances on both Linux and Windows… the logs all seem to show
things working fine.

Let me know if more info is needed or if anyone has any ideas on how I
could track down this problem.

The issue is in Tomcat not supporting “X-Sendfile”. I just had to
comment that out in my environments/production.rb.

Works perfectly now.

Thanks,
-Jim

On Thu, May 5, 2011 at 5:18 PM, Jim W. [email protected]
wrote:

Let me know if more info is needed or if anyone has any ideas on how I
could track down this problem.

The issue is in Tomcat not supporting “X-Sendfile”. I just had to
comment that out in my environments/production.rb.

Works perfectly now.

You could use a middleware for this, using some ideas from 1:

Make sure you’re using JRuby-Rack version 1.0.8 or greater.

/Nick