jimsynz / faye-rails

Simple Rails glue for the Faye messaging protocol.
MIT License
435 stars 79 forks source link

REXML::ParseExeption (The document "***" does not have a valid root) on callback-polling #37

Closed baascommandeur closed 11 years ago

baascommandeur commented 11 years ago

When I try to connect with an Android browser, the following error appears:

REXML::ParseException (The document "message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fsubscribe%22%2C%22clientId%22%3A%2254rzpsncv4pe01od07wfapg0td4gzat%22%2C%22subscription%22%3A%22%2Fwaitinglist%2Fupdate%22%2C%22id%22%3A%223%22%7D%5D" does not have a valid root):
  activesupport (3.2.11) lib/active_support/xml_mini/rexml.rb:35:in `parse'
  activesupport (3.2.11) lib/active_support/xml_mini.rb:80:in `parse'
  activesupport (3.2.11) lib/active_support/core_ext/hash/conversions.rb:98:in `from_xml'
  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:41:in `parse_formatted_parameters'
  actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:17:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__2790425369923233704__call__4262545661994225693__callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
  quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.11) lib/rails/engine.rb:479:in `call'
  railties (3.2.11) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
  thin (1.5.1) lib/thin/connection.rb:81:in `block in pre_process'
  thin (1.5.1) lib/thin/connection.rb:79:in `catch'
  thin (1.5.1) lib/thin/connection.rb:79:in `pre_process'
  thin (1.5.1) lib/thin/connection.rb:54:in `process'
  faye-websocket (0.4.7) lib/faye/adapters/thin.rb:41:in `process'
  thin (1.5.1) lib/thin/connection.rb:39:in `receive_data'
  faye-websocket (0.4.7) lib/faye/adapters/thin.rb:45:in `receive_data'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
  eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
  thin (1.5.1) lib/thin/backends/base.rb:63:in `start'
  thin (1.5.1) lib/thin/server.rb:159:in `start'
  rack (1.4.1) lib/rack/handler/thin.rb:13:in `run'
  rack (1.4.1) lib/rack/server.rb:265:in `start'
  railties (3.2.11) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.11) lib/rails/commands.rb:55:in `block in <top (required)>'
  railties (3.2.11) lib/rails/commands.rb:50:in `tap'
  railties (3.2.11) lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:8:in `require'
  script/rails:8:in `<main>'

When using just Faye the phone can just connect.. Disabling callback-longpolling makes all connection types unusable, so it has to be callback-longpolling creating the error here..

Using Ruby 1.9.3 & Rails 3.2.11

baascommandeur commented 11 years ago

I managed to solve this issue by adding the following line to the transports/cors.js file:

xhr.setRequestHeader( "Content-type","application/text" );

Right before the xhr.send() line..

jimsynz commented 11 years ago

Can you try disabling Rails' XML parameter parsing?

Stick this in an initializer:

ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
baascommandeur commented 11 years ago

That also solves the problem..!