AMFConnection for AMF remoting in Java

In couple posts back, I talked about using NetConnection to talk to a remoting destination in BlazeDS/LCDS. This helps for pure Flash clients talk to BlazeDS/LCDS but what if you have a Java client app and you want to do a remoting call from your Java app, is this possible? That’s when AMFConnection comes into play.

I created this nice little class in BlazeDS source tree a while back. It tries to mimic Flash’s NetConnection in Java (hence the name AMFConnection) and inspired by Peter Farland‘s AMFConnection. It uses BlazeDS’ AMF serializer/deserializer (which means you need flex-messaging-common.jar and flex-messaging-core.jar from BlazeDS in your classpath) and it can potentially be used from any Java code to serialize/deserialize AMF messages. Internally, Java’s HttpURLConnection is used to send/receive HTTP request/replies and can be used to perform remoting calls to BlazeDS, LCDS, or any other server technology that understands AMF from your Java client.

You would use AMFConnection pretty much like NetConnection. One notable difference is that calls are not asynchronous which makes sense for Java. Here’s a brief example:

// Create the AMF connection.
AMFConnection amfConnection = new AMFConnection();

// Connect to the remote url.

// Make a remoting call and retrieve the result.
Object result ="remoting_AMF.echo", "Hello World!");
catch (ClientStatusException cse)
// Handle exception.
catch (ServerStatusException sse)
// Handle exception.

// Close the connection.

A full example can be found in this JUnit test in BlazeDS source tree.


3 thoughts on “AMFConnection for AMF remoting in Java

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s