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

发布于 2024-12-02 20:49:24 字数 2533 浏览 0 评论 0原文

我正在尝试(没有成功)将 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>

提前致谢
桑德罗.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2024-12-09 20:49:24

我不熟悉 Orbeon XForms,所以我不确定您的问题是什么。但根据上面的 web.xml,Orbeon 过滤器仅应用于 /orbeon/*/page/* URL,而 Rack 过滤器则应用于所有内容。

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

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文