我的服务器在Tomcat上运行JRuby on Rails,其GWT前端通过gwt :: RequestBuilder连接。当我在Tomcat上运行WEBrick以及开发模式时,一切似乎都运行良好,但在生产模式下,一件奇怪的事情正在发生。我的登录控制器有一个在您第一次点击页面时运行的操作:
def is_logged_in
if session[:current_user]
# do some stuff and render response XML
else
puts "nothing status unauthorized"
render :nothing => true, :status => :unauthorized
end
end
在开发中,它工作正常,我收到401 Unauthorized错误,GWT选择它并显示登录屏幕。在生产中,我得到200 OK,没有XML响应体,即使服务器日志中出现“未授权状态”。清除Tomcat临时文件夹和webapp文件夹没有帮助。是什么赋予了?感谢您的帮助,希望这是我忽略的一些简单。
供参考: 我在Windows 7 x64中使用JRuby 1.6.6和Tomcat7。
的Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'haml'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
platforms :ruby do
gem 'mysql2'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter'
gem 'jdbc-mysql', :require => false
end
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
end
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
production.rb
Eiserver::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = true
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
为了进一步阐述希望某种灵魂指向我正确的方向,我98%确定问题在于Rails代码而不是GWT,因为对is_logged_in路由执行CURL会导致200 OK好。
这是我发现的另一个小故事,至少让我回到了工作状态,但仍然留下了许多未解决的问题。我最近更新了jruby-1.6.6,但保留了我的版本jruby-1.6.0以防万一。当我使用旧的jruby吵醒时,事情又开始起作用了。但这只是指向jruby版本和一堆宝石,我不知道如何开始找到罪魁祸首。是否有人熟悉一连串的插件,指出我正确的方向?
搁置并重新审视之后。我几乎可以肯定它与轨道宝石的版本很麻烦。我用两个版本的JRuby生成了WAR,1.6.0和1.6.6。代码是相同的,但1.6.0没有问题,而1.6.6有上面提到的问题,结果是所有控制器总是只在生产中输出200 OK响应,无论我明确设置什么状态代码。希望有人找到了解决这个问题的方法,并且已经在更新的JRuby gem版本中进行了修改。
答案 0 :(得分:1)
使用logger.warn
代替puts
。另外,仅使用head
返回标题。
logger.warn "nothing status unauthorized"
head :unauthorized