JRuby Rack - 如何添加servlet过滤器?

时间:2011-09-02 20:24:25

标签: jruby servlet-filters orbeon jruby-rack

我正在尝试(没有成功)将JRuby Rack-Rails应用程序的响应传递给过滤器以便对其进行处理。基本上我想使用Orbeon XForm引擎来增强来自我的Rails应用程序的XHTML输出。如果我在JRuby Rack上使用简单的Java servlet,一切都很顺利。

这是web.xml文件:

<!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>

提前致谢
桑德罗。

1 个答案:

答案 0 :(得分:0)

我不熟悉Orbeon XForms,所以我对你的问题不是很肯定。但根据上面的web.xml,Orbeon过滤器仅适用于/orbeon/*/page/*网址,而Rack过滤器适用于所有内容。

如果servlet方法有效,为什么不坚持呢?