2

I'm trying (with no success) to pass the response of a JRuby Rack - Rails application to a filter in order to get it processed. Basically I want to use the Orbeon XForm Engine to enhance the XHTML output coming from my Rails application. If I use a simple Java servlet instead on JRuby Rack everything works smoothly.

Here's the web.xml file:

<!DOCTYPE web-app PUBLIC
  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

  <context-param>
    <param-name>public.root</param-name>
    <param-value>/</param-value>
  </context-param>

  <context-param>
    <param-name>rails.env</param-name>
    <param-value>production</param-value>
  </context-param>

  <context-param>
    <param-name>jruby.min.runtimes</param-name>
    <param-value>2</param-value>
  </context-param>

  <context-param>
    <param-name>jruby.max.runtimes</param-name>
    <param-value>4</param-value>
  </context-param>


  <filter>
    <filter-name>orbeon-xforms-filter</filter-name>
    <filter-class>org.orbeon.oxf.servlet.OrbeonXFormsFilter</filter-class>
    <init-param>
      <param-name>oxf.xforms.renderer.context</param-name>
      <param-value>/orbeon</param-value>
    </init-param>
  </filter>

  <!-- This is necessary so that XForms engine resources can be served appropriately -->
  <filter-mapping>
    <filter-name>orbeon-xforms-filter</filter-name>
    <url-pattern>/orbeon/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <!-- Any web resource under /xforms-jsp is processed by the XForms engine -->
  <filter-mapping>
    <filter-name>orbeon-xforms-filter</filter-name>
    <url-pattern>/page/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <filter>
    <filter-name>RackFilter</filter-name>
    <filter-class>org.jruby.rack.RackFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>RackFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


  <listener>
    <listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
  </listener>


</web-app>

Thanks in advance
Sandro.

Sandro Paganotti
  • 2,295
  • 16
  • 12
  • I'm not sure why it would be working with a "simple" servlet and not JRuby Rack, since JRuby Rack is a servlet. When you're saying that it isn't working, is it as if the filter was not configured, or do you get an error? If you get an error, that could be a hint towards a solution. If it's just as if the filter wasn't there, maybe JRuby Rack has special a way to output its content which is not intercepted by the filter? Checking in the code, both `getOutputStream()` and `getWriter()` are overridden in the filter, so this shouldn't be the problem. – avernet Sep 03 '11 at 02:36
  • And for reference, here is the source of the Orbeon XForms filter: https://github.com/orbeon/orbeon-forms/blob/master/src/java/org/orbeon/oxf/servlet/OrbeonXFormsFilter.java – avernet Sep 03 '11 at 02:37

1 Answers1

0

I'm not familiar with Orbeon XForms, so I'm not positive about what your problem is. But according to the above web.xml, the Orbeon filters are only applied to /orbeon/* and /page/* URLs, while the Rack filter gets applied to everything.

If the servlet approach works, why not stick with that?

Nick Sieger
  • 3,315
  • 20
  • 14
  • Thanks for the reply, The fact that the filter needs to be applied only on certain url (/orbeon/* and /page/*) is part of the behavior I want to follow. The servlet approach means not use Ruby at all, ('cause it worked with a Java servlet) and I'd like to keep Ruby in this project. Can you confirm that is possible to pass the HTML outputted from Rails into another filter ? Do you have some sample code ? Thanks in advance :) – Sandro Paganotti Sep 02 '11 at 23:31