Java – Modifying AMF response at runtime – How to

apache-flexblazedsflex3jakarta-eejava

I have built a simple flex application (using BlazeDS) which displays "Person" details by invoking a java service using flex remoting.
So, my Person class looks something like this:

class Person {
public int age;
public String name;
}

As a java developer, here is my understanding:
When I run the front flex app in my webapp, an RPC call is executed and BlazeDS does the hard work of invoking the right method, obtaining the result as an object, converting the object to AMF format (serialization). And, then the web/app server sends back this response to the requesting app over http. The flex app now does the task of deserializing the object received in AMF format and somehow make use of it.

Here is my question:
I would like to modify the response before it reaches the Flex application by modifying the attributes of the person object. I have a Filter in place to do this. However, I am not sure as to how I would deserialize the AMF stream, modfiy the object, serialize the object back into the stream / reconstruct the stream somehow.

Is there a way to doing this? Where should I start?

PS
If the question was too confusing, here is a shorter version:
How do I modify the response stream of content type AMF-X, before it reaches a flex app using a java filter?

Best Answer

Serializing and deserializing AMF on your own is not going to be easy so definitely avoid that. A better approach is to convert the data to the right format in your back-end code. From Flex, call a service method on the back-end that then fetches the data and transforms it into the correct object structure before sending it back to Flex.