我試圖(沒有成功)將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