Giter Site home page Giter Site logo

rubyamf's Introduction

DESCRIPTION:

RubyAMF is a full-featured AMF gateway based off of Rack and supporting advanced integration with Rails and other Rack-based frameworks. It includes advanced class mapping functionality, like camel to underscore case translation, parameter mapping to convert function calls to parameter hashes for actions, hooks for processing AMF authentication credentials, and many more features.

UPGRADE FROM rubyamf_plugin:

  1. Delete RAILS_ROOT/vendor/plugins/rubyamf or comment out every line in RAILS_ROOT/vendor/plugins/rubyamf/init.rb.

  2. Add gems to application:

    Bundler:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    

    environment.rb:

    config.gem "RocketAMF"
    config.gem "rubyamf"
    
  3. Configure the endpoint path by adding the following to the end of your environment.rb file:

    RubyAMF.configure do |config|
      config.gateway_path = "/rubyamf/gateway"
    end
    

    The gateway path is no longer specified in routes.rb, so you can remove it and rubyamf_controller.rb if you want.

  4. Try out your application!

    RubyAMF should load your legacy rubyamf_config.rb file and you should be on your way.

If you want to learn more about the new features, please check out the demo app at github.com/rubyamf/rubyamf-demo or the RDoc at (SOMEWHERE).

RAILS 2 INSTALL:

  1. Add gems to application:

    Bundler:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    

    environment.rb:

    config.gem "RocketAMF"
    config.gem "rubyamf"
    
  2. Configure the endpoint path by adding the following to the end of your environment.rb file:

    RubyAMF.configure do |config|
      config.gateway_path = "/rubyamf/gateway"
    end
    

Check out the demo app at (SOMEWHERE) or the RDoc at (SOMEWHERE) for information about configuration and use.

RAILS 3 INSTALL:

  1. Add the gems to your Gemfile:

    gem "RocketAMF", :git => "git://github.com/rubyamf/rocketamf.git"
    gem 'rubyamf', :git => 'git://github.com/rubyamf/rubyamf.git'
    
  2. Configure the endpoint path by adding the following to your application.rb:

    config.rubyamf.gateway_path = "/amf"
    

Check out the demo app at github.com/rubyamf/rubyamf-demo or the RDoc at (SOMEWHERE) for information about configuration and use.

OTHER RACK FRAMEWORK INSTALL:

TODO: Write up instructions

Running Tests

Unless a command-line Rails ‘major.minor’ version is specified both bundle install, rspec, and rake spec will default to Rails 4.0. To run tests against different versions of Rails, use:

$ RAILS_VERSION=major.minor bundle install
$ RAILS_VERSION=major.minor rspec

LICENSE:

(The MIT License)

Copyright © 2011 Stephen Augenstein

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rubyamf's People

Contributors

fosrias avatar rodrigob avatar seantan avatar warhammerkid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rubyamf's Issues

As of ActiveRecord 3.2.9, NaN no longer supported; throws FloatDomainError (NaN)

See the change here:

rails/rails@v3.2.8...v3.2.10#L63L78

This causes ActiveRecord to fail on NaN input with the error "FloatDomainError (NaN)"

Here's the full stack of this error from an older version fork we're using at harleyttd/rubyamf—I did a quick look through the current code and it appears this will still be an issue in the current model.rb, so I'm still reporting it for good measure.

/Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:178:in `to_i'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:178:in `value_to_integer'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/connection_adapters/column.rb:78:in `type_cast'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/dirty.rb:86:in `_field_changed?'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/dirty.rb:63:in `write_attribute'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_methods/write.rb:14:in `slider_min_old='
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:78:in `each'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
  /Users/trisweb/.rvm/gems/ruby-1.9.3-p194@socialsci/gems/activerecord-3.2.10/lib/active_record/attribute_assignment.rb:36:in `attributes='
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/rails/model.rb:105:in `rubyamf_init'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/class_mapping.rb:201:in `populate_ruby_obj'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:43:in `populate_from_stream'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:43:in `handle_amf'
  /Users/trisweb/SocialSci/libraries/harleyttd-rubyamf/lib/rubyamf/request_parser.rb:30:in `call'
#... etc.

This is a fairly large issue since Flash uses NaN extensively as an uninitialized Number value (as far as I can remember) and it's very likely that that will make it to ActiveRecord.

Interesting to note that previously Rails handled NaN incorrectly by instead assuming it was a Boolean in value.to_i rescue value ? 1 : 0 to convert it to an int (see line in diff above). This means (yikes) that NaN was interpreted as the number 1, since NaN is a true value in ruby, unless there was some workaround already in place that I'm not aware of.

Cross-posting this to rails/rails to let them decide if they will fix it by correctly handling NaN in ActiveRecord.

Does rubyamf support jruby?

seems rubyamf based on rocketAmf, and rocketAmf is C extension.
But I need jruby, then any solution?

Thanks.

AMF Deserialization problem

I am a heavy user of AMF serialization and deserialization. Meaning, almost every one of my requests and responses will contain multiple and / or nested, associated models. With RubyAMF v1, all of this serialization and deserialization worked well.

But I seem to be having problems with RubyAMF v2 when it comes to nested models deserialization. When I send back an object of just one model type (with no associations), the deserialization seems to work fine. But when the request contains more complex objects, I receive a lot of ActiveRecord::AssociationTypeMismatch errors. A couple of examples:

ActiveRecord::AssociationTypeMismatch (Exam(#2205179320) expected, got Array(#2148433420))
ActiveRecord::AssociationTypeMismatch (MiniSubject(#2202173459) expected, got Date(#2157465432))

... where Exam and MiniSubject are models in my app. I use Charles as a local proxy to inspect my AMF calls. In Charles, I can see that the objects in my request body are of the correct types. No mismatch there. The mini_subject association had a MiniSubject object, not a Date.

I tried debugging and inspected the props variable in the rubyamf/class_mapping.rb file's populate_ruby_obj method. I saw that the mini_subject key in the props hash had a Date value. I have no idea how the gem has deserialized it into a date.

I just switched back to using RubyAMF v1 and the same request works flawlessly.

Let me know if you need any more help. When I get the time, I will try to make a sample app to reproduce the problem.

Does not work with Rails 3.2 and tests fail

After upgrading my app to Rails 3.2, I get this error when trying to POST using RubyAMF:

NoMethodError (undefined method `attributes_from_column_definition' for #):

I checked out a copy of rubyamf and run tests on it. Tests pass with Rails 3.1, but when I run with Rails 3.2, any tests that involve spec/model_spec.rb will fail.

This gets spit out repeatedly:

DEPRECATION WARNING: The method `_name', matching the attribute `name' has dispatched through method_missing. This shouldn't happen, because `name' is a column of the table. If this error has happened through normal usage of Active Record (rather than through your own code or external libraries), please report it as a bug. (called from /Users/dtt22/code/gems/rubyamf/spec/model_spec.rb:29)

I haven't been able to figure out what's the root cause, but this refactoring of ActiveRecord may be the culprit:
rails/rails@ceb33f8

Can somebody with advanced knowledge of RubyAMF take a look to see if RubyAMF can be updated to work with ActiveRecord 3.2 please?

Legacy rubyamf_config.rb doesn't seem to be read correctly...

Howdy,

First, unrelated I know, but is the google group dead?

Second, I'm not the principal Flex developer on this project; I'm the Ruby developer. I've been trying to upgrade our application to Ruby 1.9.3/Rails 3.2.15 and upgraded rubyamf from plugin (version 1.6.6 accoding to the CHANGELOG) to the gem hosted here. However, so far, I've seen no data in the SWF. When I asked our Flex developer, this was her reply:

"I ran the current flex web application in debug mode. The data comes in from the server already defined as the value object. That is the claim listing data comes in as ClaimInfo objects.

In the upgrade-ruby version the data arrives defined as a generic object. This data cannot be bound to an value object in the flex app."

Where do I look? How can I debug/fix this? If the rubyamf_config.rb file is considered legacy, what is now the preferred method of defining the rubyamf configuration? I already looked in the demo app and would like to centralize the configuration instead of having it spread out over several models.

Tries to set associations which are not sent from Flex

In my project, the parameters of my AMF calls from Flex are not always just integers or strings. The demo app only shows parameters of integer type. I send model objects as parameters too (for example a "blog" object). This model object will NOT necessarily have ALL its properties and associations set. Using the previous rubyamf_plugin, when such a model object is received by my Rails action, only those properties and associations which the Flex object had, would be set on the deserialized Rails object. Then, I read the required (relevant) properties and / or associations and saved them to the DB.

In RubyAMFv2, this does not seem to work. RubyAMFv2 seems to expect to find ALL parameters and associations on every Flex object it receives. When it doesn't find one, it throws an exception. I think this is undesirable behavior.

I think the problem is near here: line 67 - 70 in the lib/rubyamf/rails/model.rb:

# Set attributtes
# warhammerkid: Should we be setting associations some other way (not attributes)?
rubyamf_set_non_attributes attrs, base_attrs
self.send(:attributes=, attrs)

The first 11 lines of the backtrace of the error is below. "papers" is an association that I am NOT sending from Flex.

"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations/association_collection.rb:354:in `replace'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/gems/activerecord-3.0.10/lib/active_record/associations.rb:1515:in `papers='",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `send'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:120:in `rubyamf_set_non_attributes'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `each'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/model.rb:116:in `rubyamf_set_non_attributes'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/rails/model.rb:69:in `rubyamf_init'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/class_mapping.rb:201:in `populate_ruby_obj'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `populate_from_stream'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:42:in `handle_amf'",
"/Users/anjan/.rvm/gems/ree-1.8.7-2011.03@rb/bundler/gems/rubyamf-f401fc144d47/lib/rubyamf/request_parser.rb:29:in `call'"

Please let me know if you need any other information. I would appreciate any assistance to solve this problem.

Thanks.
Anjan

Error Serializing ActiveRecord::Relation

I think this is more of a gotcha than an issue but I wanted to post it to get some feedback.

The new query interface in rails 3 returns an ActiveRecord::Relation object instead of Array. If you try to pass this directly to the renderer it results in a LocalJumpError (no block given) error that can be traced back to the generic object serializer in RocketAMF (ClassMapping#props_for_serialization). Here's my Controller example:

class AddressesController < ApplicationController

   respond_to :amf, :xml

    def list_all_states
      @states = State.where(:status => 'A')
      respond_with(@states)
    end
end

I understand why this is happening and simply appending the .all to my query to kill lazy loading and get an Array allows the serialization to work like a charm:

 def list_all_states
   @states = State.where(:status => 'A').all
   respond_with(@states)
 end

However, I would still like to take advantage of the lazy loading feature for non amf calls and don't want to pollute all my actions with is_amf checks. I added the following to the Renderer hook in rails3_bootstrap.rb and it seems to work good.

# Hook up rendering
ActionController::Renderers.add :amf do |amf, options|
  @amf_response = amf.is_a?(ActiveRecord::Relation) ? amf.to_a : amf
  @mapping_scope = options[:class_mapping_scope] || options[:mapping_scope] || nil
  self.content_type ||= Mime::AMF
  self.response_body = " "
end

It seems like a safe bet since ActiveRecord::Relation objects should never be sent to the serializer. Is there a better way to handle this or am I missing something obvious? Thanks for the great work on rubyAMF and RocketAMF. It rocks!

Preloading models?

In my project I notice that when I run my project in development ActiveRecord models coming from the Flex side are being converted into hashes because RubyAMF is not recognizing them. This is because the models are not pre-loaded and so they are unknown to RubyAMF as it deserializes.

Is there a way around this? So far I have been trying to require my models manually in an initializer but thats a horrible solution.

SystemStackError Crash in Param Population

I'm getting the following stack trace when I try to make AMF calls to the server under Rails 2.3.11.

SystemStackError (stack level too deep):
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/rails/request_processor.rb:47:in `handle_method'
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/rails/request_processor.rb:19
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/envelope.rb:80:in `call'
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/envelope.rb:80:in `dispatch_call'
  /usr/lib/ruby/gems/1.8/bundler/gems/rocketamf-9e80f0a08c97/lib/rocketamf/remoting.rb:106:in `each_method_call'
  /usr/lib/ruby/gems/1.8/bundler/gems/rocketamf-9e80f0a08c97/lib/rocketamf/remoting.rb:87:in `each'
  /usr/lib/ruby/gems/1.8/bundler/gems/rocketamf-9e80f0a08c97/lib/rocketamf/remoting.rb:87:in `each_method_call'
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/rails/request_processor.rb:18:in `call'
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/request_parser.rb:51:in `handle_amf'
  /usr/lib/ruby/gems/1.8/bundler/gems/rubyamf-b4c2445b19fb/lib/rubyamf/request_parser.rb:29:in `call'
  passenger (3.0.2) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'

Problem with using RocketAMF::Ext::FastClassMapping

If I add to file config/application.rb a string

config.rubyamf.class_mapper = RocketAMF::Ext::FastClassMapping

then I get the following error:
ArgumentError (Invalid type for property key: 5)
when trying to access the application from Flex RemoteObject.

Content Length in headers not converted to string

In lib/rubyamf/request_parser.rb, line number 46:

return [400, {"Content-Type" => "text/plain", 'Content-Length' => msg.length}, [msg]]

The .to_s is missing for the msg.length. In all other places, the string conversion has been done. I guess this was an oversight.

I noticed this problem in the following situation: The AMF deserialization failed and the gem constructed the headers for the response. But the server (I was using Thin) complained that it couldn't do some operation on Fixnum. I don't remember the exact error. Thin did not even give a stacktrace of the error. Webrick gave a stacktrace which allowed me to find the source of the error.

The reason for the deserialization failing is another bug, which I will report separately.

Problem in trying to load legacy config file

Hi

I am trying to load legacy config file under config/rubyamf_config.rb. But its not taking my custom configuration.

Can you give me a sample rubyamf_config.rb file?

Thanks
Ranjith

How to get customized actionscrip class instead of generic Object on flex client after getting result from server side?

hi,

I have added RemoteClass on the actionscript class,
Anything to do on server side?

In old rubyAmf, add some code like
ClassMappings.register(
:actionscript => 'Post',
:ruby => 'Post',
...) in rubyamf_config.rb,

But for this version, seems no rubyamf_config.rb and ClassMappings.register is only for legacy.
And I also cannot find any clue in https://github.com/rubyamf/rubyamf-demo.

So, how to get specific actionscript class on flex client?

Thanks.

Params don't exist at root level, only under a '0' key

Hi there.

I recently upgraded from an older version of RubyAMF, and am noticing unexpected behavior.

Previously, params would exist at both the root level and under a 0 key. Now, they only exist under the latter. Example:

# newer RubyAMF version
params = {
  "0": {
    "event": {
      "category": "testing",
      "name": "123"
    }
   # previously, the 'event' node would also exist at the root of 'params'
  }

Can you help me resolve this? I'm guessing it's a setting I'm missing.

Support for scaffolding, or maybe not. Perhaps this is a configuration issue.

Hi there.

I saw this error message while browsing through the code:
"CONFIG PARSE ERROR: scaffolding is not supported. Please log a feature request if you need it."

So, before I log a feature request as suggested, I want to confirm this is the source of my problems. I just upgraded an old app from the RubyAMF plugin (ie. /vendor/plugins/) to this gem on a Rails 3 app. Things are now broken. I suspect it has to do with the param parsing, since the following log entries shows the params are still being passed in the same way (no surprise), but the Rails app is not getting the same params value as before the upgrade:
Parameters: {0=>{"interaction"=>{"name"=>"initial", "category"=>"timing"}}}

When I do inspect params[:interaction], I get nil, whereas prior to this upgrade, I would get the expected hash.

FWIW, my config looks like:

> RubyAMF.configuration
=> #<RubyAMF::Configuration:0x102b227a0
 @auto_class_mapping=false,
 @check_for_associations=true,
 @class_mapper=RubyAMF::ClassMapping,
 @gateway_path="/rubyamf/gateway",
 @hash_key_access=:symbol,
 @ignore_fields=["created_at", "created_on", "updated_at", "updated_on"],
 @param_mappings={},
 @populate_params_hash=true,
 @preload_models=[],
 @show_html_gateway=true,
 @translate_case=false,
 @use_array_collection=false>

Thanks for any help.
-Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.