2013-07-22 29 views
2

我有一個在tomcat下運行的jruby rails應用程序。 url中的一些格式不正確的查詢字符串會導致Rack在生產模式下顯示異常堆棧跟蹤。有沒有辦法妥善處理。我不認爲我可以使用config.exception_app,因爲它只會處理從rails應用程序生成的異常。在這種情況下,異常在到達rails應用程序之前生成。這裏是個例外:如何在到達您的導軌應用程序之前處理從機架產生的異常

org.jruby.exceptions.RaiseException: (ArgumentError) invalid %-encoding (/"{}\%#$()) 
    at Module.decode_www_form_component(jar:file:/usr/local/apache- 
tomcat/webapps/ROOT/WEB-INF/lib/gems-gems-jruby-jars-1.7.3-lib-jruby-stdlib- 
1.7.3.jar!/META-INF/jruby.home/lib/ruby/1.9/uri/common.rb:898) 
    at Rack::Utils.unescape(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:41) 
    at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:94) 
    at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2361) 
    at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:94) 
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613) 
    at Rack::Utils.parse_nested_query(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/utils.rb:93) 
    at Rack::Request.parse_query(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/request.rb:332) 
    at Rack::Request.POST(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/request.rb:209) 
    at Rack::MethodOverride.method_override(/usr/local/apache- 
tomcat/webapps/ROOT/WEB-INF/gems/gems/rack-1.4.5/lib/rack/methodoverride.rb:26) 
    at Rack::MethodOverride.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/methodoverride.rb:14) 
    at Rack::Runtime.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/runtime.rb:17) 
    at ActiveSupport::Cache::Strategy::LocalCache::Middleware.call(/usr/local/apache- 
tomcat/webapps/ROOT/WEB-INF/gems/gems/activesupport- 
3.2.13/lib/active_support/cache/strategy/local_cache.rb:72) 
    at Rack::Lock.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-1.4.5/lib/rack/lock.rb:15) 
    at Rack::Cache::Context.forward(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:136) 
    at Rack::Cache::Context.pass(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:143) 
    at Rack::Cache::Context.invalidate(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:155) 
    at Rack::Cache::Context.call!(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:71) 
    at Rack::Cache::Context.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/rack-cache-1.2/lib/rack/cache/context.rb:51) 
    at Rails::Engine.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/railties-3.2.13/lib/rails/engine.rb:479) 
    at Rails::Application.call(/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/gems/gems/railties-3.2.13/lib/rails/application.rb:223) 
    at Rack::Handler::Servlet.call(file:/usr/local/apache-tomcat/webapps/ROOT/WEB- 
INF/lib/gems-gems-jruby-rack-1.1.13.1-lib-jruby-rack- 
1.1.13.1.jar!/rack/handler/servlet.rb:22) 
+0

java land默認是在你的應用服務器上配置一個500模板,也就是你的tomcat – phoet

+0

我最終寫了一個機架中間件來攔截異常並處理它。 – DrChanimal

回答

0

如果Ruby運行時被啓動 - 在這種情況下,似乎是......你應該能夠配置(最小)機架錯誤應用剛剛成立的SMT架-Y(require 'my_error_app'; run MyErrorApp )進入jruby.rack.error.app環境參數(例如,在您的的web.xml與鶯)

+2

你能分享更多關於此的信息嗎?我無法找到如何做到這一點的例子。如何編寫機架錯誤應用程序以及如何使用jruby.rack.error.app上下文參數。 Jruby-rack github頁面似乎沒有解釋jruby.rack.error.app – DrChanimal

0

我最後寫一個機架中間件優雅地處理異常。我在MethodOverride中間件之前插入中間件,它是引發異常的地方。

相關問題