Java, Flash, ActionScript and AMF

The interaction between Java and Flash
(part 1)


I'm writing some notes about the java and flash interaction.
I wish to achieve in the communication between a java web technology and flash client side tecnology

Client Side:

Flex and Flash.
Flex is more powerful with business logic, Flash is the best choose for designers.
See at wikipedia for a little introduction.

Websites using the Adobe Flash Player platform or Flex is programmable by ActionScript language.
Actually the latest version is the 3.0

AMF(Action Message Format) is a binary format for data serialization and remote method invocation. It is for better perfomance, it compress the size of data transferred and it is more powerful than parsing XML data. Basically AMF is the native choose if you want to comunicate with actionscript.


About performance benchmarks are very bright, as you see in this link AMF 3 is the best.
But the webservice is a standard for a scalable architecture. you write a service with soap specification and the you can reuse it in different client technology.
So what about interaction with AS3 and Webservice?

Action Script 3 and Webservice

In the Action Script 2.0 there is a component that allow to consume a webservice.
In Action Script 3.0 it disappears, because now it belong to flex sdk.
So, in order to consume a webservice you need to use a thirdy part component.

I try two thirdy part component, 


But I obtain several error in calling a simple java jax ws "hello world" webservice.
So I think that this component can't handle well the jax ws wsdl and webservice without any further modification.

So, If you want to use webservice you must see Flex within its webservice managed component.
Now I leave this way.

Action Script 3 and AMF

AMF is the easiest way to get communication between flash and the web server.
Data is compressed and is in binary format.

I found an actionscript client code in order to see what data is sent thru amf:

var nc:NetConnection=new NetConnection();


var res:Responder=new Responder(onResult,onError);"func_name",res,"a_parameter");

function onResult(e:Object):void

function onError(e:Object):void

Then I make a simple java servlet in order to see what headers, parameters and body stream is sent.

The content type arrived is application/x-amf
And in the body stream I see the string func_name, a_parameter and other chars, so I think that is the right moment to search for a java amf library for body deserialization.

There are many solutions for AMF in java side:

OpenAMF is a Java port of AMFPHP, it does a small subset of BlazeDS, i.e. Flash Remoting. 

BlazeDS  has a proxy service to proxy HTTP calls, it has an extensive messaging infrastructure with various server push flavors (polling, long-polling, streaming) to build messaging applications, it has JMS capabilities and many different features.

Red5 is a video/audio streaming oriented solution and more close to the Adobe's Flash Media Server. It does  also Flash remoting and remote shared objects which provide limited data connectivity. (BlazeDS does not have video/audio streaming.)

Cinnamon has a full support for AMF4, it works with or without flex, it support spring beans and plain java classes as services, has also an automatic source generation for AS3 service interfaces. Basically is a remoting framework connecting as3 clients with java ee server applications.

Pimento is a framework for integrating data management into RIA. It integrates Java apps, Hibernate, spring with flex,flash and air clients.

Granite DS is an open source framework for integrating Java EE with Flex and AMF3 serialization. It provides interoperability with popular framework service like EJB3, Spring, Google Guice, POJO service etc.


Loyal-Job Jones said...

Thank you for your informative post. I was wondering if you could elaborate more on BlazeDS vs RED5 vs Cinnamon vs OpenAMF vs Pimento vs Granite? Is there much of a difference? Which is the fastest? Which is more supported? Which would you recommend?

Giuseppe Morreale said...

I don't try all the frameworks so I can't tell more about.

The better solution depends on what you wish to do!

Loyal-Job Jones said...

I wish to have many concurrent connects from many different users. With an emphasis on speed. Any idea which would be better suited? Thanks in advance for your reply.