我试图(没有成功)将JRuby Rack-Rails应用程序的响应传递给过滤器,以便处理它。基本上我想使用Orbeon XForm引擎来增强来自我的Rails应用程序的XHTML输出。如果我在JRuby Rack上使用简单的Java servlet,那么一切都可以顺利进行。JRuby Rack - 如何添加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>
在此先感谢
桑德罗。
我不确定为什么它会使用“简单”servlet而不是JRuby Rack,因为JRuby Rack是一个servlet。当你说它不起作用时,它好像没有配置过滤器,或者你有错误?如果出现错误,那可能是解决方案的暗示。如果过滤器不在那里,也许JRuby Rack有特殊的方法输出其内容,而不会被过滤器拦截?检查代码时,过滤器中会覆盖getOutputStream()和getWriter(),所以这不应该成为问题。 – avernet
供参考,这里是Orbeon XForms过滤器的源代码:https://github.com/orbeon/orbeon-forms/blob/master/src/java/org/orbeon/oxf/servlet/OrbeonXFormsFilter.java – avernet