Skip to content

Java servlet store broken with Rails 5.1 and Tomcat 7 #211

Closed
@HarlemSquirrel

Description

@HarlemSquirrel

I am trying to set up my rails app to use :java_servlet_store in place of :cookie_store for my session store.

Rails throws undefined method 'get_header' for Rack::Handler::Servlet::DefaultEnv being thrown when adding the following configuration:

if defined?($servlet_context)
  require 'action_controller/session/java_servlet_store'
  # tell rails to use the java container's session store
  Rails.application.config.session_store :java_servlet_store
else
  Rails.application.config.session_store :cookie_store, key: '_servicesdirectory_session'
end

Full backtrace:

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: I, [2017-08-11T19:47:14.637448 #1]  INFO -- : [150177b8-e353-437b-b893-a951d7029046] Started GET "/jruby-rails-tomcat-sample/" for 172.19.0.1 at 2017-08-11 19:47:14 +0000

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: I, [2017-08-11T19:47:14.736209 #1]  INFO -- : [150177b8-e353-437b-b893-a951d7029046] Processing by MessagesController#index as HTML

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: I, [2017-08-11T19:47:14.826652 #1]  INFO -- : [150177b8-e353-437b-b893-a951d7029046] Completed 500 Internal Server Error in 80ms

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: F, [2017-08-11T19:47:14.844744 #1] FATAL -- : [150177b8-e353-437b-b893-a951d7029046]   

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: F, [2017-08-11T19:47:14.846148 #1] FATAL -- : [150177b8-e353-437b-b893-a951d7029046] NoMethodError (undefined method `get_header' for #<Rack::Handler::Servlet::DefaultEnv:0x39f27856>):

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: F, [2017-08-11T19:47:14.846964 #1] FATAL -- : [150177b8-e353-437b-b893-a951d7029046]   

Aug 11, 2017 7:47:14 PM org.apache.catalina.core.ApplicationContext log
INFO: F, [2017-08-11T19:47:14.847805 #1] FATAL -- : [150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:295:in `current_session_id'
[150177b8-e353-437b-b893-a951d7029046] uri:classloader:/jruby/rack/session_store.rb:162:in `session_exists?'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:124:in `exists?'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:149:in `load_for_read!'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:56:in `[]'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/turbolinks-5.0.1/lib/turbolinks/redirection.rb:43:in `set_turbolinks_location_header_from_session'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:413:in `block in make_lambda'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:197:in `block in halting'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/abstract_controller/callbacks.rb:12:in `block in Callbacks'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:198:in `block in halting'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:507:in `block in invoke_before'
[150177b8-e353-437b-b893-a951d7029046] org/jruby/RubyArray.java:1734:in `each'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:507:in `invoke_before'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:130:in `run_callbacks'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/abstract_controller/callbacks.rb:19:in `process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal/rescue.rb:20:in `process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `block in instrument'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/notifications.rb:166:in `instrument'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activerecord-5.1.3/lib/active_record/railties/controller_runtime.rb:22:in `process_action'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/abstract_controller/base.rb:124:in `process'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionview-5.1.3/lib/action_view/rendering.rb:30:in `process'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal.rb:189:in `dispatch'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_controller/metal.rb:253:in `dispatch'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:31:in `serve'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/journey/router.rb:46:in `block in serve'
[150177b8-e353-437b-b893-a951d7029046] org/jruby/RubyArray.java:1734:in `each'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/journey/router.rb:33:in `serve'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/routing/route_set.rb:834:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/conditional_get.rb:25:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
[150177b8-e353-437b-b893-a951d7029046] uri:classloader:/jruby/rack/session_store.rb:79:in `context'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/session/abstract/id.rb:226:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/cookies.rb:613:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/callbacks.rb:97:in `run_callbacks'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/railties-5.1.3/lib/rails/rack/logger.rb:36:in `call_app'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `block in call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `block in tagged'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:26:in `tagged'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/tagged_logging.rb:69:in `tagged'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/railties-5.1.3/lib/rails/rack/logger.rb:24:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/request_id.rb:25:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/activesupport-5.1.3/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/actionpack-5.1.3/lib/action_dispatch/middleware/executor.rb:12:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
[150177b8-e353-437b-b893-a951d7029046] gems/gems/railties-5.1.3/lib/rails/engine.rb:522:in `call'
[150177b8-e353-437b-b893-a951d7029046] uri:classloader:/rack/handler/servlet.rb:22:in `call'

Adding the configuration above to my sample app shows this happens with a new rails app.

I also posted in SO.
https://stackoverflow.com/questions/45594295/undefined-method-get-header-for-rackhandlerservletdefaultenv

Thanks in advance for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions