Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
mapping question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
roobnoob  
View profile  
 More options Feb 20 2008, 9:26 pm
From: roobnoob <gtga...@gmail.com>
Date: Wed, 20 Feb 2008 18:26:29 -0800 (PST)
Local: Wed, Feb 20 2008 9:26 pm
Subject: mapping question
Hi, i'm starting to use rubyamf, and if i have a ruby object that i
want to map that is NOT an ActiveRecord object, how would i do that?

Eg, the following works fine:

ClassMappings.register(
        :actionscript => 'com.pomodo.vo.AccountVO',
        :ruby => 'Account',
        :type => 'active_record',
        :attributes => ['id', 'email', 'birthdate', 'gender'] )

Account is an ActiveRecord class found in the 'models' directory. The
following does not work:

ClassMappings.register(
        :actionscript => 'com.pomodo.vo.ServiceErrorVO',
        :ruby => 'ServiceError',
        :type => 'custom',
        :attributes => ['code', 'message' ] )

ServiceError is a ruby class in the models directory, but it does not
inherit from ActiveRecord. I noticed a comment in the config file
saying one must specify the "classpath" for non AR classes, but not
sure what that would be (i tried 'models.ServiceError') and that
didn't work.

What happens is that the flex side recognizes the incoming amf as
com.pomodo.vo.AccountVO in the first case, and in the 2nd it just
thinks it's an Object:

(mx.messaging.messages::AcknowledgeMessage)#0
  body = (Object)#1
    code = 1
    message = "not found"
  clientId = "3c2621bb-1fcd-7c05-ee27-3974ade2a15b"
  correlationId = "B88E6DD5-9C17-5B8C-CBFE-39C341334A87"
  destination = (null)
  headers = (Object)#2
  messageId = "5cf69c75-ff77-ae4d-27c5-a0bb8ae8aa10"
  timestamp = NaN
  timeToLive = 0

A 2nd question has to do with error handling. Eg, i hit the server,
the controller does something, and finds that there's a problem. I
want to return some sort of structured object containing the error
info:

   if all_went_well
      render :amf => obj_to_return
  else
     render :amf => ServiceError.new(SYSTEM_ERROR, "system error")
  end

In the success case i return the object the client asked for, but in
the error case i want to return a different object. What's the best
practice for handling errors?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aaron smith  
View profile  
 More options Feb 20 2008, 10:02 pm
From: "aaron smith" <beingthexempl...@gmail.com>
Date: Wed, 20 Feb 2008 19:02:47 -0800
Local: Wed, Feb 20 2008 10:02 pm
Subject: Re: [RubyAMF] mapping question

so you're just wondering about handling errors, not neccessarily mapping non
AR objects?

for error handling, there is an object called FaultObject, when used it
triggers your fault handler in flash. You want to use this instead because
of the fact that it triggers fault handlers.

so you'd do something like;

render :amf => FaultObject.new(1, "my error");  //1 is any code you want

and in flash i believe it comes in faultCode and faultMessage /
faultDetails. I can't remember off hand, but that's pretty much what you
want.

and just in case you want to map non-ar objects, you need to require the
file in the rubyamf init.rb file (in the rubyamf plugins dir). So that the
class is in memory and available at runtime. So your service error class
mapping is correct, the class just needs to be required in that init file.

-Aaron


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
roobnoob  
View profile  
 More options Feb 21 2008, 7:58 pm
From: roobnoob <gtga...@gmail.com>
Date: Thu, 21 Feb 2008 16:58:15 -0800 (PST)
Local: Thurs, Feb 21 2008 7:58 pm
Subject: Re: mapping question

Thanks for the response. Comments inline..

On Feb 20, 7:02 pm, "aaron smith" <beingthexempl...@gmail.com> wrote:

> so you're just wondering about handling errors, not neccessarily mapping non
> AR objects?

I was asking about both...

> for error handling, there is an object called FaultObject, when used it
> triggers your fault handler in flash. You want to use this instead because
> of the fact that it triggers fault handlers.

> so you'd do something like;

> render :amf => FaultObject.new(1, "my error");  //1 is any code you want

> and in flash i believe it comes in faultCode and faultMessage /
> faultDetails. I can't remember off hand, but that's pretty much what you
> want.

Ok, i tried this, but i get back this monster object which includes a
stack trace. This stack trace also appears on the server-side which i
don't want. Also, it has a particular structure; i want to define my
own error object, not something pre-defined for me. Basically i want
to define my own class (as in the ServiceError example above) and
return that. It looks like i'll have to distinguish between the two
(or create a wrapper class) in the result handler.

> and just in case you want to map non-ar objects, you need to require the
> file in the rubyamf init.rb file (in the rubyamf plugins dir). So that the
> class is in memory and available at runtime. So your service error class
> mapping is correct, the class just needs to be required in that init file.

I do want to map non-AR objects, but adding it to init.rb did not
help, i was still getting the below:

From GetAccount result: (mx.messaging.messages::AcknowledgeMessage)#0
  body = (Object)#1
    code = 101
    message = "object not found"
  clientId = "dfa4d449-517e-0556-ee1c-d3d9f7e6b3d7"
  correlationId = "9E2230A5-D462-2FA4-AB30-3DAFEA8E1A79"
  destination = (null)
  headers = (Object)#2
  messageId = "eec4ce23-d61d-9f09-c52c-3397b0ebd1cf"
  timestamp = NaN
  timeToLive = 0

In other words, getting "Object" back instead of
com.pomodo.vo.ServiceErrorVO. HOWEVER, the client code wasn't actually
instantiating a ServiceErrorVO since i was just testing (ie, dumping
the contents of ResultEvent.message). When i added some client code
that instantiated a ServiceErrorVO from the result object, then it was
fine. Note that this worked fine w/o any require statement in init.rb.
Freaky.

Eg,  this is my function that receives the result:

private function handleGetAccountResult(e:ResultEvent): void {
        Debug.log( e.message ); // this prints out the above

                // So if the below is commented out, then the above
says that i have an "Object" back. But if it's not, then i properly
get a "ServiceErrorVO" object.
        //var error: ServiceErrorVO = ServiceErrorVO(e.result);
        ...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »