views:

152

answers:

3

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?

+1  A: 

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.

James Ward
A: 

To further James' answer, use something like spring to interecpt the return of the call and interfere with it there (again, before it gets serialized).

You would basically have to reimplement the (de) serialization process, and that's not simple.

Gregor Kiddie
A: 

Well, It's not exactly what you want, but if you only need to change something occasionally while testing there's a solution. Charles Proxy (http://www.charlesproxy.com/) does let you modify the return data 'by hand'. It's a tool I use daily for monitoring AMF traffic, as it does a great job deserializing it, and showing it human readable format. There's a free version you can try.

Short instruction on how to edit the data:

0) Install Charles (including the firefox plugin if you use it

1) Choose Proxy->Breakpoints from the main menu.

2) Fill in the host (you can do it using wildcards - eg. mydomain.com* )

3) Check the "Response" box

4) Call the server

5) The breakpoint should fire when data comes back. Now just find the "Edit Response" tab, choose "AMF" on the bottom, and you can edit anything you want.

Hope this helps

Robert Bak