Demonstrates the configuration of RubyAMF 2.0 in a Ruby on Rails application and an associated Flex application.
A live version of the application can be found here.
-
Clone the repository and run bundle install then rake db:create, db:migrate and db:seed.
-
Launch the server on port [port] and fire it up on locahost:[port].
-
Global RubyAMF configurations are found at the bottom of config/application.rb.
-
Parameter mappings are found in config/routes.rb for adding incoming parameters to the params hash.
-
In-model class mappings are found in the app/models files.
-
Using the
ActionController#credentials
attribute, which contains the :username and :password hash keys set with the FlashRemoteObject.setRemoteCredentials
method, with Authogic authentication is shown in theUserSessionsController#create
method. -
The use of deserialized objects in controllers is demonstrated in the various app/controllers files. Currently, RubyAMF 2.0 has not implemented scaffolding (converting objects to hashes that can be passed to the
create
,update_attributes
, andbuild
methods ofActiveRecord
). Thus, all the examples demonstrate using de-serialized class instances in controller methods. -
TODO: Testing discussion.
Currently due to a (yet un-found) regression in spark.controls.datagroup in SDK 4.5, the Flex application is built using Flex SDK 4.1. You will need to use SDK 4.1 if you want to compile and trace the Flex code.
-
There are two different Flex applications included in this demo:
Lite A read-only Flex application that demonstrates the basics of configuring a Flex application for remoting with source code found in app/flex/lite.
Full A Flex application that demonstrates a complete CRUD application with source code found in app/flex/full.
-
To configure the projects locally with FlashBuilder:
-
Import the project from app/flex/.
-
In Properties/Flex Compiler, configure and select Flex SDK 4.1.
-
Configure the Properties/Flex Build Path (lite version)
-
Output folder: path/to/rubyamf-demo/public (../public/lite)
-
Output folder URL: localhost:[port] (//localhost:/lite)
-
-
-
RubyAMF remoting in each of the applications is:
-
Configured using remoting-config.xml and services-config.xml in the app/flex/config folder and including
-services "../config/services-config.xml"
in the compliler arguments. -
Defined for remote objects in the mxml file business.Services.
-
Note the use a static class variable that ensures that all remote classes are specifically referenced in the Flex application. If you do not do something like this you pull your hair out wondering why you keep getting un-mapped generic Objects back for certain classes when you are testing remote calls after setting up the classes. The reason this happens is you have not yet used the class anywhere and thus the compiler ignores it. Thus, this useful little hack.
-
-
-
RubyAMF remote object configuration is found in the
demolite.business.Services
class. -
Mapped Models and Value Objects corresponding to remote classes are defined in the
demo.models
anddemo.vos
packages (see ruby classes for corresponding client package mapping definition). -
All remote calls are made and handled in the
demolite.views.MainUI
component.
Note this version is not fully functional yet.
-
The full Flex application uses the Mate MVC framework for Flex. Unless otherwise noted, all of the classes discussed below are in the com.rubyamf.demo package.
-
RubyAMF remoting is implemented in the
LocalEventMap
classes in themaps
package in theAsyncMethodInvoker
tag. -
Mapped Models and Value Objects corresponding to remote classes are defined in the
models
andvos
packages (see corresponding ruby classes for associated in-model mapping definition). -
Managers (Mate’s terminology for Controller in MVC) handle all view interactions in their
execute
method. All remote results are handled in thecallResult
andcallFault
methods. Placing breakpoints at the first line of each of these methods will allow you to easily trace how calls are formulated and their results.In each manager, see the
remoteCall
method to see how call parameters are configured and the asynchronous call is dispatched to the correspondingLocalEventMap
. -
The delegate class
com.fosrias.library.business.RemoteService
is responsible for the raw asynchronous calls. Placing breakpoints at the first line of thecall
,onResult
andonFault
methods will allow you to easily trace how the raw remote calls are configured and their raw results. -
The Flex application incorporates a debug console that you can open and close by dragging the white handle at the bottom of the application. Among other things, it displays remote call related timestamps.
-
The
managers.UserSessionsManager
execute
method demonstrates setting remote credentials. -
Tracing shorcuts:
-
Review business.Services class to see how the
RemoteObject
tags are configured for their corresponding controllers. -
In all managers, except
managers.MainManager
, place break points at the beginning of theexecute
,remoteCall
,callFault
, andcallResult
methods to trace how user interaction translates to remote calls and how those calls are handled upon return. -
In the
com.fosrias.library.business.RemoteService
class, place breakpoints at the beginning of thecall
,onFault
, andonResult
methods to trace raw call configuration and
-
(The MIT License)
Copyright © 2011 Mark W. Foster
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.