How can I debug AMF (BlazeDS) serialization of Java objects to Actionscript?

13,196

Solution 1

These are two of the tools I use when working with BlazeDS, AMF, etc.:

  • Use an HTTP proxy tool that shows the calls between your client and server, like Charles

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

  • Turn on the logging for BlazeDS. Within WEB-INF/conf/services-conf.xml, lower the debugging level to 'debug' like in the below snippit. The output, which is fairly detailed, will appear in {tomcat-home}/logs/localhost.yyyy-mm-dd.log

    <target class="flex.messaging.log.ConsoleTarget" level="debug">

Solution 2

The easiest way to check on the communication between service-clients AMF messages is to use FireFox, install FireBug extension and add the AMF Explorer. You can see the structured requests and responses.

Solution 3

The java class that is being deserialized in the client side must have a reference to an object of the corresponding AS3 class in the application (mxml or as3). Otherwise, the as3 class will not be loaded in the swf file and will result in deserializing the java class to a generic as3 object.

updatedThis will happen despite having the mapping, getters and setters. Just declare an object of the corresponding AS3 class in script section of your mxml.

Share:
13,196
Boden
Author by

Boden

Updated on June 21, 2022

Comments

  • Boden
    Boden almost 2 years

    I'm using BlazeDS to remote some Java objects that I'm consuming in a Flex application. I'm getting a type coercion error with one of my classes that I can't for the life of me figure out. I have other classes that are working fine using the same data types, and I've gone over my mapping a dozen times. I'm following all of the necessary conventions for getters and setters as far as I know...

    Anyhow, my question is: how can I debug this problem? Running the Flex app in debug mode spits out some generic errors to the console that don't really help much (TypeError: Error #1034: Type Coercion failed: cannot convert Object@5d1d809 to valueObjects.SomeClass.).

    I'm new to this whole AMF / Flex + Java thing, so any tips would be greatly appreciated.

  • Boden
    Boden almost 15 years
    Thanks! Well it looks like everything is being serialized correctly on the server side. When it gets to the client something is puking. How can I see what's happening in the client as it's deserializing?
  • Stu Thompson
    Stu Thompson almost 15 years
    I would check to see if you are "binding" correctly, with truly 1:1 Java:AS3 objects, compatible data types and correct usage of "[Bindable]" and "[RemoteClass(alias="com.mycorp.myproj.vo.User")]" AS3 binding features. There are plenty of examples out there in the googlenets.
  • Boden
    Boden almost 15 years
    My types are ok, my remote class aliases are correct, and I've experimented with Bindable. I used Charles per your suggestion and everything is coming back from the server looking great....class names, types, data, everything. If I could just see the specific reason that the coercion is failing I might be able to figure this out...but right now I feel blind.
  • Boden
    Boden almost 15 years
    Ok, it was a binding problem as you suspected. I was marking my value objects as bindable and while this worked for some, it didn't work for all. I found a video about binding in flex and am about to watch it to see if I can get a better understanding of this stuff. Thanks again!
  • Boden
    Boden almost 15 years
    PS - I'm going to accept this answer because your original response did answer my original question (although suggestions for seeing what's happening in the client a little better would be great.)
  • stubotnik
    stubotnik over 13 years
    Hi - sorry for resurrecting an old thread but I was about to post the exact same question when I found this. Like yourself I'd love to be able to get some feedback on why object translation fails in the client (presuming all type mappings. etc. are correct). Before I go and create a brand new question I was just wondering what the Binding issue you mention towards the end was? ie: is it something generic?
  • Mickaël Gauvin
    Mickaël Gauvin about 8 years
    In my main.mxml, I just add private const myVO:MyVO = null; and I worked, thank you.