3

I'm currently migrating a large project from Flex 3 to Flex 4.5. The problem I'm stuck on is network communication: we're using a custom protocol that we embed in AMF3, but it seems the messages sent by flash.net.NetConnection aren't readable.

Our Java back-end uses some BlazeDS classes to deserialize the message, namely flex.messaging.io.amf.AmfMessageDeserializer.AmfMessageDeserializer, and I can monitor the network traffic with Charles Web Proxy which decodes AMF3. The very simple code herebelow sends a message that can be decoded by Charles when compiled in Flex 3.5, but not in Flex 4.5 (I get "Failed to parse data (com.xk72.amf.AMFException: Unsupported AMF3 packet type 17 at 26").

import mx.controls.Alert;

private function init():void
{
    var pdl : Dictionary = new Dictionary();

    var connection : NetConnection = new NetConnection();
    connection.connect("http://localhost");

    var responder : Responder = new Responder(result);
    connection.call("net", responder, pdl);
}

private function result(pdl : Object) : void {
    Alert.show("coucou", "hello");
}

I've set up an apache server at localhost:80 to test this.

Has anyone used NetConnection in Flex 4.5 and encountered deserialization problems? How did you solve them?

Thanks,

Daniel

2 Answers2

3

AMF3 has a bunch of different core types it can serialize. One of those core types is new to AMF3 in the past year or two, Dictionary, and it has a "packet type" of 17, thus the error message. I'm not sure why Flex 3 would serialize it as something other than a Dictionary and Flex 4.5 would serialize it as the new Dictionary type, but you're getting an error because your BlazeDS backend doesn't support the new Dictionary type.

The solution is to either figure out what it was sending as in Flex 3 and switch to that, or to upgrade BlazeDS (there seems to have been a patch added to BlazeDS last year for Dictionary http://forums.adobe.com/thread/684487).

edit: Didn't realize that the error was with Charles. Charles probably hasn't added support for Dictionary, as it's not part of the documented AMF3 specs. Have you tried the beta of Charles?

warhammerkid
  • 955
  • 5
  • 6
  • 1
    +1 for "Charles probably hasn't added support for Dictionary". The first thing I did after reading this question was check out the last time Charles was updated: August 2010. – elekwent Jun 03 '11 at 16:08
  • Upgrading to BlazeDS 4.5 and JRE 1.6 did solve the communication issue - I had to modify the parsing code a little bit since the object's type on the Java side is no longer ASObject but a Hashtable. Another solution that worked was to pass an AS3 Object as parameter to `call` instead of a Dictionary - easy to implement since we used a class derived from Dictionary, I just had to make it derive from Object instead (we never used weak keys anyway). – Daniel Kitachewsky Jun 06 '11 at 10:12
0

Since you're working with legacy code, you may need to set the NetConnection's objectEncoding property manually before you make the connection. You can set the connection's objectEncoding with the help of the ObjectEncoding class.

What version of Flash Player are you using?

elekwent
  • 763
  • 5
  • 10
  • I'm using Flash player debug version 10.2.159.1. The connection's objectEncoding is equal to 3, I'm not modifying the parameter. – Daniel Kitachewsky Jun 03 '11 at 15:34
  • In that case, the object encoding should default to AMF3. Your error message "Unsupported AMF3 packet" convinces me it's an encoding problem. I see the error message originates from "com.xk72.amf.AMFException" which is Charles class right? Do you have access to the code in that package? If not, you may have to contact the vendor directly. – elekwent Jun 03 '11 at 15:53
  • Changing objectEncoding to ObjectEncoding.AMF0 makes the message readable, and I do get a response, but the Responder's result and status methods are never called. It's also the case in Flex 3.5, thereby breaking the legacy code. – Daniel Kitachewsky Jun 03 '11 at 15:57
  • elekwent: the message is also unreadable by BlazeDS. I've tried recompiling the back-end using the latest BlazeDS version (4.0.1.21287). – Daniel Kitachewsky Jun 03 '11 at 16:01
  • Seems this isn't the latest version. I'll try with 4.5.0.21329. – Daniel Kitachewsky Jun 03 '11 at 16:10